944,164 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 12772
  • C++ RSS
Feb 13th, 2007
0

Named Pipe (FIFO)

Expand Post »
Hi,
I'm trying to write a program using named pipes, and I'm having trouble opening it. In another program I call this line:
C++ Syntax (Toggle Plain Text)
  1. mkfifo("./fife", 0777);

So my named pipe exists and I see it in my list of files. Then I run the program I included below, but I can not get past the open call. Any help would be appreciated for I can not find a lot of resources on this subject.

C++ Syntax (Toggle Plain Text)
  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <stdlib.h>
  6. #include <sys/stat.h>
  7. #include <iostream>
  8.  
  9. #define MSGSIZE 14
  10.  
  11. void main() {
  12. char *message = "Hello, world!";
  13.  
  14. int fd;
  15. fd = open("fife", O_WRONLY);
  16. // Can not get past this point!
  17.  
  18. cout << "fd: " << fd << endl;
  19.  
  20. if (write(fd, message, MSGSIZE) < 0)
  21. cout << "error writing" << endl;
  22.  
  23. close(fd);
  24. }
Similar Threads
Reputation Points: 36
Solved Threads: 2
Junior Poster in Training
nanodano is offline Offline
78 posts
since Feb 2005
Feb 13th, 2007
0

Re: Named Pipe (FIFO)

Look at the errno which open sets, when it returns with a failure?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Feb 14th, 2007
0

Re: Named Pipe (FIFO)

I found out the problem. It waits because it wants another program to handle the other end of the pipe.

I fixed my codes up and I wrote a script like this to fix the problem:

C++ Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. echo "Running clients..."
  3. ./client &
  4. ./client &
  5.  
  6. echo "Running server..."
  7. ./server
  8. # The & runs the program in the background, so you can run another program, playing client and server in the same console
Reputation Points: 36
Solved Threads: 2
Junior Poster in Training
nanodano is offline Offline
78 posts
since Feb 2005
May 21st, 2008
0

Re: Named Pipe (FIFO)

can you post the client program (reading program) too?
Last edited by mustihi; May 21st, 2008 at 8:58 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mustihi is offline Offline
1 posts
since May 2008
May 21st, 2008
0

Re: Named Pipe (FIFO)

a) you're too late - by at least a year, check the dates.
b) try programming something for yourself.
c) start your own thread when you've got something to show.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I Need to Help very Very Fast ( Help Me Please) of Factorial ?
Next Thread in C++ Forum Timeline: Debugging - input validation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC