[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FIFO




Hi

I'm also using FIFOs in my program and my code looks similar to yours. The
FIFO path is important - it won't work with "/mnt/flash/FIFO" ! 
Moreover, mkfifo( ) won't work if the FIFO allready exists, so make sure
that there is no FIFO witfh the same path- and filename!
I send a part of my code (it works :->)

prozess 1:
   if(mkfifo("/tmp/.fifo1",S_IWUSR|S_IRUSR)<0) {
      perror("couln't create FIFO, or FIFO allready exists");
      return -1;
   }
   if((fd=open("/tmp/.fifo1",O_RDONLY))<0) { // blocking till IPC opens the FIFO 
      perror("couln't open FIFO");                  // and starts to write
      return -1;
   }
   if((size=read(fd,&ch,1))<0) { [....]

prozess 2:
   if((fifo_fd=open("/tmp/.fifo1",O_RDWR))<0) {
      perror("SERVER couldn't open FIFO");
      return -1;
   }
   if(write(fifo_fd,puffer,strlen(puffer))<0) 
      perror("FIFO write error"); 						
   close(fifo_fd);

hope it helps

	NKrug




Am Son, 26 Nov 2000 schrieben Sie:
> the sourcecode I wrote was just an example (sorry)
> The fifo is created correctly
> return-values are:
>   mkfifo 0
>   open   the fd of the fifo
>   read   -1
>   write  -1
> Furthermore my example code generates a deadlock - it should be:
>   fd=open("./FIFO",WRONLY|O_NONBLOCK) or "/tmp/FIFO" or whatever
> the problem is not the open(...) - except that it returns even if it should
> be blocked (NO O_NONBLOCK) -  the trouble lies in the read(...) and
> write(...) functions, which return with value -1. (an unknown errno is set)
> 
> but thanks for the fast answer ..
> JF
> 
> 
> 
> 
>    From: johan.adolfsson@xxxxxxx.com
>    To: "Justin Flik" <justin_flik@xxxxxxx.com>
>    Subject: Re: FIFO
>    Date: Sun, 26 Nov 2000 14:00:55 +0100
> 
>    Without having tested it, it looks like you should check the return 
> values
>    from mkfifo, open etc. to detect and print ny errors.
>    The root is read only so depending on where you run your program from
>    "./FIFO" might not be created, try "/tmp/FIFO" instead.
> 
>    /Johan
> 
>    -----Original Message-----
>    From: Justin Flik <justin_flik@xxxxxxx.com>
>    To: dev-etrax@xxxxxxx.com>
>    Date: den 25 november 2000 22:19
>    Subject: FIFO
> 
> 
>    >Hi there!
>    >
>    >I just writing a program in C++ at elinux. I need to communicate between
>    >processes and like to use FIFOs. The trouble is, that I get errors if I
>    try
>    >to read or write on it. (The same code is running on my PC with no
>    >problems).
>    >Furthermore it seems that elinux ignores the blocking mechanism - this
>    means
>    >it returns the open-function even if it should not! open("FIFO",RDONLY)
>    has
>    >the same effect than open("FIFO",RDONLY|O_NONBLOCK) !? where noone else
>    >opens the same FIFO in write-mode.
>    >Could it be that FIFOs aren't implemented correctly in elinux yet? Or 
> did
>    i
>    >do something wrong in my code:
>    >
>    >process ONE:
>    > mkfifo("./FIFO",S_IRUSR|S_IWUSR);
>    > fd=open("./FIFO",RDONLY); // should be wait till process
>    > read(fd,&ch,1);   // TWO opens FIFO to write
>    > close(fd);
>    >
>    >process TWO:
>    > fd=open("./FIFO",WRONLY);
>    > write(fd,"hello world",12);
>    > close(fd);
>    >
>    >hope you can help me
>    >thanks in advance
>    >
>    > JF
>    >
>    
>  >___________________________________________________________________________
>    __________
>    >Get more from the Web.  FREE MSN Explorer download :
>    http://explorer.msn.com
>    >
>    >This Hotmail WebCourier newsletter has been sent to you from
>    >justin_flik@xxxxxxx.
>    >Get your own FREE subscription in a few easy steps.
>    >
>    >I do not have a Hotmail account:
>    >Choose this or any of our 60+ newsletters while registering for a free
>    >Hotmail e-mail account. http://www.hotmail.com
>    >
>    >I am a current Hotmail user:
>    >Sign in at http://www.hotmail.com, then click Free News in the left 
> menu.
>    >Check the box next to , then click OK.
>    >
>    >
> 
> _____________________________________________________________________________________
> Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com
-------------------------------------------------------