[En-Nut-Discussion] killing threads waiting for a connection in NutTcpAccept
José Vallet
jose.vallet at hut.fi
Mon Apr 6 17:51:38 CEST 2009
I have some threads waiting for connections with NutTcpAccept, and I'd
like to kill them.
The (simplified) code goes like this
__________________
...
sock = NutTcpCreateSocket();
NutTcpAccept(sock, SERVER_PORT);
mystream =_fdopen((int) sock, "r+b");
whihle(!disconnect)
{
...
}
fclose(sl_stream);
NutTcpCloseSocket(_sl_sock);
NutThreadExit();
__________________
The problem is that while the connection does not arrive the thread is
blocked waiting for connections, and thus the thread will never reach
NutThreadExit.
I have "solved" this by sending from another thread an event to
"sock->so_pc_tq", which is the queue where NutTcpStatePassiveOpenEvent
(called from NutTcpAccept) blocks waiting for events (connections). The
result is that, as the stack thinks that a valid connection has arrived,
all the code between NutTcpAccept and NutThreadExit() is executed
normally as if the connection had arrived properly.
Though I can live with this for my particular application, I guess this
solution is ugly and dirty (at least to me) and I wonder if there is any
other better solution to unblock the thread waiting for connections
(note: closing the socket does not unblock NutTcpAccept).
Thanks and regards
José
More information about the En-Nut-Discussion
mailing list