Named Pipes, FIFOs, Unix Gods?
Hi there,
I''m new to working with IPC and pipes, etc. I''m wondering is there any type of lseek() or truncate() that can be used with named pipes? I''m trying to create a very simple set of two programs that use named pipes to communicate. One program waits in an infitine while loop for a file name to be on the pipe. Like this...
while(1)
{
read pipe
if(request)
process request
else
do nothing
}
the other program starts and puts a file name on the pipe, and waits in a similar fasion to the above code for a response. I need to know if I need to "rewind" a read/write pointer for the pipe after an unsuccessful read, like I would if I was using a shared file.
Is there any way to do it like this
while(1)
{
save current postion in pipe
read pipe
if(request)
process request
set current postion to new position
else
rewind to current position
}
Am I making sense? I code post code if you want to see it... THANKS
I believe named pipes work just like TCP/IP sockets. In other words, you just read from it, and you get what someone else writes to it. Once you read something, it''s gone. So there''s no rewinding or seeking involved. Like stdin, also.
If it isn''t a request and you put it back then how does it become a request? Is it that it could be a request or it could be something else? Is it that the complete request may not have arrived yet?
Tim Mann (http://www.tim-mann.org) has written a GUI for chess programs that does something similar to what you are trying to achieve. The GUI is called Winboard (and the unix/linux version is XBoard). The way it works is that the chess programmer writes a console program that writes its commands to standard out. The GUI reads the commands and updates the graphical board, etc. So my chess program just does printf("e4\n"); fflush(stdout); and the move e4 is played on the graphical board. Winboard is open source, so you can see how he does it. I''ve also seen a class that will do this pretty cleanly. I''ll see if I can''t find it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement