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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to