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

Windows Sockets/WSAECONNABORTED error

355 views
Skip to first unread message

JanO

unread,
May 10, 2002, 6:04:41 PM5/10/02
to
Greetings,

I am currently trying to (sucessfully) connect and
disconnect a Client-Server socket connection using
Windows/Visual C++.

The connection seems to happen without problems, but the
disconnect does not go as gracefully. Background: the
client socket is blocked on a recv() call in one thread,
and I am trying to disconnect gracefully via a second
thread. In the second thread, I am initiating a
disconnect on the Client side by first setting the LINGER
options to a graceful disconnect:

LINGER linger;
linger.l_onoff = 1;
linger.l_linger = 0;
dwError = setsockopt ( m_hSocket, SOL_SOCKET,
SO_LINGER, (char *) &
linger, sizeof ( linger ) );
if ( dwError == SOCKET_ERROR )
{
TRACE ("Set Socket opt error \n");
}
}
}

then calling closesocket () to shutdown the socket:

if(closesocket(m_hSocket) == SOCKET_ERROR)
{
ErrorHandler( &dwError , ErrStr );
}

This results in the error WSAECONNABORTED (saying that
software caused connection abort). I have tried various
things to remedy this, such as waiting inbetween the calls
to "flush" things out, calling shutdown() in between, but
these do not seem to affect anything. Any suggestions or
insight would be greatly appreciated.

Cheers,

Jan

arkadyf

unread,
May 14, 2002, 10:04:14 AM5/14/02
to
Hi !
When you set in setsockopt() SO_LINGER you enable linger ( waiting ) with
default if 0 time.
When you do closesocket() you close socket but because you are in recv() the
WSAECONNABORTED
is return code. As I can see you want SO_DONTLINGER because SO_LINGER you
have by default.
Using of these options influence upon TIME_WAIT stage of socket closing and
strongly not recommended.
BTW using shutdown() is most recommended way to close connection with
closesocket after receiving 0
on recv().
IMHO you need to wait on recv() TO ( default is 45 sec ) or you can change
it if you are in
winsock2 by setsockopt with SO_RCVTIMEO or use set sock to non-blocked ,do
recv() , and wait some TO
of recv on select()
Arkady


JanO <jan_...@agilent.com> wrote in message
news:275701c1f86e$af439f20$3bef2ecf@TKMSFTNGXA10...

0 new messages