How does overlapped DeviceIoControl work? If I call the same overlapped DeviceIoControl several times from 1 thread and evrytime I call it it hasn't completed the previous operation, what happens?
Is another thread created for each DeviceIoControl call?
I ask because I have a PCI device which has 16MB of memory available through a special HPI (Host Port Interface), which is rather slow. So I want to make a driver that provides reading and writing to that memory without blocking and waiting for completion. Somekind of overlapped read and write operations. But next write or read operation can't start befor the previos one ends. I want to make somekind of a read/write operation queue and place data in a special buffer from which it can be and read transferred to the device when it's idle by another thread. So I'm looking for the best way to do so. Any help is mostly appreciated.
I thought I could use overlapped DeviceIoControl for writing to the divice, but if the device is busy than I have to maintain the data buffer from which I write intact until the transfer completes. So I have to block in order to copy data to another special buffer and call overlapped writing DeviceIoControl than. But what happens if I call it several times without waiting for completion? Can a context switch occur while DIOC is running? I think this has to look like a file system driver... may be..
Posted on 2002-09-25 14:05:17 by Vaxon
ya gotta use events for overlapped. Here's the blurb from ms on the overlapped structure. Note the hEvent member.

Events schments, I'll take handshaking anytime. What I did to get around events was to send a USER message to the window I wanted to notify that the VxD had done it's task.



OVERLAPPED

The OVERLAPPED structure contains information used in asynchronous input and output (I/O).


typedef struct _OVERLAPPED { ULONG_PTR Internal; ULONG_PTR InternalHigh; DWORD Offset; DWORD OffsetHigh; HANDLE hEvent;
} OVERLAPPED;
Members

Internal
Reserved for operating system use. This member, which specifies a system-dependent status, is valid when the GetOverlappedResult function returns without setting the extended error information to ERROR_IO_PENDING.

InternalHigh
Reserved for operating system use. This member, which specifies the length of the data transferred, is valid when the GetOverlappedResult function returns TRUE.

Offset
File position at which to start the transfer. The file position is a byte offset from the start of the file. The calling process sets this member before calling the ReadFile or WriteFile function. This member is ignored when reading from or writing to named pipes and communications devices and should be zero.

OffsetHigh
High-order word of the byte offset at which to start the transfer. This member is ignored when reading from or writing to named pipes and communications devices and should be zero.

hEvent
Handle to an event set to the signaled state when the operation has been completed. The calling process must set this member either to zero or a valid event handle before calling any overlapped functions. To create an event object, use the CreateEvent function.
Functions such as WriteFile set the event to the nonsignaled state before they begin an I/O operation
Posted on 2002-09-25 18:09:54 by sceptor