• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with NSInputStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with NSInputStream


  • Subject: Problem with NSInputStream
  • From: Remco Poelstra <email@hidden>
  • Date: Tue, 7 Dec 2010 15:17:50 +0100

Hi all,

I've a problem with NSInputStream:
In my object I create (only once) an input and output stream like:

	CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)IPString, 2101, &readStream, &writeStream);
	if (readStream==NULL || writeStream==NULL ) {
		return NO;
	}

	CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
	CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

	serialInput=(NSInputStream *)readStream;
	serialOutput=(NSOutputStream *)writeStream;

	[serialInput setDelegate:self];
	[serialOutput setDelegate:self];
	[serialInput scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
	[serialOutput scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
	[serialOutput open];
	[serialInput open];

When I'm done with my object, I clean it up (in dealloc) like:
	[serialInput  close];
	[serialInput release];
	[serialOutput  close];
	[serialOutput release];

The problem is now that the stream event handler is still called after dealloc has finished, resulting in a crash. How can I make sure that the event handler is not called anymore? It seems the socket does not get properly closed. Maybe a problem with slow handshaking over Wi-Fi?

Any help is appreciated.

Kind regards,

Remco Poelstra

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: SearchBar doesn't display at all
  • Next by Date: NSDocument app where the document is a SQLite file
  • Previous by thread: Re: SearchBar doesn't display at all
  • Next by thread: NSDocument app where the document is a SQLite file
  • Index(es):
    • Date
    • Thread