Re: IOCP Across Threads - Error 995
- From: Len Holgate <len.holgate@xxxxxxxxxxx>
- Date: Tue, 02 Oct 2007 01:23:45 -0700
The problem is that when a thread exits with outstanding overlapped
send requests in progress all of those requests are cancelled - See:
http://msdn2.microsoft.com/en-us/library/ms742203.aspx (under Note in
the Overlapped IO section). I expect that you're just being lucky when
you say that all your data arrives OK...
So, to fix this, you either need to keep track of when these requests
complete and keep your send thread alive until that point or you need
to do your sends from a thread that wont exit.
I opted for the later in my IOCP client server framework and I
'marshal' requests to the IO threads to action since I know the IO
threads wont exit... This makes the operations less effiicient when
used from threads that aren't in the IO pool but it means that the
code is easier for users of the framework to use.... In your case it's
probably as easy to track the sends and their completions and keep
your thread alive until all of the outstanding requests complete...
In case you're interested: my IOCP framework is available with full
source code, free of charge, here: http://www.lenholgate.com/archives/000637.html
and there are links to the original code project articles that explain
some of the design decisions made during development.
Len
On Oct 2, 1:08 am, LongJohn <LongJ...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Hi,
I have an application that creates an IOCP in the main thread, then creates
worker threads that wait on it. This works very well for incoming
connections from clients.
I have created an additional thread that initiates connections to the
clients (who are listening for these "reverse" connections). In that thread,
I associate the outgoing transaction sockets to the same IOCP (from the
global handle), so I can use a single handler for all the I/O. This thread
exits after the outgoing connections have connected and the send buffers have
been posted to them.
This even works well, but recently I have observed the following phenomenon:
When the outgoing connection thread ends, sometimes some of the sends that
were posted return to the handler with an error condition of 995, indicating
that they were aborted due to a thread exiting. The data is making it to the
client successfully.
As an experiment, I placed a Sleep() at the end of the outgoing connection
thread and all the sends now are returned to the handler successfully. This
is obviously not a solution.
I thought that when I posted sends to the global IOCP, it would not matter
which thread I did it from, or whether that thread was still alive. I don't
want to add another handler in that outgoing connection thread to wait for
all connections to complete before exiting the thread.
Is this really an error, or just a "notification"?
Any ideas?
.
- Prev by Date: Re: URL filtering using LSP
- Next by Date: Re: IOCP Across Threads - Error 995
- Previous by thread: Re: Process created by telnet session shows no windows, why ?
- Next by thread: Re: IOCP Across Threads - Error 995
- Index(es):
Relevant Pages
|