Re: Sockets causing deadlock
- From: "Shawn Overcash" <dsi1@xxxxxxxx>
- Date: Thu, 14 Sep 2006 13:32:35 -0400
My responses:
- No data is shared between the threads.
- My mistake if I said non-blocking. They are actually blocking. The sockets
are made non-blocking for receives, but during the connect(), shutdown(),
and disconnect() calls they are made blocking to make sure the call
finishes.
- A separate thread handles the connect, so that the main thread can
continue processing. In the main program this is necessary, but I have
duplicated the problem in a test program that simple waits for the connect
thread to finish. It just goes into a loop (using SleepEx) waiting for the
connect thread to signal that it is finished.
- I do use SleepEx() in most places. If I am not mistaken, this is needed
for receive callbacks.
Unfortunately the code is spread out in several files, and is difficult to
paste here (and some of it is copyrighted). Here is the basic algorithm:
<Main Loop>
while (Not time to shut down)
{
if (we don't have a socket)
{
Allocate a new socket
Set it to blocking
}
CheckConnection() //See below
SleepEx()
}
-------------------------------------
CheckConnection()
{
switch (status)
{
case not_connected:
Start the connection thread //see below
Status = connecting
break;
case connecting:
Do nothing - just wait
break;
case connection_failed:
call shutdown()
call closesocket();
break;
}
}
--------------------------------
ConnectionThread
{
call connect()
if (failed)
{
status = connection_failed
}
// Note: there is some other code to handle successful, but it won't get
called
exit
}
.
- Follow-Ups:
- Re: Sockets causing deadlock
- From: Michael K. O'Neill
- Re: Sockets causing deadlock
- References:
- Sockets causing deadlock
- From: Shawn Overcash
- Re: Sockets causing deadlock
- From: Michael K. O'Neill
- Sockets causing deadlock
- Prev by Date: Re: Starting IOCP
- Next by Date: Re: Starting IOCP
- Previous by thread: Re: Sockets causing deadlock
- Next by thread: Re: Sockets causing deadlock
- Index(es):
Relevant Pages
|