aio in win32 .. how?

Michael Roberts mike at mjr104.co.uk
Fri Dec 12 14:50:56 UTC 2003


On Fri, Dec 12, 2003 at 01:15:58PM +0100, Ragnar Hojland Espinosa wrote:
> What would be the equivalent of aioEnable, aioHandle and aioDisable in
> MS Windows?

I'm not familiar with aio or how much you know about Win32...
but I have done a wee bit of asynchronous stuff on Windows. (serial programming mainly)

CreateFile() can take an option FILE_FLAG_OVERLAPPED with an OVERLAPPED structure.  then ReadFile() and WriteFile() can be put into an asynchronous mode.  The API is a little 'overloaded' - basically these few functions can do quite a few different different things depending on all the settings you maintain across the related function calls.  

In asynchronous mode the read and write functions return FALSE and then you check GetLastError() for ERROR_IO_PENDING.  You need to trap for various bits of state - the async operation can complete immediately or can pend and there are various failure modes as well - if GetLastError() doesn't return you ERROR_IO_PENDING.  You also may not get as many bytes, say when writing, transfered as you wanted so you have to potentially go around again to finish your operation. 

In the overlapped structure you can create an event object and then you can WaitForSingleObject() or WaitForMultipleObject() to go to sleep and get a signal when the async operation has completed.  I think you also have the choice to poll if you don't want to go to sleep and do other processing at the same time as your async operation.  When you get woken up, IIRC, you have to check how you were woken up for other error conditions.  

Are you loving this API yet?  grrr.. :-)

If you have Visual Studio you can check the help api or you can check MSDN online.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp

None of this information necessarily helps you interface to Squeak, mind, but if you weren't aware of it then maybe it helps you get a little bit closer. 

I have had a quick look at the SM card for aio and it seems (on the face of it) that you could do the notfication stuff using a windows event object to get signalled when the async operation is complete.  You would need a windows thread to go to sleep on the event object, however, but that's details I guess. 

Cheers

Mike



More information about the Squeak-dev mailing list