• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Non-Blocking File IO on Linux

Anyone know how to achieve overlapped File IO on Linux (RedHat 6.2)?  I tried open with O_NONBLOCK, and tested for EAGAIN / EWOULDBLOCK, but could not raise that error on a read or a write (1MB buffer on a 32MB file).  I also tried fcntl with O_NONBLOCK.

The only references to O_NONBLOCK I can find refer to sockets, FIFOs, and terminals.  Are these the only devices which support it?  I also read that non-blocking IO is only available on STREAMS devices, but RedHat Linux does not include STREAMS !

I guess Unix File IO is supposed to be asynchronous, but there is a significant delay in transferring, say, 1MB buffer compared to < 4KB.  The delay could well be in kernel finding buffer space, but nevertheless I dont want to wait around while it does it!
0
Clive013000
Asked:
Clive013000
  • 2
1 Solution
 
jlevieCommented:
I suspect that what you want is un-buffered I/O asynchronous I/). By default file I/O is buffered and synchronous, meaning that program execution gets blocked until the I/O request completes.

To do un-buffered I/O you'll use open, read/write, and fnctl to set the mode. You'll also probably want to have the I/O subsystem send your program a signal as the I/O completes. Take a look at the man pages for open, fcntl, and signal.
0
 
ufolk123Commented:

overlapped File IO as you are expecting to behave here is not strictly an overlapped I/O but you want the kernal to indicate success or failure for a file read or write if kernal is supposed to take time doing it .This is different from sockets/pipes etc  where system can block because the protocol may need to block for input from other side or buffers might be full.
for ordinary files , Unix generally  will not block ( As kernal will always find ways to transfer a file in some finite time).
So i do not think you will be able to get this non-blocking behaviour for files in Unix.
May be you could try for files of very big size(>32 MB).But again this is implementation dependent.


ufolk123

0
 
ufolk123Commented:

overlapped File IO as you are expecting to behave here is not strictly an overlapped I/O but you want the kernal to indicate success or failure for a file read or write if kernal is supposed to take time doing it .This is different from sockets/pipes etc  where system can block because the protocol may need to block for input from other side or buffers might be full.
for ordinary files , Unix generally  will not block ( As kernal will always find ways to transfer a file in some finite time).
So i do not think you will be able to get this non-blocking behaviour for files in Unix.
May be you could try for files of very big size(>32 MB).But again this is implementation dependent.


ufolk123

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now