Non-blocking writing on a Named pipe

Non-blocking writing on a Named pipe

Post by Twiggy1 » Wed, 04 Dec 2002 04:18:10



Hi,

Is there someoen who know how to write a function that write into a
named pipe without blocking?

My problem is that many process write in the same named pipe. So they
wait until they got read by the main process. But if the system crash,
all the messages awaiting to be read by the main process will be lost.
So if they could be write on disk in the named pipe, the data won't be
lost.

I need a solution in any language ( Perl, Korn, C, ... )

Thank  

Twiggy

 
 
 

Non-blocking writing on a Named pipe

Post by Grant Taylo » Wed, 04 Dec 2002 04:54:48



> Is there someoen who know how to write a function that write into a
> named pipe without blocking?

Open the pipe with the O_NONBLOCK flag, and it will be a nonblocking
file descriptor.  But it sounds like nonblocking i/o isn't what you
actually want:

Quote:> My problem is that many process write in the same named pipe. So they
> wait until they got read by the main process. But if the system crash,
> all the messages awaiting to be read by the main process will be lost.
> So if they could be write on disk in the named pipe, the data won't be
> lost.

Pipe data doesn't exist on disk no matter what you do; that's not what
pipes are, named or not.

If you want reliable sequenced message delivery, across system
restarts, you'll want something like the message queueing middleware
various networked business apps get built from.  You could also whip
up your own scheme for using files as queues.  But pipes aren't it.

--
Grant Taylor - gtaylor<at>picante.com - http://www.picante.com/~gtaylor/
 Linux Printing Website and HOWTO:  http://www.linuxprinting.org/

 
 
 

Non-blocking writing on a Named pipe

Post by Lew Pitch » Wed, 04 Dec 2002 04:52:30


On 2 Dec 2002 11:18:10 -0800, in comp.unix.programmer,


>Hi,

>Is there someoen who know how to write a function that write into a
>named pipe without blocking?

>My problem is that many process write in the same named pipe. So they
>wait until they got read by the main process. But if the system crash,
>all the messages awaiting to be read by the main process will be lost.
>So if they could be write on disk in the named pipe, the data won't be
>lost.

>I need a solution in any language ( Perl, Korn, C, ... )

open() the pipe with O_NONBLOCK or O_NDELAY mode

Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employer's.)

 
 
 

1. select() and write() behavior with non-blocking named-pipe

I've got a process that sets a named-pipe to be non-blocking. The first
time that the process
enters a situation where the write() would block it adds the fd into the
select() calls set
for writers. The expectation was that the select() would indicate that
the fd was ready for
writing and the write() would be accomplished. On an HP/UX box we have a
situation
where the process that is doing this logic starts to take a large
portion of the CPU -- just
as if it was polling the fd. I used the HP/UX tusc/truss command and it
shows that what is
happening is that the select() returns a 1 (with the indication that the
fd that is being tested
for writing is set), but the write() returns a 0 and nothing is written.
I have always been
under the impression that write() would return a non-zero value and that
select() would not
return the fd for writing if it wasn't really ready for writing.

What is the problem with the logic in this case?

Thanks for the help!

Roger

2. Shell script is not finishing!!! (PPPd)

3. [2.5] Non-blocking write can block

4. secure ftp & telnet

5. select(), non blocking writes to pipes and EAGAIN

6. "Out of Memory" errors

7. Non Blocking Named Pipe

8. Help -- How to hook the timer interrupt

9. ksh: wanted - non-blocking pipes

10. Problem : can't make pipe non-blocking on 2.5.X

11. Non-Blocking Reads on a Pipe

12. non-blocking IO with pipes?

13. TCP Socket Non-Blocking write ?