On Thu, May 8, 2008 at 12:59 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: > Are there any guarantees about blocking behavior for NSInputStream and > NSOutputStream? For example, if I receive an NSStreamEventHasSpaceAvailable > for an NSOutputStream, how many bytes can I write without blocking? It > doesn't seem safe to do I/O in the main thread if there are no such > guarantees, but the documentation on Cocoa streams is unsettlingly vague on > this point.
NSStream matches the semantics of the UNIX read/write calls. In both cases, if you are informed that data or space is available, you can issue a read or write for an arbitrary amount of data and be guaranteed that it will not block. The only catch, of course, is that the system makes no guarantee as to how much data it will actually read or write before giving control back to you, which is why these functions/methods have return values. The documentation of the semantics could use some help, to be sure. For example, the docs for read:maxLength: don't even mention the fact that you can get 0 or -1 as return values (for EOF and error, respectively)! This rather critical omission can make for some fun explosions when you start passing the return value around as if it were an unsigned byte count. Mike _______________________________________________ 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 [EMAIL PROTECTED]