Clive013000
asked on
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!
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!
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.