Re: Sending archived objects to a child process via NSPipe
Re: Sending archived objects to a child process via NSPipe
- Subject: Re: Sending archived objects to a child process via NSPipe
- From: "Stephen J. Butler" <email@hidden>
- Date: Thu, 14 Jan 2010 13:23:54 -0600
On Thu, Jan 14, 2010 at 1:11 PM, Christian Ziegler <email@hidden> wrote:
> Hi all!
>
> It is probably simple, but I can't figure it out atm. I want to send an archived object through an NSPipe to a child process. As long as there is only a single object in the pipe at a given time the receiver can unarchive the object properly. However, once I send another object to the pipe, unarchiving raises the error "uncomprehensible archive". I played around with all three read methods but nothing worked. How can I distinguish between several objects in the pipe? Maybe I can write an EOF indicator to the pipe somehow?
Pipes are implemented in the kernel by a fixed sized buffer. I don't
remember exactly how large it is, but let's say it's 4K. Any data sent
under 4K can be transmitted at once, but data over 4K will come in
multiple chunks. It's your job on the receiver end to store those
chunks until you have it all. Then do the unarchiving.
My guess is that your single archive is less than 4K, but two archives
together is more. What you need to do is develop a protocol to send
data over the pipe. Very simply, you could send a 32bit integer first
indicating how many bytes are in the archive. Then read until you get
that many from the pipe. Repeat.
Keeping in mind that I used 4K in my explanation, but the actually
pipe buffer may be more or less.
_______________________________________________
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