Bytes read equals zero during overlapped read

Hey,

I’m reading data from my NDIS miniport driver through ReadFile() with
overlapped I/O in a dedicated reading thread. I’m using
GetOverlappedResult() with the wait-parameter set to TRUE in order to block
until data has been received.

Now, what I am experiencing is that some times when GetOverlappedResult()
returns, the number of bytes read is 0, even though I can see my driver
reports another value through DbgPrint(). If I use my debugger to move the
point of execution back to the GetOverlappedResult() call, the function
returns immediately (as it should, since data has been received), and this
time around the number of bytes read are reported correctly.

What’s going on here…?

Thanks,

From your previous post, you are not using a hEvent parameter in your
OVERLAPPED structure, from the SDK on GetOverLappedResult…

Windows NT/2000/XP: If the hEvent member of the
OVERLAPPED
structure is NULL, the system uses the state of the hFile handle to signal when the operation has been completed. Use of file, named pipe, or communications-device handles for this purpose is discouraged. It is safer to use an event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device. In this situation, there is no way to know which operation caused the object’s state to be signaled.

I would suggest that you use an hEvent parameter, it is as simple as using CreateEvent to create one and initializing the hEvent member of the OVERLAPPED structure to it. You should read all the SDK docs on the file I/O calls.

At 08:10 AM 1/23/2006, =?UNKNOWN?Q?S=F8ren?= Dreijer wrote:

Hey,

I’m reading data from my NDIS miniport driver through ReadFile() with

overlapped I/O in a dedicated reading thread. I’m using

GetOverlappedResult() with the wait-parameter set to TRUE in order to block

until data has been received.

Now, what I am experiencing is that some times when GetOverlappedResult()

returns, the number of bytes read is 0, even though I can see my driver

reports another value through DbgPrint(). If I use my debugger to move the

point of execution back to the GetOverlappedResult() call, the function

returns immediately (as it should, since data has been received), and this

time around the number of bytes read are reported correctly.

What’s going on here…?

Thanks,


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@credence.com

To unsubscribe send a blank email to xxxxx@lists.osr.com


Russ Poffenberger

Credence Systems Corp.

xxxxx@credence.com

Ah, makes sense as I, as you’re pointing at, am both writing and reading.

I usually do read the docs, but this one has obviously slipped my eyes :[

Thanks once again for the quick and helpful response!
“Russell Poffenberger” wrote in message news:xxxxx@ntdev…
From your previous post, you are not using a hEvent parameter in your OVERLAPPED structure, from the SDK on GetOverLappedResult…

Windows NT/2000/XP: If the hEvent member of the OVERLAPPED structure is NULL, the system uses the state of the hFile handle to signal when the operation has been completed. Use of file, named pipe, or communications-device handles for this purpose is discouraged. It is safer to use an event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device. In this situation, there is no way to know which operation caused the object’s state to be signaled.

I would suggest that you use an hEvent parameter, it is as simple as using CreateEvent to create one and initializing the hEvent member of the OVERLAPPED structure to it. You should read all the SDK docs on the file I/O calls.

At 08:10 AM 1/23/2006, =?UNKNOWN?Q?S=F8ren?= Dreijer wrote:

Hey,

I’m reading data from my NDIS miniport driver through ReadFile() with
overlapped I/O in a dedicated reading thread. I’m using
GetOverlappedResult() with the wait-parameter set to TRUE in order to block
until data has been received.

Now, what I am experiencing is that some times when GetOverlappedResult()
returns, the number of bytes read is 0, even though I can see my driver
reports another value through DbgPrint(). If I use my debugger to move the
point of execution back to the GetOverlappedResult() call, the function
returns immediately (as it should, since data has been received), and this
time around the number of bytes read are reported correctly.

What’s going on here…?

Thanks,


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@credence.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Russ Poffenberger
Credence Systems Corp.
xxxxx@credence.com

This is just a shot in the dark (since I don’t know about NDIS drivers), but perhaps the IRPs are being completed based on a timeout value in the driver. Did you set up timeout values ( COMMTIMEOUTS ) from your app code using a call to SetCommTimeouts()? The MSDN documentation says that “unpredictable results can occur if you fail to set time-out values” using SetCommTimeouts. Do the timeouts have a non-zero default value in the driver? (From you app, can call GetCommTimeouts() to see what they are set at.)

----- Original Message -----
From: S?ren Dreijermailto:xxxxx
Newsgroups: ntdev
To: Windows System Software Devs Interest Listmailto:xxxxx
Sent: Monday, January 23, 2006 8:10 AM
Subject: [ntdev] Bytes read equals zero during overlapped read

Hey,

I’m reading data from my NDIS miniport driver through ReadFile() with
overlapped I/O in a dedicated reading thread. I’m using
GetOverlappedResult() with the wait-parameter set to TRUE in order to block
until data has been received.

Now, what I am experiencing is that some times when GetOverlappedResult()
returns, the number of bytes read is 0, even though I can see my driver
reports another value through DbgPrint(). If I use my debugger to move the
point of execution back to the GetOverlappedResult() call, the function
returns immediately (as it should, since data has been received), and this
time around the number of bytes read are reported correctly.

What’s going on here…?

Thanks,


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256http:

You are currently subscribed to ntdev as: xxxxx@msn.commailto:xxxxx
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx>