Re: impossible?
Jens.Toerring_at_physik.fu-berlin.de
Date: 08/07/04
- Previous message: Pascal Bourguignon: "Re: Floppy..."
- In reply to: Alex Jones: "impossible?"
- Next in thread: Nick Patavalis: "Re: impossible?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Aug 2004 14:13:16 GMT
Alex Jones <dontlikespam@email.com> wrote:
> "Barry Margolin" <barmar@alum.mit.edu> wrote in message
> news:barmar-631F5F.00434907082004@comcast.dca.giganews.com...
>> In article <cf0po5$91h$07$1@news.t-online.com>,
>> "Alex Jones" <dontlikespam@email.com> wrote:
>> > I'm trying to implement synchronous interprocess communication where
> the
>> > reader blocks until data is available and (the important thing) the
>> > sender blocks until the sent data is fully read by the other side. I
>> > thought this could be done using a pty/tty couple, but the sender
>> > continues execution before the data has been read, so that it seems
> the
>> > data is somewhere buffered. I know that such a communication will
> reduce
>> > performance, but that doesn't matter in this case. The man page for
>> > open(..) showed the a flag O_SYNC, which doesn't make any
> difference.
>> > Another interesting flag is O_DIRECT, which doesn't seem to be
> defined.
>> > cfmakeraw() didn't work either.
>>
>> I don't think any of the standard IPC mechanisms provide this feature.
>> I suggest you use a semaphore to implement the blocking. After the
>> writer writes his data, he waits on the semaphore, which the reader
>> signals after he has completed reading the data.
> Thanks for your response, but that won't be possible, because the child
> process (the writer) will be a compiled program (using execlp() ) later,
> not written by me. But is it really _impossible_ to just create a
> completely unbuffered stream for communication??
When you have no control about the writer how should you be able to
control if it writes without buffering? If the writer uses e.g. the
C standard I/O function and doesn't set them explicitely to unbuf-
fered mode there's hardly anything you can do about that (short of
fiddling with the libc it's using) - the data will stay in the
writers side I/O buffer (controlled by the I/O functions) which will
only get flushed when it's full (if the writer thinks it's writing
to a file) or if there's a '\n' is in the stream (if the writer
assumes to be writing to a terminal). What you can achieve with
a set of pty's in between the processes is making the writer believe
it's talking to a terminal, thus flushing it's buffers on '\n', but
not more.
What kind of a program are you trying to write where on the one hand
you want absolute control about details like buffering down to a
single byte level but on the other hand you have no influence about
the behavior of the sides? If you would give a bit more of a complete
picture perhaps there are alternatives you didn't take into account
yet.
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Previous message: Pascal Bourguignon: "Re: Floppy..."
- In reply to: Alex Jones: "impossible?"
- Next in thread: Nick Patavalis: "Re: impossible?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|