I have a USB device and WDM driver I've developed with heavy borrowing from
Oney's book. The device sends data to the host PC using a bulk IN pipe. The
driver buffers this data until requested by the User code.
I'd like to implement a mechanism whereby the user code can request data,
but if it's not available, it can can block up to a programmable timeout
delay, until the data is available.
This seems like a common need, but I'm unsure how to implement it. Should
the timeout be implemented in user or kernel mode? It seems I could do it
either way.
The method I'm considering is:
The user code makes the request via an IOCTL
If data is available, then the data is returned, with a STATUS_SUCCESS.
If no data is available, then the IRP is cached and STATUS_PENDING is
returned.
The user code completes if STATUS_SUCCESS was returned.
If STATUS_PENDING was returned, then the user code calls
WaitForSingleObject with the desired timeout
When data is available, the IRP is completed with the data and
STATUS_SUCCESS
If the user code times out, then I would cancel the IRP
(Is there a risk of a race here? What if my driver is completing the
IRP when the cancel occurs?)
Any general suggestions are welcome.
Thanks in advance for help,
Dennis