ReadFile with OVERLAPPED is blocking!! help

Hi,

In my functional driver,

In the read dispatch routine I am doing :

return (IoCallDriver(deviceExtension->LowerDeviceObject, Irp));
I am *not* calling IoMarkIrpPending in the dispatch routune. This IRP is
not created by my driver. My driver does not do queuing of IRPs and hence
no startio routine. The driver uses DIRECT IO.

In the completion routine i am doing:

if ( Irp->PendingReturned )
{
IoMarkIrpPending(Irp);
}

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = bytesTransferred;

//some cleanup

return STATUS_SUCCESS;

The application is blocking at READFILE call until the data is received
though I specified the overlapped structure with an event.
The ReadFile call is supposed to unblock.

Let me know where I am doing wrong.

Thanks in advance.

xxxxx@hotmail.com wrote:

In the read dispatch routine I am doing :
return (IoCallDriver(deviceExtension->LowerDeviceObject, Irp));
In the completion routine i am doing:
if ( Irp->PendingReturned )
{
IoMarkIrpPending(Irp);
}
The application is blocking at READFILE call until the data is received
though I specified the overlapped structure with an event.
The ReadFile call is supposed to unblock.

It sounds like you’re doing everything right in the driver. Are you sure
the application opened the handle with the FILE_FLAG_OVERLAPPED flag?


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

xxxxx@hotmail.com wrote:

The application is blocking at READFILE call until the data
is received though I specified the overlapped structure with
an event. The ReadFile call is supposed to unblock.

Two things -

One, specifying the OVERLAPPED structure is not enough. You have to
have specified FILE_FLAG_OVERLAPPED on your CreateFile call. (And then
you’re required to provide the OVERLAPPED structure.)

Two, even if you got all that right, this is only a request, not a
demand. As long as no one in the stack returns control before passing
the IRP to a lower layer, any driver in the stack might be completing
the request “in line”. If the IRP is passed to IoCompleteRequest before
the top-level driver’s dispatch routine returns control to its caller –
which can happen for a ReadFile, if for example the required data is
already in a buffer or a cache somewhere – you will get the behavior
you’re describing.

If this seems confusing, think about what would happen if your dispatch
routine passed the IRP to IoCompleteRequest. This is a perfectly
reasonable thing to do in many cases. Well, the same thing can happen
in a lower layer, it’s just a few more nested procedure calls. Or for
that matter a lower layer can pass the IRP to a queueing routine, and
thence to a “start IO” routine or similar - but THAT routine can call
IoCompleteRequest. Again, it all happens in the context of the calling
thread, and there is no chance to “return before the IO is done”, so you
will see no computational activity in your calling thread in user mode
before the IO is done.

If this is unclear or seems incomplete in any way, please don’t hesitate
to ask for clarification.

— Jamie Hanrahan
Azius Developer Training http://www.azius.com/
Windows Driver Consulting and Training

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Friday, March 21, 2003 01:49
To: NT Developers Interest List
Subject: [ntdev] ReadFile with OVERLAPPED is blocking!! help

Hi,

In my functional driver,

In the read dispatch routine I am doing :

return (IoCallDriver(deviceExtension->LowerDeviceObject,
Irp)); I am *not* calling IoMarkIrpPending in the dispatch
routune. This IRP is not created by my driver. My driver does
not do queuing of IRPs and hence no startio routine. The
driver uses DIRECT IO.

In the completion routine i am doing:

if ( Irp->PendingReturned )
{
IoMarkIrpPending(Irp);
}

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = bytesTransferred;

//some cleanup

return STATUS_SUCCESS;

The application is blocking at READFILE call until the data
is received though I specified the overlapped structure with
an event. The ReadFile call is supposed to unblock.

Let me know where I am doing wrong.

Thanks in advance.


You are currently subscribed to ntdev as: xxxxx@cmkrnl.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Does your OVERLAPPED structure contain a properly initialized and set event
handle?


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

> In the read dispatch routine I am doing :


return (IoCallDriver(deviceExtension->LowerDeviceObject, Irp));
I am *not* calling IoMarkIrpPending in the dispatch routune.

This is correct.

In the completion routine i am doing:

if ( Irp->PendingReturned )
{
IoMarkIrpPending(Irp);
}

This is correct too since you return STATUS_SUCCESS.

Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = bytesTransferred;

Never ever update the IoStatus in the completion routine, unless you
want to do some complex stuff like error code adjustment. It holds the
results of the IO operation completed by the driver below you and is
usually read-only for completion routines.

Max

“Maxim S. Shatskih” wrote:

Never ever update the IoStatus in the completion routine, unless you
want to do some complex stuff like error code adjustment. It holds the
results of the IO operation completed by the driver below you and is
usually read-only for completion routines.

This is too strong a statement. He may have piggy backed some other IRPs
on the one he got and be completing the original one with STATUS_SUCCESS
for perfectly good reasons.


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

Yes, I forgot to add the flag FILE_FLAG_OVERLAPPED in the code for the file
that I intended to do overlapped io. I have added this flag for opening the
wrong file by mistake.

Thanks for the help

From: Walter Oney
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: ReadFile with OVERLAPPED is blocking!! help
>Date: Fri, 21 Mar 2003 05:32:05 -0500
>
>xxxxx@hotmail.com wrote:
> > In the read dispatch routine I am doing :
> > return (IoCallDriver(deviceExtension->LowerDeviceObject, Irp));
> > In the completion routine i am doing:
> > if ( Irp->PendingReturned )
> > {
> > IoMarkIrpPending(Irp);
> > }
> > The application is blocking at READFILE call until the data is received
> > though I specified the overlapped structure with an event.
> > The ReadFile call is supposed to unblock.
>
>It sounds like you’re doing everything right in the driver. Are you sure
>the application opened the handle with the FILE_FLAG_OVERLAPPED flag?
>
>–
>Walter Oney, Consulting and Training
>Basic and Advanced Driver Programming Seminars
>Now teaming with John Hyde for USB Device Engineering Seminars
>Check out our schedule at http://www.oneysoft.com
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail