[erlang-questions] erlang port and C executable

Johnny Billquist bqt@REDACTED
Sun Nov 23 19:14:20 CET 2008


Per Hedeland wrote:
> "Edwin Fine" <erlang-questions_efine@REDACTED> wrote:
>> One of the most annoying aspects is that under
>> circumstances that are not clear to me, the C program that is spawned
>> sometimes does not seem to be sent a signal for end of file when you close
>> the port, so if it is reading stdin, it's just going to sit there until
>> killed manually.
> 
> This should never happen - i.e. there is no "signal" for end of file,
> it's just the result of reading when there is nothing more to read - but
> a port program that actually reads its stdin should always get end of
> file when the port is closed (after having read what there is to read,
> if anything). "You're probably doing something wrong."

The most common "wrong" is that someone opens/creates a pipe/socket, 
forks, and then writes to the fd, and eventually closes it. The reader 
will not receive an eof, since another process still have the fd open as 
well. eof will only be signalled once *all* processes having the 
pipe/socket open for writing have closed it.

It's a rather common error people do. :-)

>> Worse, if it gets stuck doing something and is NOT reading
>> stdin then you are out of luck.
> 
> This is expected, and can be considered a feature - it allows you to
> e.g. start a daemon that *should* keep running after you close the port.

Yes, I agree. It's a good thing, not a bad one. It's a bad assumption 
that the receiver should stop just because you don't have any more data 
to feed it.

	Johnny



More information about the erlang-questions mailing list