[En-Nut-Discussion] TCP Socket waiting in TCPS_CLOSE_WAIT
Michael Baverso
mbaverso at elcontech.com
Fri Mar 7 04:15:12 CET 2003
I have had similar problems, it seems that the
client requests to close the socket because of a timeout but the thread my
server was in stopped running,
I never quite corrected it, I actually kept the socket open to meet the
requirements of the protocol I was working with
(bad hack) but it has been working faithfully.
In talking to Harald he felt it was probably a memory corruption issue,
take a close look at the code you are usintg in your server thread.
THREAD(Modbus, arg)
{
TCPSOCKET *sock;
u_long timeout = 10000;
/*
* Now loop endless for connections.
*/
for(;;)
{
/*
* Create a socket.
*/
if((sock = NutTcpCreateSocket()) == 0)
{
NutSleep(5000);
continue;
}
/*
* Listen on port 502. If we return,
* we got a client.
*/
NutTcpAccept(sock, 502);
/*
* Check for enough memory. If we are below
* 8 kByte, take a nap and try again.
*/
for(;;)
{
if(NutHeapAvailable() > 8192)
break;
NutSleep(1000);
}
NutTcpSetSockOpt(sock, SO_RCVTIMEO , &timeout, sizeof(timeout));
//NutTcpSetSockOpt(sock, SO_SNDTIMEO , &timeout, sizeof(timeout));
****probably not thr best but it works
while(sock->so_state != TCPS_CLOSE_WAIT)
{
if (ProcessMBQuery(sock) == -1)
break;
NutThreadYield();
}
****
/*
* Close our socket.
*/
NutTcpCloseSocket(sock);
NutThreadYield();
}
}
----- Original Message -----
From: "Stephen Noftall" <stephenn at lcsaudio.com>
To: <en-nut-discussion at egnite.de>
Sent: Thursday, March 06, 2003 8:31 PM
Subject: [En-Nut-Discussion] TCP Socket waiting in TCPS_CLOSE_WAIT
> Hi, hopefully a simple answer to this one:
>
> In my app, I wait on a tcp connection. When it's available, I read and
write
> it using NutTcpSend() and NutTcpReceive().
>
> Everything seems to be working ok, I can connect and send and receive
data
> via a remote telnet app.
>
> My problem is that when my remote telnet application closes, I am
expecting
> the Ethernut to generate and error in NutTcpSend() or NutTcpReceive(). I
was
> hoping it would generate the ETIMEDOUT or something similar. My problem
is
> that my Ethernut application just sits there, and never errors out. Of
> course, when I try to connect again with my telnet app, it refuses the
> connection.
>
> When I look at the sockets via my debug RS422 port (allways have to have
one
> of those ;-), it shows the TCP socket in the TCPS_CLOSE_WAIT state.
>
> Does anyone have any ideas what I could try? I tried to change the
timeout
> values, but they did not seem to help.
>
> Any help would be appreciated.
>
> Thanks
>
> Stephen Noftall
>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo/en-nut-discussion
More information about the En-Nut-Discussion
mailing list