UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2009-02-06 09:18 AM

jacquesdirac
Member
Registered: 2009-02-06
Posts: 15

Re: FIFO: Resource temporarily unavailable

Hi,

I'm new to this forum and to working with FIFO's, but have a 'hard' question :confused:.

Sometimes when I want to write to a FIFO, I get the error: "Resource temporarily unavailable".

My code:

...  
  assert(state == st_open);
  
  c = ::write(fd, buf, count);
  if (c == -1) {
    PM_DEBUG("Error writing to fifo, error: %s", strerror(errno));
  }
...

- Most important: What's wrong here?
- Is a FIFO stored in RAM?
- Can a FIFO ever get full? And how can a see / adjust the size of a FIFO?

Hope you can help me with this.

Offline

#2 2009-02-06 03:49 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: FIFO: Resource temporarily unavailable

"Resource temporarily unavailable" is EAGAIN, aka EWOULDBLOCK...  You will get it
only on file descriptors that you have explicitly set to non-blocking I/O mode...  And, it
indicates that your I/O operation would normally have blocked at that point, because
it couldn't occur immediately...  (Ie: for reading, there's currently no data to read; for
writing, the buffer is full and needs to be emptied first...)  So, as to your questions:

- Most important: What's wrong here?

Nothing: you set your FIFO FD to non-blocking mode, and it's behaving exactly as
it's supposed to...

- Is a FIFO stored in RAM?

I'm not entirely sure what you're trying to ask here...  If by FIFO, you mean a traditional
Unix-style named pipe, then you could say at least part of it is stored on disk (namely
the inode info describing it as a FIFO and giving its name and perms and such)...
However, the data transfer through it takes place entirely in RAM, yes...

- Can a FIFO ever get full? And how can a see / adjust the size of a FIFO?

Yes, all pipes (named and unnamed) have an internal buffer size limit...  What that
is varies across systems...  I believe Posix requires at least 512 bytes; other than
that, anything goes...  (On modern Linux, I believe the internal pipe buffer is 64K,
though PIPE_BUF is set to just 4096, which is the guaranteed atomic write amount...)
As for adjusting this value, you can't...  Well, maybe by modifying and recompiling
your kernel...  But, if you're filling your pipe buffer, then the reader on the other end
of the pipe isn't reading fast enough to keep up with your writing...  Maybe you can
fix things from that end...  Or, just write slower...

Offline

#3 2009-02-11 08:48 AM

jacquesdirac
Member
Registered: 2009-02-06
Posts: 15

Re: FIFO: Resource temporarily unavailable

Thanks RobSeace for your great answer!

This was very usefull to me.

Offline

Board footer

Powered by FluxBB