• 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
Re: Reading NSInputStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading NSInputStream


  • Subject: Re: Reading NSInputStream
  • From: Ashley Perrien <email@hidden>
  • Date: Wed, 21 Oct 2009 18:48:52 -0500

After initiating a connection (getStreamsToHost) I don't get an event that the input stream has bytes available, if I check it, it returns NO but if I go ahead and read it anyway, I get the usual banner.

It sounds like you didn't call -scheduleInRunLoop:forMode: ?

Covered. See below for full code.

uint8_t *readBuffer;
unsigned int bufferLength;
BOOL gotBuffer = [readStream getBuffer: &readBuffer length: &bufferLength];
The last line always says arguments 1 and/or 2 are incompatible pointer type. I've tried every combination of * and &, no luck.

Try declaring bufferLength as NSUInteger, as it's declared in the docs and header.

D'oh, thanks, that fixed that problem. Still getting strange issues though with this code:


[NSStream getStreamsToHost: mailHost port: mailPortNumber inputStream: &readStream outputStream: &writeStream];

mailHost and mailPortNumber are imap.gmail.com and 587 if that matters	

Both streams are retained, setDelegate: self, scheduleInRunLoop and open.

if ([readStream hasBytesAvailable])
NSLog(@"Has Bytes");
else
NSLog(@"No Bytes");


This always returns No Bytes

uint8_t *readBuffer;
NSUInteger bufferLength;
BOOL gotBuffer = [readStream getBuffer: &readBuffer length: &bufferLength];


gotBuffer always == NO and bufferLength of 0.

	int len = [readStream read: readBuffer maxLength: 300];

len always == 0 and the buffer is empty.

NSMutableData *returnMessage = [NSMutableData dataWithLength: 300];
[readStream read: [returnMessage mutableBytes] maxLength: 300];
NSMutableString *readData = [[[NSMutableString alloc] initWithBytes: [returnMessage bytes] length: 300 encoding: NSUTF8StringEncoding] autorelease];
NSLog(@"Read: %@", readData);
return readData;

This will always work as expected:
Read: 220 mx.google.com ESMTP...
But only if I don't read from the stream twice. If all of the above code is run, it fails with "Program received signal: “EXC_BAD_ACCESS”." If I comment out the int len = [readStream... section, the NSMutableData section reads fine and gets data.


It's almost is if the NSMutableData is making it up but the docs say dataWithLength returns a zeroed out object.



_______________________________________________

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


  • Follow-Ups:
    • Re: Reading NSInputStream
      • From: Jens Alfke <email@hidden>
References: 
 >Reading NSInputStream (From: Ashley Perrien <email@hidden>)
 >Re: Reading NSInputStream (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: NSColor for darker hightlight color
  • Next by Date: Re: NSColor for darker hightlight color
  • Previous by thread: Re: Reading NSInputStream
  • Next by thread: Re: Reading NSInputStream
  • Index(es):
    • Date
    • Thread