• 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: Writing NSString to a file descriptor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing NSString to a file descriptor


  • Subject: Re: Writing NSString to a file descriptor
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 21 Nov 2007 10:47:14 +0000

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:
This email sent to email@hidden


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

  • Prev by Date: Re: Source list with counter next to item title
  • Next by Date: Re: Plugins Utilizing Core Data NSManagedObjectContext
  • Previous by thread: Writing NSString to a file descriptor
  • Next by thread: Re: Writing NSString to a file descriptor
  • Index(es):
    • Date
    • Thread