Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing NSString to a file descriptor



On 20 Nov 2007, at 18:47, AstroK Software wrote:

Just to test this possible solution I wrote the following test code:

- (void)useTool
{
NSString *msgStr = [[NSString alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"test" ofType:@"spam"]];
NSData *msgData = [msgStr dataUsingEncoding:NSASCIIStringEncoding];
NSPipe *pipe = [NSPipe pipe];

The first problem is that this pipe is autoreleased, as another poster pointed out


NSFileHandle *fh = [pipe fileHandleForWriting];

The second problem is that here you have a file handle that is only good for *writing*...


	[[NSNotificationCenter defaultCenter] addObserver:self
						 selector:@selector(getData:)
						name:NSFileHandleReadCompletionNotification
						object:fh];
	[fh readInBackgroundAndNotify];

...and here you're trying to read from it.

The file handles you get from NSPipe are unidirectional file handles, like the ones you get from the UNIX pipe() function. It sounds to me like you're going to need a UNIX domain socket instead (sockets are bidirectional, so you can use the same file handle for reading and writing, though you'll still need one at each end).

Consider using socketpair() to create a pair of connected, unnamed, UNIX domain sockets. You can then use NSFileHandle or NS/CFStream as appropriate.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Writing NSString to a file descriptor (From: AstroK Software <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.