From: Alexander Grigoriev on

Does your driver ever set STATUS_CANCELLED to the requests?

b. All unused fields in OVERLAPPED should be zero-initialized.

"Anand Choubey" <anand.choubey(a)gmail.com> wrote in message
news:837a4da7-2a6d-4b96-ae16-358c09e1e54a(a)k6g2000prg.googlegroups.com...
Hi,

Thanks for reply.

a. What driver is that? Is that your custom driver?
Ans: It is custom driver.

b. 3. OVERLAPPED should be reinitialized before you call
DeviceIoControl with
it again.
Ans: I have doubt on it:
Should I create new event object i.e. CreateEvent or just
reinitialized OVERLAPPED structure field except Event field?

c. My issue is GetOverlappedResult returns 995 i.e. Thread/Application
aborted. But neither thread is aborted nor application terminated.
What would be potential reason of above error?

Could you please let me the answer of above queries?

Thanks again.

Regards,

Anand Choubey

On Mar 23, 3:53 pm, "Alexander Grigoriev" <al...(a)earthlink.net> wrote:
> 1. Your wraparound logic doesn't seem to handle a case when next expected
> is
> 0 and i=63.
>
> 2. Calling ResetEvent is not necessary. DeviceIoControl will do that.
>
> 3. OVERLAPPED should be reinitialized before you call DeviceIoControl with
> it again.
>
> 4. What driver is that? Is that your custom driver?
>
> "Anand Choubey" <anand.chou...(a)gmail.com> wrote in message
>
> news:6c199537-6f6c-4d68-be69-81a91691585d(a)a10g2000pri.googlegroups.com...
> Hi Tim,
>
> Thanks for your response.
> My answers are:
>
> a. How many requests re you issuing at once?
> Ans: 64 requested issue at once.
>
> b. Are there many threads?
> Ans: Application is having multiple threads but overlapped io is done
> by only one thread.
>
> c. How are you constructing the list of handles for
> WaitForMultipleObjects?
> Ans: There is an array of 64 overlapped events' handle.
>
> d. Are you sure you're calling GetOverlappedResult on the handle that
> was completed?
> Ans: I think so.
>
> Here is code snip:
>
> DWORD WINAPI DataHandletThread(LPVOID lpParam )
> { //wait for returns fromoverlapped
>
> iCustomBufferSizeInBytes = BUFFER_SIZE;
> TOTAL_BUFFERS = 64
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
> hEvent[i] =
> overlapped[i].hEvent =
> CreateEvent( NULL, TRUE, FALSE, NULL );
>
> if ( overlapped[i].hEvent == NULL )
> {
> rc = GetLastError();
> Log("CreateEvent failed rc=%d\n", rc );
> return 0;
> }
> }
>
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
>
> buffer[i] = (PCHAR)malloc(iCustomBufferSizeInBytes);
> if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> buffer[i], iCustomBufferSizeInBytes,
> NULL,
> &overlapped[i] ) &&
> ( rc = GetLastError() != ERROR_IO_PENDING ))
> {
> //Failed here
>
> return 0
>
> }
>
> }
>
> //Creating a circular Queue using WFMO.
> /*
> * WaitForMultipleObjects returns left mode index of events' array
> which is set.
> * Example: If events are set in following order: 62,63,0,1 then
> * WaitForMultipleObjects will returns 0, 1, 62, 63.
> * Therefore 62 and 63 should be read before 0.
> */
> int iNextExpected = 0;
> bool b1And0Buffer = false;
> i = 0;
>
> while (1) {
> //
> // check if receive buffer is returned
> //
> rc = WaitForMultipleObjects( TOTAL_BUFFERS, hEvent, FALSE,
> INFINITE );
>
> i = rc - WAIT_OBJECT_0;
>
> //This is most bundary condition, when buffer 1 comes before 0.
> if((i - iNextExpected) == -1)
> {
> b1And0Buffer = true;
>
> }
>
> if ( ( i >= 0 ) && ( i < TOTAL_BUFFERS ) )
> {
> //
> // get receive buffer info
> //
> for(int iIndex = iNextExpected; b1And0Buffer || (iIndex != (i + 1)
> % TOTAL_BUFFERS); iIndex = (iIndex + 1) % TOTAL_BUFFERS)
> {
> b1And0Buffer = false;
> ResetEvent(hEvent[iIndex]);
>
> if ( GetOverlappedResult( hIoctl, &overlapped[iIndex],
> &bytesReceived,
> FALSE ) )
> {
>
> if(filterStopping)
> break;
> bl = (msg_buffer*) buffer[iIndex];
>
> //Data processing here
> //with b1
>
> //Reissue the overlapped DIOC request.
> if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> buffer[iIndex], iCustomBufferSizeInBytes,
> NULL, &overlapped[iIndex] ) &&
> ( rc = GetLastError() != ERROR_IO_PENDING ) )
> {
> //Log error here DIOC failed.
> break;
>
> }
> }
>
> else
> {
> if(ERROR_IO_INCOMPLETE != GetLastError())
> {
> //995 Error occurs.
> Log("GetOverlappedResult failed Error %d", GetLastError());}
> break;
> }
> }
>
> }
> else
> {
> Log("WaitForMultipleObjects failed i = %d rc=%d\n", i, rc);
> break;
>
> }
>
> iNextExpected = (i + 1) % TOTAL_BUFFERS;
> }
>
> //
> // cleanup and exit
> //
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
> if ( overlapped[i].hEvent )
> {
> CloseHandle( overlapped[i].hEvent );
> }
> }
>
> return 0;
>
> }
>
> Regards,
> Anand Choubey
>
> On Mar 22, 9:12 pm, Tim Roberts <t...(a)probo.com> wrote:
>
>
>
> > Anand Choubey <anand.chou...(a)gmail.com> wrote:
>
> > >I am facing an issue with my driver and user land code. User land code
> > >communicates with driver using overlapped IO mechanism which is
> > >straight forward.
> > >Basic algorithm is at user land:
>
> > >Thread()
> > >{
> > > Initialize overlapped structure with event = CreateEvent() with
> > >Manual Event Set
> > >issue_again:
> > > Issue IO request using DeviceIOControl()
>
> > > WaitForMultipleObjects() on overlapped events.
>
> > > if(event is signaled) then ResetEvent, check result using
> > >GetOverlappedResult(), process data and goto issue_again:
> > > }
>
> > >Driver side is simple:
> > >just complete IO request.
>
> > >I do not know exact scenario/reason but sometime GetOverlappedResult
> > >returns 995.
>
> > If you don't know the exact scenario, then there's no possible way to
> > diagnose this. How many requests re you issuing at once? Are there many
> > threads? How are you constructing the list of handles for
> > WaitForMultipleObjects? Are you sure you're calling GetOverlappedResult
> > on
> > the handle that was completed?
>
> > Why don't you post the code? We'll see if anything looks unusual.
> > --
> > Tim Roberts, t...(a)probo.com
> > Providenza & Boekelheide, Inc.


From: m on
This is unrelated to your main problem, but have you considered using the
thread pool functions / IOCP? Your current implementation is an inefficient
way to handle IO completion in Windows and even if your IO rate is low, it
always feels better not to waste resources.

BTW: on some versions of Windows (pre Vista IIRC) this error can occur when
the thread that issued the IOOP terminates while it is still in progress.
The error can also occur if the handle is closed while the operation is in
progress, or after a call to CancelIo() or CancelIoEx(). As this is a
custom device, you can likely find out what other circumstances can cause
and IOOP (IRP) to be canceled - typical examples might include network
disconnect or surprise removal

"Anand Choubey" <anand.choubey(a)gmail.com> wrote in message
news:6c199537-6f6c-4d68-be69-81a91691585d(a)a10g2000pri.googlegroups.com...
> Hi Tim,
>
> Thanks for your response.
> My answers are:
>
> a. How many requests re you issuing at once?
> Ans: 64 requested issue at once.
>
> b. Are there many threads?
> Ans: Application is having multiple threads but overlapped io is done
> by only one thread.
>
> c. How are you constructing the list of handles for
> WaitForMultipleObjects?
> Ans: There is an array of 64 overlapped events' handle.
>
> d. Are you sure you're calling GetOverlappedResult on the handle that
> was completed?
> Ans: I think so.
>
> Here is code snip:
>
>
> DWORD WINAPI DataHandletThread(LPVOID lpParam )
> { //wait for returns fromoverlapped
>
>
> iCustomBufferSizeInBytes = BUFFER_SIZE;
> TOTAL_BUFFERS = 64
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
> hEvent[i] =
> overlapped[i].hEvent =
> CreateEvent( NULL, TRUE, FALSE, NULL );
>
> if ( overlapped[i].hEvent == NULL )
> {
> rc = GetLastError();
> Log("CreateEvent failed rc=%d\n", rc );
> return 0;
> }
> }
>
>
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
>
> buffer[i] = (PCHAR)malloc(iCustomBufferSizeInBytes);
> if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> buffer[i], iCustomBufferSizeInBytes,
> NULL,
> &overlapped[i] ) &&
> ( rc = GetLastError() != ERROR_IO_PENDING ))
> {
> //Failed here
>
> return 0
> }
>
> }
>
> //Creating a circular Queue using WFMO.
> /*
> * WaitForMultipleObjects returns left mode index of events' array
> which is set.
> * Example: If events are set in following order: 62,63,0,1 then
> * WaitForMultipleObjects will returns 0, 1, 62, 63.
> * Therefore 62 and 63 should be read before 0.
> */
> int iNextExpected = 0;
> bool b1And0Buffer = false;
> i = 0;
>
> while (1) {
> //
> // check if receive buffer is returned
> //
> rc = WaitForMultipleObjects( TOTAL_BUFFERS, hEvent, FALSE,
> INFINITE );
>
> i = rc - WAIT_OBJECT_0;
>
> //This is most bundary condition, when buffer 1 comes before 0.
> if((i - iNextExpected) == -1)
> {
> b1And0Buffer = true;
> }
>
>
> if ( ( i >= 0 ) && ( i < TOTAL_BUFFERS ) )
> {
> //
> // get receive buffer info
> //
> for(int iIndex = iNextExpected; b1And0Buffer || (iIndex != (i + 1)
> % TOTAL_BUFFERS); iIndex = (iIndex + 1) % TOTAL_BUFFERS)
> {
> b1And0Buffer = false;
> ResetEvent(hEvent[iIndex]);
>
> if ( GetOverlappedResult( hIoctl, &overlapped[iIndex],
> &bytesReceived,
> FALSE ) )
> {
>
> if(filterStopping)
> break;
> bl = (msg_buffer*) buffer[iIndex];
>
> //Data processing here
> //with b1
>
>
> //Reissue the overlapped DIOC request.
> if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> buffer[iIndex], iCustomBufferSizeInBytes,
> NULL, &overlapped[iIndex] ) &&
> ( rc = GetLastError() != ERROR_IO_PENDING ) )
> {
> //Log error here DIOC failed.
> break;
> }
>
> }
> else
> {
> if(ERROR_IO_INCOMPLETE != GetLastError())
> {
> //995 Error occurs.
> Log("GetOverlappedResult failed Error %d", GetLastError());
> }
> break;
> }
> }
> }
> else
> {
> Log("WaitForMultipleObjects failed i = %d rc=%d\n", i, rc);
> break;
> }
>
> iNextExpected = (i + 1) % TOTAL_BUFFERS;
> }
>
>
> //
> // cleanup and exit
> //
> for ( i = 0; i < TOTAL_BUFFERS; i++ )
> {
> if ( overlapped[i].hEvent )
> {
> CloseHandle( overlapped[i].hEvent );
> }
> }
>
> return 0;
> }
>
>
>
> Regards,
> Anand Choubey
>
> On Mar 22, 9:12 pm, Tim Roberts <t...(a)probo.com> wrote:
>> Anand Choubey <anand.chou...(a)gmail.com> wrote:
>>
>> >I am facing an issue with my driver and user land code. User land code
>> >communicates with driver using overlapped IO mechanism which is
>> >straight forward.
>> >Basic algorithm is at user land:
>>
>> >Thread()
>> >{
>> > Initialize overlapped structure with event = CreateEvent() with
>> >Manual Event Set
>> >issue_again:
>> > Issue IO request using DeviceIOControl()
>>
>> > WaitForMultipleObjects() on overlapped events.
>>
>> > if(event is signaled) then ResetEvent, check result using
>> >GetOverlappedResult(), process data and goto issue_again:
>> > }
>>
>> >Driver side is simple:
>> >just complete IO request.
>>
>> >I do not know exact scenario/reason but sometime GetOverlappedResult
>> >returns 995.
>>
>> If you don't know the exact scenario, then there's no possible way to
>> diagnose this. How many requests re you issuing at once? Are there many
>> threads? How are you constructing the list of handles for
>> WaitForMultipleObjects? Are you sure you're calling GetOverlappedResult
>> on
>> the handle that was completed?
>>
>> Why don't you post the code? We'll see if anything looks unusual.
>> --
>> Tim Roberts, t...(a)probo.com
>> Providenza & Boekelheide, Inc.
>
From: Anand Choubey on
Hi,

Thanks for reply and great suggestion.
I am using Cancel Safe Queue on driver side. I cancel the IRP in this
csq cancel routine only.

As per my understanding, cancel routine is called only if either
application is abnormally terminated or application closes driver
handle. Both thing did not happen with the application/driver.

Are there more reason to cancel IRP?

If IRP is cancelled then does 995 error occur?

Regards,
Anand Choubey

On Mar 23, 7:17 pm, "m" <m...(a)b.c> wrote:
> This is unrelated to your main problem, but have you considered using the
> thread pool functions / IOCP?  Your current implementation is an inefficient
> way to handle IO completion in Windows and even if your IO rate is low, it
> always feels better not to waste resources.
>
> BTW: on some versions of Windows (pre Vista IIRC) this error can occur when
> the thread that issued the IOOP terminates while it is still in progress.
> The error can also occur if the handle is closed while the operation is in
> progress, or after a call to CancelIo() or CancelIoEx().  As this is a
> custom device, you can likely find out what other circumstances can cause
> and IOOP (IRP) to be canceled - typical examples might include network
> disconnect or surprise removal
>
> "Anand Choubey" <anand.chou...(a)gmail.com> wrote in message
>
> news:6c199537-6f6c-4d68-be69-81a91691585d(a)a10g2000pri.googlegroups.com...
>
>
>
> > Hi Tim,
>
> > Thanks for your response.
> > My answers are:
>
> > a. How many requests re you issuing at once?
> > Ans: 64 requested issue at once.
>
> > b. Are there many threads?
> > Ans: Application is having multiple threads but overlapped io is done
> > by only one thread.
>
> > c. How are you constructing the list of handles for
> > WaitForMultipleObjects?
> > Ans: There is an array of 64 overlapped events' handle.
>
> > d. Are you sure you're calling GetOverlappedResult on the handle that
> > was completed?
> > Ans:  I think so.
>
> > Here is code snip:
>
> > DWORD WINAPI DataHandletThread(LPVOID lpParam )
> > {   //wait for returns fromoverlapped
>
> >    iCustomBufferSizeInBytes = BUFFER_SIZE;
> >    TOTAL_BUFFERS = 64
> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >    {
> >       hEvent[i] =
> >            overlapped[i].hEvent =
> >            CreateEvent( NULL, TRUE, FALSE, NULL );
>
> >        if ( overlapped[i].hEvent == NULL )
> >        {
> >            rc = GetLastError();
> >            Log("CreateEvent failed rc=%d\n", rc );
> >            return 0;
> >        }
> >    }
>
> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >    {
>
> > buffer[i] = (PCHAR)malloc(iCustomBufferSizeInBytes);
> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> > buffer[i], iCustomBufferSizeInBytes,
> > NULL,
> > &overlapped[i] ) &&
> > ( rc = GetLastError() != ERROR_IO_PENDING ))
> > {
> > //Failed here
>
> > return 0
> > }
>
> >    }
>
> > //Creating a circular Queue using WFMO.
> > /*
> > * WaitForMultipleObjects returns left mode index of events' array
> > which is set.
> > * Example: If events are set in following order: 62,63,0,1 then
> > * WaitForMultipleObjects will returns 0, 1, 62, 63.
> > * Therefore 62 and 63 should be read before 0.
> > */
> > int iNextExpected = 0;
> > bool b1And0Buffer = false;
> > i = 0;
>
> >    while (1) {
> >        //
> >        // check if receive buffer is returned
> >        //
> >        rc = WaitForMultipleObjects( TOTAL_BUFFERS, hEvent, FALSE,
> > INFINITE );
>
> >        i = rc - WAIT_OBJECT_0;
>
> > //This is most bundary condition, when buffer 1 comes before 0.
> > if((i - iNextExpected) == -1)
> > {
> > b1And0Buffer = true;
> > }
>
> >        if ( ( i >= 0 ) && ( i < TOTAL_BUFFERS ) )
> >        {
> >            //
> >            // get receive buffer info
> >            //
> > for(int iIndex = iNextExpected; b1And0Buffer || (iIndex != (i + 1)
> > % TOTAL_BUFFERS); iIndex = (iIndex + 1) % TOTAL_BUFFERS)
> > {
> > b1And0Buffer = false;
> > ResetEvent(hEvent[iIndex]);
>
> > if ( GetOverlappedResult( hIoctl, &overlapped[iIndex],
> > &bytesReceived,
> > FALSE ) )
> > {
>
> > if(filterStopping)
> > break;
> > bl = (msg_buffer*) buffer[iIndex];
>
> > //Data processing here
> > //with b1
>
> > //Reissue the overlapped DIOC request.
> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> > buffer[iIndex], iCustomBufferSizeInBytes,
> > NULL, &overlapped[iIndex] ) &&
> > ( rc = GetLastError() != ERROR_IO_PENDING ) )
> > {
> > //Log error here DIOC failed.
> > break;
> > }
>
> > }
> > else
> > {
> > if(ERROR_IO_INCOMPLETE != GetLastError())
> > {
> > //995 Error occurs.
> > Log("GetOverlappedResult failed Error %d", GetLastError());
> > }
> > break;
> > }
> > }
> >        }
> >        else
> > {
> > Log("WaitForMultipleObjects failed i = %d rc=%d\n", i, rc);
> > break;
> > }
>
> > iNextExpected = (i + 1) % TOTAL_BUFFERS;
> >    }
>
> >    //
> >    // cleanup and exit
> >    //
> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >    {
> >        if ( overlapped[i].hEvent )
> >        {
> >            CloseHandle( overlapped[i].hEvent );
> >        }
> >    }
>
> >    return 0;
> > }
>
> > Regards,
> > Anand Choubey
>
> > On Mar 22, 9:12 pm, Tim Roberts <t...(a)probo.com> wrote:
> >> Anand Choubey <anand.chou...(a)gmail.com> wrote:
>
> >> >I am facing an issue with my driver and user land code. User land code
> >> >communicates with driver using overlapped IO mechanism which is
> >> >straight forward.
> >> >Basic algorithm is at user land:
>
> >> >Thread()
> >> >{
> >> >      Initialize overlapped structure with event = CreateEvent() with
> >> >Manual Event Set
> >> >issue_again:
> >> >      Issue IO request using DeviceIOControl()
>
> >> >     WaitForMultipleObjects() on overlapped events.
>
> >> >     if(event is signaled) then ResetEvent, check result using
> >> >GetOverlappedResult(), process data and goto issue_again:
> >> >  }
>
> >> >Driver side is simple:
> >> >just complete IO request.
>
> >> >I do not know exact scenario/reason but sometime GetOverlappedResult
> >> >returns 995.
>
> >> If you don't know the exact scenario, then there's no possible way to
> >> diagnose this.  How many requests re you issuing at once?  Are there many
> >> threads?  How are you constructing the list of handles for
> >> WaitForMultipleObjects?  Are you sure you're calling GetOverlappedResult
> >> on
> >> the handle that was completed?
>
> >> Why don't you post the code?  We'll see if anything looks unusual.
> >> --
> >> Tim Roberts, t...(a)probo.com
> >> Providenza & Boekelheide, Inc.

From: m on
995 is ERROR_OPERATION_ABORTED
(http://msdn.microsoft.com/en-us/library/ms681388(VS.85).aspx)

Since your driver does not intentionally cancel the IRP, then there is
either a call to CancelIo, CancelIoEx, or CloseHandle (implicit on process
termination) or a bug in your driver. I suggest that you enable some kind
of call tracing or hook up a debugger and see what your driver and app are
doing when you encounter this problem. You can also try a simplified
application with non-overlapped IO and see if that fails too - although any
decent driver in Windows must support overlapped IO with multiple pended
requests or else it will be banned as junk / malware.

"Anand Choubey" <anand.choubey(a)gmail.com> wrote in message
news:59c7ea45-0313-42ea-9e74-c394621bed0d(a)t23g2000yqt.googlegroups.com...
> Hi,
>
> Thanks for reply and great suggestion.
> I am using Cancel Safe Queue on driver side. I cancel the IRP in this
> csq cancel routine only.
>
> As per my understanding, cancel routine is called only if either
> application is abnormally terminated or application closes driver
> handle. Both thing did not happen with the application/driver.
>
> Are there more reason to cancel IRP?
>
> If IRP is cancelled then does 995 error occur?
>
> Regards,
> Anand Choubey
>
> On Mar 23, 7:17 pm, "m" <m...(a)b.c> wrote:
>> This is unrelated to your main problem, but have you considered using the
>> thread pool functions / IOCP? Your current implementation is an
>> inefficient
>> way to handle IO completion in Windows and even if your IO rate is low,
>> it
>> always feels better not to waste resources.
>>
>> BTW: on some versions of Windows (pre Vista IIRC) this error can occur
>> when
>> the thread that issued the IOOP terminates while it is still in progress.
>> The error can also occur if the handle is closed while the operation is
>> in
>> progress, or after a call to CancelIo() or CancelIoEx(). As this is a
>> custom device, you can likely find out what other circumstances can cause
>> and IOOP (IRP) to be canceled - typical examples might include network
>> disconnect or surprise removal
>>
>> "Anand Choubey" <anand.chou...(a)gmail.com> wrote in message
>>
>> news:6c199537-6f6c-4d68-be69-81a91691585d(a)a10g2000pri.googlegroups.com...
>>
>>
>>
>> > Hi Tim,
>>
>> > Thanks for your response.
>> > My answers are:
>>
>> > a. How many requests re you issuing at once?
>> > Ans: 64 requested issue at once.
>>
>> > b. Are there many threads?
>> > Ans: Application is having multiple threads but overlapped io is done
>> > by only one thread.
>>
>> > c. How are you constructing the list of handles for
>> > WaitForMultipleObjects?
>> > Ans: There is an array of 64 overlapped events' handle.
>>
>> > d. Are you sure you're calling GetOverlappedResult on the handle that
>> > was completed?
>> > Ans: I think so.
>>
>> > Here is code snip:
>>
>> > DWORD WINAPI DataHandletThread(LPVOID lpParam )
>> > { //wait for returns fromoverlapped
>>
>> > iCustomBufferSizeInBytes = BUFFER_SIZE;
>> > TOTAL_BUFFERS = 64
>> > for ( i = 0; i < TOTAL_BUFFERS; i++ )
>> > {
>> > hEvent[i] =
>> > overlapped[i].hEvent =
>> > CreateEvent( NULL, TRUE, FALSE, NULL );
>>
>> > if ( overlapped[i].hEvent == NULL )
>> > {
>> > rc = GetLastError();
>> > Log("CreateEvent failed rc=%d\n", rc );
>> > return 0;
>> > }
>> > }
>>
>> > for ( i = 0; i < TOTAL_BUFFERS; i++ )
>> > {
>>
>> > buffer[i] = (PCHAR)malloc(iCustomBufferSizeInBytes);
>> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
>> > buffer[i], iCustomBufferSizeInBytes,
>> > NULL,
>> > &overlapped[i] ) &&
>> > ( rc = GetLastError() != ERROR_IO_PENDING ))
>> > {
>> > //Failed here
>>
>> > return 0
>> > }
>>
>> > }
>>
>> > //Creating a circular Queue using WFMO.
>> > /*
>> > * WaitForMultipleObjects returns left mode index of events' array
>> > which is set.
>> > * Example: If events are set in following order: 62,63,0,1 then
>> > * WaitForMultipleObjects will returns 0, 1, 62, 63.
>> > * Therefore 62 and 63 should be read before 0.
>> > */
>> > int iNextExpected = 0;
>> > bool b1And0Buffer = false;
>> > i = 0;
>>
>> > while (1) {
>> > //
>> > // check if receive buffer is returned
>> > //
>> > rc = WaitForMultipleObjects( TOTAL_BUFFERS, hEvent, FALSE,
>> > INFINITE );
>>
>> > i = rc - WAIT_OBJECT_0;
>>
>> > //This is most bundary condition, when buffer 1 comes before 0.
>> > if((i - iNextExpected) == -1)
>> > {
>> > b1And0Buffer = true;
>> > }
>>
>> > if ( ( i >= 0 ) && ( i < TOTAL_BUFFERS ) )
>> > {
>> > //
>> > // get receive buffer info
>> > //
>> > for(int iIndex = iNextExpected; b1And0Buffer || (iIndex != (i + 1)
>> > % TOTAL_BUFFERS); iIndex = (iIndex + 1) % TOTAL_BUFFERS)
>> > {
>> > b1And0Buffer = false;
>> > ResetEvent(hEvent[iIndex]);
>>
>> > if ( GetOverlappedResult( hIoctl, &overlapped[iIndex],
>> > &bytesReceived,
>> > FALSE ) )
>> > {
>>
>> > if(filterStopping)
>> > break;
>> > bl = (msg_buffer*) buffer[iIndex];
>>
>> > //Data processing here
>> > //with b1
>>
>> > //Reissue the overlapped DIOC request.
>> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
>> > buffer[iIndex], iCustomBufferSizeInBytes,
>> > NULL, &overlapped[iIndex] ) &&
>> > ( rc = GetLastError() != ERROR_IO_PENDING ) )
>> > {
>> > //Log error here DIOC failed.
>> > break;
>> > }
>>
>> > }
>> > else
>> > {
>> > if(ERROR_IO_INCOMPLETE != GetLastError())
>> > {
>> > //995 Error occurs.
>> > Log("GetOverlappedResult failed Error %d", GetLastError());
>> > }
>> > break;
>> > }
>> > }
>> > }
>> > else
>> > {
>> > Log("WaitForMultipleObjects failed i = %d rc=%d\n", i, rc);
>> > break;
>> > }
>>
>> > iNextExpected = (i + 1) % TOTAL_BUFFERS;
>> > }
>>
>> > //
>> > // cleanup and exit
>> > //
>> > for ( i = 0; i < TOTAL_BUFFERS; i++ )
>> > {
>> > if ( overlapped[i].hEvent )
>> > {
>> > CloseHandle( overlapped[i].hEvent );
>> > }
>> > }
>>
>> > return 0;
>> > }
>>
>> > Regards,
>> > Anand Choubey
>>
>> > On Mar 22, 9:12 pm, Tim Roberts <t...(a)probo.com> wrote:
>> >> Anand Choubey <anand.chou...(a)gmail.com> wrote:
>>
>> >> >I am facing an issue with my driver and user land code. User land
>> >> >code
>> >> >communicates with driver using overlapped IO mechanism which is
>> >> >straight forward.
>> >> >Basic algorithm is at user land:
>>
>> >> >Thread()
>> >> >{
>> >> > Initialize overlapped structure with event = CreateEvent() with
>> >> >Manual Event Set
>> >> >issue_again:
>> >> > Issue IO request using DeviceIOControl()
>>
>> >> > WaitForMultipleObjects() on overlapped events.
>>
>> >> > if(event is signaled) then ResetEvent, check result using
>> >> >GetOverlappedResult(), process data and goto issue_again:
>> >> > }
>>
>> >> >Driver side is simple:
>> >> >just complete IO request.
>>
>> >> >I do not know exact scenario/reason but sometime GetOverlappedResult
>> >> >returns 995.
>>
>> >> If you don't know the exact scenario, then there's no possible way to
>> >> diagnose this. How many requests re you issuing at once? Are there
>> >> many
>> >> threads? How are you constructing the list of handles for
>> >> WaitForMultipleObjects? Are you sure you're calling
>> >> GetOverlappedResult
>> >> on
>> >> the handle that was completed?
>>
>> >> Why don't you post the code? We'll see if anything looks unusual.
>> >> --
>> >> Tim Roberts, t...(a)probo.com
>> >> Providenza & Boekelheide, Inc.
>
From: Anand Choubey on
Thanks a lot you guys to improve my understanding about the system.

Regards,

Anand Choubey
On Mar 24, 7:11 pm, "m" <m...(a)b.c> wrote:
> 995 is ERROR_OPERATION_ABORTED
> (http://msdn.microsoft.com/en-us/library/ms681388(VS.85).aspx)
>
> Since your driver does not intentionally cancel the IRP, then there is
> either a call to CancelIo, CancelIoEx, or CloseHandle (implicit on process
> termination) or a bug in your driver.  I suggest that you enable some kind
> of call tracing or hook up a debugger and see what your driver and app are
> doing when you encounter this problem.  You can also try a simplified
> application with non-overlapped IO and see if that fails too - although any
> decent driver in Windows must support overlapped IO with multiple pended
> requests or else it will be banned as junk / malware.
>
> "Anand Choubey" <anand.chou...(a)gmail.com> wrote in message
>
> news:59c7ea45-0313-42ea-9e74-c394621bed0d(a)t23g2000yqt.googlegroups.com...
>
>
>
> > Hi,
>
> > Thanks for reply and great suggestion.
> > I am using Cancel Safe Queue on driver side. I cancel the IRP in this
> > csq cancel routine only.
>
> > As per my understanding, cancel routine is called  only if either
> > application is abnormally terminated or application closes driver
> > handle. Both thing did not happen with the application/driver.
>
> > Are there more reason to cancel IRP?
>
> > If IRP is cancelled then does 995 error occur?
>
> > Regards,
> > Anand Choubey
>
> > On Mar 23, 7:17 pm, "m" <m...(a)b.c> wrote:
> >> This is unrelated to your main problem, but have you considered using the
> >> thread pool functions / IOCP?  Your current implementation is an
> >> inefficient
> >> way to handle IO completion in Windows and even if your IO rate is low,
> >> it
> >> always feels better not to waste resources.
>
> >> BTW: on some versions of Windows (pre Vista IIRC) this error can occur
> >> when
> >> the thread that issued the IOOP terminates while it is still in progress.
> >> The error can also occur if the handle is closed while the operation is
> >> in
> >> progress, or after a call to CancelIo() or CancelIoEx().  As this is a
> >> custom device, you can likely find out what other circumstances can cause
> >> and IOOP (IRP) to be canceled - typical examples might include network
> >> disconnect or surprise removal
>
> >> "Anand Choubey" <anand.chou...(a)gmail.com> wrote in message
>
> >>news:6c199537-6f6c-4d68-be69-81a91691585d(a)a10g2000pri.googlegroups.com....
>
> >> > Hi Tim,
>
> >> > Thanks for your response.
> >> > My answers are:
>
> >> > a. How many requests re you issuing at once?
> >> > Ans: 64 requested issue at once.
>
> >> > b. Are there many threads?
> >> > Ans: Application is having multiple threads but overlapped io is done
> >> > by only one thread.
>
> >> > c. How are you constructing the list of handles for
> >> > WaitForMultipleObjects?
> >> > Ans: There is an array of 64 overlapped events' handle.
>
> >> > d. Are you sure you're calling GetOverlappedResult on the handle that
> >> > was completed?
> >> > Ans:  I think so.
>
> >> > Here is code snip:
>
> >> > DWORD WINAPI DataHandletThread(LPVOID lpParam )
> >> > {   //wait for returns fromoverlapped
>
> >> >    iCustomBufferSizeInBytes = BUFFER_SIZE;
> >> >    TOTAL_BUFFERS = 64
> >> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >> >    {
> >> >       hEvent[i] =
> >> >            overlapped[i].hEvent =
> >> >            CreateEvent( NULL, TRUE, FALSE, NULL );
>
> >> >        if ( overlapped[i].hEvent == NULL )
> >> >        {
> >> >            rc = GetLastError();
> >> >            Log("CreateEvent failed rc=%d\n", rc );
> >> >            return 0;
> >> >        }
> >> >    }
>
> >> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >> >    {
>
> >> > buffer[i] = (PCHAR)malloc(iCustomBufferSizeInBytes);
> >> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> >> > buffer[i], iCustomBufferSizeInBytes,
> >> > NULL,
> >> > &overlapped[i] ) &&
> >> > ( rc = GetLastError() != ERROR_IO_PENDING ))
> >> > {
> >> > //Failed here
>
> >> > return 0
> >> > }
>
> >> >    }
>
> >> > //Creating a circular Queue using WFMO.
> >> > /*
> >> > * WaitForMultipleObjects returns left mode index of events' array
> >> > which is set.
> >> > * Example: If events are set in following order: 62,63,0,1 then
> >> > * WaitForMultipleObjects will returns 0, 1, 62, 63.
> >> > * Therefore 62 and 63 should be read before 0.
> >> > */
> >> > int iNextExpected = 0;
> >> > bool b1And0Buffer = false;
> >> > i = 0;
>
> >> >    while (1) {
> >> >        //
> >> >        // check if receive buffer is returned
> >> >        //
> >> >        rc = WaitForMultipleObjects( TOTAL_BUFFERS, hEvent, FALSE,
> >> > INFINITE );
>
> >> >        i = rc - WAIT_OBJECT_0;
>
> >> > //This is most bundary condition, when buffer 1 comes before 0.
> >> > if((i - iNextExpected) == -1)
> >> > {
> >> > b1And0Buffer = true;
> >> > }
>
> >> >        if ( ( i >= 0 ) && ( i < TOTAL_BUFFERS ) )
> >> >        {
> >> >            //
> >> >            // get receive buffer info
> >> >            //
> >> > for(int iIndex = iNextExpected; b1And0Buffer || (iIndex != (i + 1)
> >> > % TOTAL_BUFFERS); iIndex = (iIndex + 1) % TOTAL_BUFFERS)
> >> > {
> >> > b1And0Buffer = false;
> >> > ResetEvent(hEvent[iIndex]);
>
> >> > if ( GetOverlappedResult( hIoctl, &overlapped[iIndex],
> >> > &bytesReceived,
> >> > FALSE ) )
> >> > {
>
> >> > if(filterStopping)
> >> > break;
> >> > bl = (msg_buffer*) buffer[iIndex];
>
> >> > //Data processing here
> >> > //with b1
>
> >> > //Reissue the overlapped DIOC request.
> >> > if ( !DeviceIoControl( hIoctl, IOCTL_GET_DATA, NULL, 0,
> >> > buffer[iIndex], iCustomBufferSizeInBytes,
> >> > NULL, &overlapped[iIndex] ) &&
> >> > ( rc = GetLastError() != ERROR_IO_PENDING ) )
> >> > {
> >> > //Log error here DIOC failed.
> >> > break;
> >> > }
>
> >> > }
> >> > else
> >> > {
> >> > if(ERROR_IO_INCOMPLETE != GetLastError())
> >> > {
> >> > //995 Error occurs.
> >> > Log("GetOverlappedResult failed Error %d", GetLastError());
> >> > }
> >> > break;
> >> > }
> >> > }
> >> >        }
> >> >        else
> >> > {
> >> > Log("WaitForMultipleObjects failed i = %d rc=%d\n", i, rc);
> >> > break;
> >> > }
>
> >> > iNextExpected = (i + 1) % TOTAL_BUFFERS;
> >> >    }
>
> >> >    //
> >> >    // cleanup and exit
> >> >    //
> >> >    for ( i = 0; i < TOTAL_BUFFERS; i++ )
> >> >    {
> >> >        if ( overlapped[i].hEvent )
> >> >        {
> >> >            CloseHandle( overlapped[i].hEvent );
> >> >        }
> >> >    }
>
> >> >    return 0;
> >> > }
>
> >> > Regards,
> >> > Anand Choubey
>
> >> > On Mar 22, 9:12 pm, Tim Roberts <t...(a)probo.com> wrote:
> >> >> Anand Choubey <anand.chou...(a)gmail.com> wrote:
>
> >> >> >I am facing an issue with my driver and user land code. User land
> >> >> >code
> >> >> >communicates with driver using overlapped IO mechanism which is
> >> >> >straight forward.
> >> >> >Basic algorithm is at user land:
>
> >> >> >Thread()
> >> >> >{
> >> >> >      Initialize overlapped structure with event = CreateEvent() with
> >> >> >Manual Event Set
> >> >> >issue_again:
> >> >> >      Issue IO request using DeviceIOControl()
>
> >> >> >     WaitForMultipleObjects() on overlapped events.
>
> >> >> >     if(event is signaled) then ResetEvent, check result using
> >> >> >GetOverlappedResult(), process data and goto issue_again:
> >> >> >  }
>
> >> >> >Driver side is simple:
> >> >> >just complete IO request.
>
> >> >> >I do not know exact scenario/reason but sometime GetOverlappedResult
> >> >> >returns 995.
>
> >> >> If you don't know the exact scenario, then there's no possible way to
> >> >> diagnose this.  How many requests re you issuing at once?  Are there
> >> >> many
> >> >> threads?  How are you constructing the list of handles for
> >> >> WaitForMultipleObjects?  Are you sure you're calling
> >> >> GetOverlappedResult
> >> >> on
> >> >> the handle that was completed?
>
> >> >> Why don't you post the code?  We'll see if anything looks unusual..
> >> >> --
> >> >> Tim Roberts, t...(a)probo.com
> >> >> Providenza & Boekelheide, Inc.