1

I am writing a Windows device driver using WDF (KMDF) for a USB3 device that transfers data in large chunks at a time. I've written a user-level application that tests this functionality, and for the most part, things work.

The problem I encounter is this: I have found that when I force-close (CTRL+C from a cmd window) the application mid-transfer, the on-going data transfer at the time of cancel immediately stops and the host seems to simply stop communicating with that endpoint. I have observed this on a USB bus trace. The requests return in the function driver as "STATUS_CANCELLED"

I have looked at other similar third party devices and ran their test applications with their drivers on those devices and found that when I kill their test applications mid-data-transfer, the transfer completes before the application closes.

My question:

How/when does Windows decide to kill in-flight requests when applications are closed?

Is there any way to mark the request as "uncancelable"? I've scoured the documentation but found nothing that suggests I need to do something to keep requests from being cancelled behind the scenes mid-transfer.

Any insights appreciated, thanks.

8bitcartridge
  • 1,629
  • 6
  • 25
  • 38

1 Answers1

3

It's not about the device driver; it's about the way the console application handles the Ctrl-C event. The console application must trap the Ctrl-C event, and wait for the transfer to finish before it exits.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • I see. Thank you. This logically makes sense to me, but is there anything that the driver can do to be more robust? In other words, is what I describe ("marking" an event as uncancelable) even possible? – 8bitcartridge Mar 07 '13 at 18:46
  • The device driver would have to hold the application open or "block" (since it is the container for the process), which I think would be considered "bad behavior." From a user point of view, Ctrl-C means "I want to stop. Now." I don't know how Windows knows that the application has gone bye-bye; I suspect that a handle has probably been invalidated, or the device driver gets a message from the process that it is exiting. – Robert Harvey Mar 07 '13 at 18:48