LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 03-19-2008, 11:13 AM   #1
gjpc
LQ Newbie
 
Registered: Jan 2005
Posts: 6
Thanked: 0
Linux 2.6 FIFO vs Linux 2.4 FIFO


[Log in to get rid of this advertisement]
Hi,

I am back porting a Linux 2.6 project to Linux 2.4. The main process is a daemon that accepts control inputs over a named pipe FIFO. It works just fine on the 2.6 kernel. The 2.4 kernel appears to have a very aggressive FIFO buffering scheme, 2.4 does not allow the reading end to see the data in the FIFO until either there is a lot of data or the write end closes. This is very inconvenient because some of the command sequences are interactive.

Must I close a 2.4 pipe every time I wish to transmit a short message to the reader? I tried getc's and they do not return anything until the writer closes the pipe or it fills up. I am using iostream objects on each end of the pipe. Readers open with:
in.open( fifoInName.c_str(), ios::in );
Writers open with:
out.open( fifoOutName.c_str(), ios::trunc );
I have proof that the pipe code is functional in Linux 2.4: If I cat the output FIFO to the screen in one shell and echo the help command into the input FIFO in another shell I get full text of the help command.

Any suggestions are appreciated.
gjpc is offline     Reply With Quote
Old 03-19-2008, 01:14 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware 11.0, Slackware 12.1, slamd64 12.2, Ubuntu Server 8.04, Kubuntu 9.04
Posts: 2,078
Thanked: 38
Have you tried non-blocking reads?
ta0kira
ta0kira is offline     Reply With Quote
Old 03-19-2008, 01:29 PM   #3
gjpc
LQ Newbie
 
Registered: Jan 2005
Posts: 6
Thanked: 0

Original Poster
Peek does not reveal anything in the FIFO. The problem is that there is data in the FIFO and the reciever does not see it until the FIFO file is closed.
gjpc is offline     Reply With Quote
Old 03-19-2008, 03:34 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware 11.0, Slackware 12.1, slamd64 12.2, Ubuntu Server 8.04, Kubuntu 9.04
Posts: 2,078
Thanked: 38
Peeking isn't a system-level I/O operation. It's associated with the FILE* buffer placed on top of the file descriptor. The only way to tell if the FIFO is closed is to have a read operation return 0 bytes read, which the libc interface handles internally (you don't deal with it directly when using FILE*.)
ta0kira

PS Place this right after fdopen on the reading end and see what happens:
Code:
setvbuf(/*FILE**/ your_file, NULL, _IONBF, 0);
fcntl( /*int*/ your_fd, F_SETFL, fcntl(/*int*/ your_fd, F_GETFL) | O_NONBLOCK ); //(needs <fcntl.h>)
You'll need to allow for empty reads that aren't necessarily indicative of EOF.

Last edited by ta0kira; 03-19-2008 at 07:49 PM..
ta0kira is offline     Reply With Quote
Old 03-19-2008, 08:26 PM   #5
gjpc
LQ Newbie
 
Registered: Jan 2005
Posts: 6
Thanked: 0

Original Poster
problem solved

Blocking is not a factor.

After much experimentation, I discovered that it must be the g++ 3.2 runtime vs g++ 3.4 runtime.

g++ 3.4 must have the smarts to open a FIFO in O_DIRECT mode.

I had to drop using the ostream and istream objects and do
out = open( "fifoOut", O_RDONLY | O_DIRECT)
and
in = open( "fifoIn", O_TRUNC | O_WRONLY | O_DIRECT)
Of course all my token processing has to be redone. I do not have the option of installing the new gnu c++ runtime on the old systems. Thank goodness for ostrstream!

I could not find a way to have the 3.2 runtime open with O_DIRECT mode.

Last edited by gjpc; 03-19-2008 at 08:28 PM..
gjpc is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fifo help !! matlin Linux - Newbie 1 02-21-2008 02:51 PM
Force Linux to run shell script in FIFO manner _hadi_ Programming 3 12-17-2006 03:12 AM
Weird FIFO problem on Linux 2.6 darkwoods Programming 6 04-06-2006 12:29 AM
snmptrapd FIFO eccsamba Linux - Networking 2 11-24-2004 09:52 AM
nfs FIFO??? granny Linux - Newbie 1 12-16-2002 04:38 PM


All times are GMT -5. The time now is 09:05 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration