Asynchronous read and write requests hanging the thread

Hi,

I am writing a WDF driver for a serial port. I am using sequential dispatching for read and write requests in my driver.

I want to fill the write queue with some write requests so that i could test the functionality of WdfIoQueuePurge method. I have some queries.

  1. How to fill up the write queue with write requests? I tried sending Write requests asynchronously but i am not sure whether they are getting filled up in the queue because a write request typically takes very less time to complete.

I tried commenting out the WDFCOmpleteRequest method inEvtIOWrite dispatch function in the driver so that the write request doesn’t complete and the subsequent write requests will be placed in the write queue.

I then tried sending 50 write requests asynchronously from my test application(by calling WriteFile with overlapped structure) but the application is hanging while sending these requests. However if i send only 2 WriteFile requests then those requests pass without any hang.

is there a limit on the number of requests that i can send to the framework while a request is pending to be finished in the driver? If yes who imposes this limit?

  1. When the write queue has some write requests, if i call WDFIoQueuePurge, the framework will cancel the unprocessed write requests. Can i get any logs of this cancellation action? how can i confirm that the framework has cancelled all of these write requests?

  2. What is the difference between sending a WriteFile with Overlapped structure and sending a WriteFileEx API?

xxxxx@gmail.com wrote:

  1. How to fill up the write queue with write requests? I tried sending Write requests asynchronously but i am not sure whether they are getting filled up in the queue because a write request typically takes very less time to complete.

I tried commenting out the WDFCOmpleteRequest method inEvtIOWrite dispatch function in the driver so that the write request doesn’t complete and the subsequent write requests will be placed in the write queue.

Who completes it? Someone has to complete it sooner or later. Note
that when you take ownership of a request (by receiving it in a dispatch
callback), then you are responsible for handling cancellation. If you
abort the calling process, the request will remain outstanding until YOU
complete it.

is there a limit on the number of requests that i can send to the framework while a request is pending to be finished in the driver? If yes who imposes this limit?

There is no limit (except for memory).

  1. When the write queue has some write requests, if i call WDFIoQueuePurge, the framework will cancel the unprocessed write requests. Can i get any logs of this cancellation action? how can i confirm that the framework has cancelled all of these write requests?

That’s the purpose of the API. Do you think it’s going to leave some
behind? If you really don’t trust it, you can certainly add an
EvtIoCanceledOnQueue callback when you call WdfIoQueueCreate. That will
get called any time a request gets canceled. Or, you can supply an
EvtIoQueueState callback when you call WdfIoQueuePurge. That will get
called when the queue is empty.

  1. What is the difference between sending a WriteFile with Overlapped structure and sending a WriteFileEx API?

With WriteFile, the hEvent handle gets signaled when the request is
complete. With WriteFileEx, the hEvent is ignored, and your completion
routine gets called when the request is complete. There’s no difference
from a driver’s point of view.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.