caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Named pipe problem: is this a bug?
@ 2005-08-01 15:03 Alan Schmitt
  2005-08-01 15:41 ` [Caml-list] " Virgile Prevosto
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alan Schmitt @ 2005-08-01 15:03 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

Hello,

I've stumbled upon a small bug, and I wonder if it's a OS X bug (I'm  
using X.4.2), or a caml bug. The problem is the following: I create a  
named pipe, then I open it. The open system call seems to block until  
there is data in the pipe.

Here is a small program illustrating this:

let _ =
   Unix.mkfifo "pipe_test" 0o640;
   print_endline "pipe created";
   flush stdout;
   let chin = open_in "pipe_test" in
     print_endline "pipe opened";
     flush stdout

Compile it using "ocamlc unix.cma bug.ml" (the bug occurs both in  
bytecode and native code). When a.out is run, one sees:
pipe created
and the program keeps running. If one then does a
echo foo >> pipe_test
then the "pipe opened" line is shown, and the program terminates.

Is this behaviour normal?

Thanks,

Alan Schmitt

-- 
The hacker: someone who figured this out and made something cool happen.
.O.
..O
OOO



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 186 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Named pipe problem: is this a bug?
  2005-08-01 15:03 Named pipe problem: is this a bug? Alan Schmitt
@ 2005-08-01 15:41 ` Virgile Prevosto
  2005-08-01 15:42 ` Damien Bobillot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Virgile Prevosto @ 2005-08-01 15:41 UTC (permalink / raw)
  To: caml-list

Le 08/01/2005, à 05:03:42 PM, Alan Schmitt a écrit:
> let _ =
>    Unix.mkfifo "pipe_test" 0o640;
>    print_endline "pipe created";
>    flush stdout;
>    let chin = open_in "pipe_test" in
>      print_endline "pipe opened";
>      flush stdout
> 
> Compile it using "ocamlc unix.cma bug.ml" (the bug occurs both in  
> bytecode and native code). When a.out is run, one sees:
> pipe created
> and the program keeps running. If one then does a
> echo foo >> pipe_test
> then the "pipe opened" line is shown, and the program terminates.
> 
> Is this behaviour normal?
> 

Hello Allan,
this corresponds to what the manual page of fifo says (at least under
linux)
  The FIFO must be opened on both ends (reading and writing) before data
  can  be  passed. Normally, opening the FIFO blocks until the other end
  is opened also.

If you don't want that behavior, you'll have to open pipe_test in
non-blocking mode (e.g. with open_in_gen and the Open_nonblock flag)

By the way, what is the purpose of the Open_rdonly and Open_wronly
flags, given that the open_in* and open_out* functions return values of
different types?
-- 
E tutto per oggi, a la prossima volta
Virgile


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Named pipe problem: is this a bug?
  2005-08-01 15:03 Named pipe problem: is this a bug? Alan Schmitt
  2005-08-01 15:41 ` [Caml-list] " Virgile Prevosto
@ 2005-08-01 15:42 ` Damien Bobillot
  2005-08-01 15:55 ` Richard Jones
  2005-08-02  7:59 ` Alan Schmitt
  3 siblings, 0 replies; 5+ messages in thread
From: Damien Bobillot @ 2005-08-01 15:42 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1513 bytes --]


Le 1 août 05 à 17:03, Alan Schmitt a écrit :

> Hello,
>
> I've stumbled upon a small bug, and I wonder if it's a OS X bug  
> (I'm using X.4.2), or a caml bug. The problem is the following: I  
> create a named pipe, then I open it. The open system call seems to  
> block until there is data in the pipe.
>
> Here is a small program illustrating this:
>
> let _ =
>   Unix.mkfifo "pipe_test" 0o640;
>   print_endline "pipe created";
>   flush stdout;
>   let chin = open_in "pipe_test" in
>     print_endline "pipe opened";
>     flush stdout
>
> Compile it using "ocamlc unix.cma bug.ml" (the bug occurs both in  
> bytecode and native code). When a.out is run, one sees:
> pipe created
> and the program keeps running. If one then does a
> echo foo >> pipe_test
> then the "pipe opened" line is shown, and the program terminates.

Same thing on my computers (Mac OS X & Linux).

In fact, a pipe is considered to be opened only if both ends exists  
(you've created the read end, "echo foo >> .." create the write end).

http://www.annodex.net/cgi-bin/man/man2html?fifo+4 says :
"The kernel maintains exactly one pipe object for each FIFO special  
file that is opened by at least one process. The FIFO must be opened  
on both ends (reading and writing) before data can be passed.  
Normally, opening the FIFO blocks until the other end is opened also."

(it's no use to call flush after print_endline : printf_endline do  
the flush itself)

-- 
Damien Bobillot


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2375 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Named pipe problem: is this a bug?
  2005-08-01 15:03 Named pipe problem: is this a bug? Alan Schmitt
  2005-08-01 15:41 ` [Caml-list] " Virgile Prevosto
  2005-08-01 15:42 ` Damien Bobillot
@ 2005-08-01 15:55 ` Richard Jones
  2005-08-02  7:59 ` Alan Schmitt
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Jones @ 2005-08-01 15:55 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: caml-list

This is documented behaviour.  You can't open a FIFO in read mode
until a writer has opened the FIFO - instead the open(2) syscall will
block.  You can pass the O_NONBLOCK flag to open, in which case the
open call will not block.  Or you can open for read and write (because
you yourself are then supplying a writer).

Some more details here:

http://nixdoc.net/man-pages/Linux/man4/fifo.4.html

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Named pipe problem: is this a bug?
  2005-08-01 15:03 Named pipe problem: is this a bug? Alan Schmitt
                   ` (2 preceding siblings ...)
  2005-08-01 15:55 ` Richard Jones
@ 2005-08-02  7:59 ` Alan Schmitt
  3 siblings, 0 replies; 5+ messages in thread
From: Alan Schmitt @ 2005-08-02  7:59 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]

Thanks for all the answers. I tried to man and apropos fifo, but I  
only have documentation about mkfifo which does not mention this issue.

Thanks again,

Alan

-- 
The hacker: someone who figured this out and made something cool happen.
.O.
..O
OOO



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 186 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-08-02  8:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-01 15:03 Named pipe problem: is this a bug? Alan Schmitt
2005-08-01 15:41 ` [Caml-list] " Virgile Prevosto
2005-08-01 15:42 ` Damien Bobillot
2005-08-01 15:55 ` Richard Jones
2005-08-02  7:59 ` Alan Schmitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).