Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IOCompletionCallback

0 views
Skip to first unread message

Roy Chastain

unread,
Mar 21, 2003, 3:08:10 PM3/21/03
to
I want to use asynchronous I/O, but I don't want to use the mechanism
that is given as an example in Asynchronous File I/O. I found the
IOCompletionCallback Delegate, but absolutely no information on how to
use it.

The text says 'Receives the error code, number of bytes, and
overlapped value type when an I/O operation completes on the thread
pool'. This appears to be a wrapper for GetQueuedCompletionStatus
which is exactly the call that I would be making if I were using the
API.

How do I use IOCompletionCallback and IO Completions?

Thanks

-------------------------------------------
Roy Chastain
KMSystems, Inc.

Jun Su [MSFT]

unread,
Mar 24, 2003, 1:33:17 AM3/24/03
to
Hi,

If your code runs on the Windows NT/2K/XP/2003, several part of .NET
framework will use IO Completion port. Such as FileStream, Sockets. In most
scenerio, you need not use the completion port manually. The Framework will
do it for you. Depending on the target platform, the .NET Framework will
decide to use the IOCompletionPorts API or not, maximizing the performance
and minimizing the resources.

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: Roy Chastain <r...@kmsys.com>
| Subject: IOCompletionCallback
| Date: Fri, 21 Mar 2003 15:08:10 -0500

Roy Chastain

unread,
Mar 24, 2003, 6:43:49 AM3/24/03
to
No, this answer does not really help. I already have this part of the
in formation. What I want to do is be able to wait a thread in a pool
on a single completion port. Things should go like this.

A worker thread gets a task. I completes the task (starts an IO). It
goes to GetQueuedCompletionStatus and waits for the next task
(completion of ANY IO).

The model being presented in the book for asynchronous IO is more like
this.

Main thread kicks off IO. Worker tread gets notified that IO has
started. Worker thread does ENDxxxx to wait for IO to complete. The
worker thread does not get any work done in this model. It just does
not make any sense to me. Why have threads waiting on IO when they
have nothing else to do or any reason to be around?

Jun Su [MSFT]

unread,
Mar 25, 2003, 1:47:02 AM3/25/03
to
Hi,

The worker thread will not waiting for IO when you use Asynchronous IO. The
following is from MSDN:
===========
Using asynchronous I/O completion events, a thread from the thread pool
will process data only when the data is received, and once the data has
been processed, the thread will return to the thread pool.

To make an asynchronous I/O call, an operating-system I/O handle must be
associated with the thread pool and a callback method must be specified.
When the I/O operation completes, a thread from the thread pool invokes the
callback method.
============
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconioasynchronouscomp
letion.asp

When you call EndXXX in the callback method, it is used to figure out how
much data are read or written. Please also check the following link:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconasynchronousfileio
.asp

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: Roy Chastain <r...@kmsys.com>

| Subject: Re: IOCompletionCallback
| Date: Mon, 24 Mar 2003 06:43:49 -0500

Roy Chastain

unread,
Mar 25, 2003, 10:53:40 AM3/25/03
to
My point of confusion was that some of the documentation indicated
that when a AsyncCallback was passed to the BeginXXX method (in my
case BeginConnect), a different thread was activated from the thread
pool to do the IO and that the activated thread immediately called the
callback function and then the callback function would have to wait
(via EndConnect for example) for the connect to be done.

The implication of the above is that I have an entire thread pool
worth of threads each waiting on 1 and only 1 IO to complete. That is
not a good model.

Now, if I reread and decide that it really means that the callback is
not called until the IO is complete and (in the case of the
AsyncCallback) the EndConnect is simply to transfer the completion
status from its hiding place to where I can see it, then the model
makes more sense.

Now for even more trouble.
I just put a breakpoint in my AsyncCallback function and looked at the
Socket Object that I am using to do a BeginConnect. There is a
property called UseOverlappedIO on that object (The property is
completely undocumented.) that is FALSE. That implies to me that it
is not doing overlapped IO. I need overlapped IO for performance.

Can someone at MS please step and clear up this confusion.
1) - Does Socket Class use Overlapped IO?
2) - If so, how do I use it.
3) - What is the purpose of the IOCOmpletionCallback delegate
4) - If Socket Class does not use Overlapped IO, some direction as to
how to do it myself in managed code would be helpful.
5) - How do I really tell that the connect worked. I am trying to
connect to an system that does not exist, yet the AsyncCallback is
getting called and the EndConnect is returning. There is not
exception and there is no place to check a status that I know about.
In fact NETSTAT indicates the socket is in FIN_WAIT_2. That is not a
completed connect in my book.

This is the 3rd time I have tried to get some clear understanding of
the Async IO model and sockets and each time, I do not get a complete
answer.

Thanks


On Tue, 25 Mar 2003 06:47:02 GMT, ju...@online.microsoft.com (Jun Su
[MSFT]) wrote:

>Hi,
>


>The worker thread will not waiting for IO when you use Asynchronous IO. The
>following is from MSDN:
>===========
>Using asynchronous I/O completion events, a thread from the thread pool
>will process data only when the data is received, and once the data has
>been processed, the thread will return to the thread pool.
>
>To make an asynchronous I/O call, an operating-system I/O handle must be
>associated with the thread pool and a callback method must be specified.
>When the I/O operation completes, a thread from the thread pool invokes the
>callback method.
>============
>http://msdn.microsoft.com/library/en-us/cpguide/html/cpconioasynchronouscomp
>letion.asp
>
>When you call EndXXX in the callback method, it is used to figure out how
>much data are read or written. Please also check the following link:
>http://msdn.microsoft.com/library/en-us/cpguide/html/cpconasynchronousfileio

Jun Su [MSFT]

unread,
Mar 26, 2003, 4:45:42 AM3/26/03
to
Hi,

First, Overlapped IO is different from CompltionPort IO. Please referemce
MSDN to clarify this two terms.

| 1) - Does Socket Class use Overlapped IO?

Yes when the OS doesn't support IOCompletionPort.

| 2) - If so, how do I use it.

Just call BeginXXX.

| 3) - What is the purpose of the IOCOmpletionCallback delegate

Currently, there is not enough document on it. It should be used when you
implement a new class to support CompletionPort


| 4) - If Socket Class does not use Overlapped IO, some direction as to
| how to do it myself in managed code would be helpful.
| 5) - How do I really tell that the connect worked. I am trying to
| connect to an system that does not exist, yet the AsyncCallback is
| getting called and the EndConnect is returning. There is not
| exception and there is no place to check a status that I know about.
| In fact NETSTAT indicates the socket is in FIN_WAIT_2. That is not a
| completed connect in my book.

You should get the exception when you call the EndConnect in the callback
method.

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: Roy Chastain <r...@kmsys.com>
| Subject: Re: IOCompletionCallback

| Date: Tue, 25 Mar 2003 10:53:40 -0500

Roy Chastain

unread,
Mar 26, 2003, 6:36:18 AM3/26/03
to
I must say that your answers below are less than forth coming and they
really don't make a lot of sense.

1) - If IOCompletionPort is anything to do with Win32 Completion Ports
then Overlapped IO is a requirement for IOCompletionPort. PS. I have
been trying to clarify what an IOCompletionCallback is. No one will
tell me. Just what do you think Completion Port IO is?

2) - Obviously not. The Socket object itself said that is was NOT
using overlapped IO.

3) - That has to be one of the most evasive answers I have ever
received from a Microsoft. AGAIN HOW DO I USE IT.

4) - No response as usual.

5) - I finally made my main thread wait long enough for the timeout to
occur and I did get the exception.

On Wed, 26 Mar 2003 09:45:42 GMT, ju...@online.microsoft.com (Jun Su

0 new messages