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!
Clive013000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.