block in open()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > block in open()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    block in open()  
freegnu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-06 12:21 PM

hi all, it strange, when i use open() to open a FIFO to write, but i find wh
en i use
open(Fifo,O_WRONLY | O_CREAT | O_TRUNC);
it will block

i really confused





[ Post a follow-up to this message ]



    Re: block in open()  
Nils O. Selåsdal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-06 12:21 PM

freegnu wrote:
> hi all, it strange, when i use open() to open a FIFO to write, but i
> find when i use
> open(Fifo,O_WRONLY | O_CREAT | O_TRUNC);
> it will block

Opening a fifo blocks until someone opens if for reading.





[ Post a follow-up to this message ]



    Re: block in open()  
phil-news-nospam@ipal.net


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-25-06 12:17 AM

On Tue, 24 Oct 2006 13:53:02 +0200 "Nils O. Sel?sdal" <NOS@utel.no> wrote:

| freegnu wrote:
|> hi all, it strange, when i use open() to open a FIFO to write, but i
|> find when i use
|> open(Fifo,O_WRONLY | O_CREAT | O_TRUNC);
|> it will block
|
| Opening a fifo blocks until someone opens if for reading.

So how to make a program that can listen on more than one fifo?  EAGAIN?

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org)  /  Do not send to the address below |
| first name lower case at ipal.net   /  spamtrap-2006-10-24-1312@ipal.net |
|------------------------------------/-------------------------------------|





[ Post a follow-up to this message ]



    Re: block in open()  
William Ahern


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-25-06 12:17 AM

On Tue, 24 Oct 2006 18:13:07 +0000, phil-news-nospam wrote:

> On Tue, 24 Oct 2006 13:53:02 +0200 "Nils O. Sel?sdal" <NOS@utel.no> wrote:
>
> | freegnu wrote:
> |> hi all, it strange, when i use open() to open a FIFO to write, but i
> |> find when i use
> |> open(Fifo,O_WRONLY | O_CREAT | O_TRUNC); it will block

O_CREAT and O_TRUNC are both nonsensical and dangerous to use with named
pipes.

> | Opening a fifo blocks until someone opens if for reading.
>
> So how to make a program that can listen on more than one fifo?  EAGAIN?

open(Fifo, O_WRONLY | O_NONBLOCK);

Note that in Linux O_NONBLOCK only makes the open non-blocking, but I've
recently learned that in BSD it also makes all subsequent I/O operations
non-blocking.







[ Post a follow-up to this message ]



    Re: block in open()  
Nils O. Selåsdal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-25-06 06:33 AM

phil-news-nospam@ipal.net wrote:
> On Tue, 24 Oct 2006 13:53:02 +0200 "Nils O. Sel?sdal" <NOS@utel.no> wrote:
>
> | freegnu wrote:
> |> hi all, it strange, when i use open() to open a FIFO to write, but i
> |> find when i use
> |> open(Fifo,O_WRONLY | O_CREAT | O_TRUNC);
> |> it will block
> |
> | Opening a fifo blocks until someone opens if for reading.
>
> So how to make a program that can listen on more than one fifo?  EAGAIN?

Open it non-blocking, use select or poll.





[ Post a follow-up to this message ]



    Re: block in open()  
Ralf Fassel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-25-06 12:18 PM

* William Ahern <william@25thandClement.com>
| open(Fifo, O_WRONLY | O_NONBLOCK);
|
| Note that in Linux O_NONBLOCK only makes the open non-blocking, but
| I've recently learned that in BSD it also makes all subsequent I/O
| operations non-blocking.

Hmm.  My open(2) manpages says:

O_NONBLOCK or O_NDELAY
When possible, the file is opened in non-blocking
mode. Neither the open() nor any subsequent operations
on the file descriptor which is returned will cause the
calling process to wait.  ...

ERRORS
..
ENXIO
O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and
no process has the file open for reading.  ...

man fifo(4):
..
A process can open a FIFO in non-blocking mode. In this case,
opening for read only will succeed even if noone has opened on
the write side yet; opening for write only will fail with ENXIO
(no such device or address) unless the other end has already
been opened.

Under Linux, opening a FIFO for read and write will succeed
both in blocking and non-blocking mode. POSIX leaves this
behaviour undefined.  This can be used to open a FIFO for
writing while there are no readers available.  ...

So this seems highly system-dependent. :-/

R'





[ Post a follow-up to this message ]



    Re: block in open()  
Kaz Kylheku


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-26-06 06:31 AM

phil-news-nospam@ipal.net wrote:
> | Opening a fifo blocks until someone opens if for reading.
>
> So how to make a program that can listen on more than one fifo?  EAGAIN?

You use the O_NDELAY flag when opening the fifo to prevent the blocking
behavior. If no reader is waiting, it will fail. If opening for reading
with O_NDELAY, it will succeed even if there is no writer.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:55 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register