lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] how to cancel a netconn conncetion?


From: address@hidden
Subject: Re: [lwip-users] how to cancel a netconn conncetion?
Date: Mon, 09 Nov 2009 17:26:25 +0100
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

I suppose you mean "cancel the netconn accepting" as netconn_accept() is the blocking call, not netconn_listen()?

This has been covered numerous times on this list: The netconn and socket API is *not* designed to let one connection (or socket) be used simultaneously from more than one thread. One thread blocking and one calling xxx_close() involves two threads -> not supported!

Instead, register a callback for the listening netconn. When this callback is called with REVEIVE_PLUS (use a mutex or whatever you want to wait for it), call netconn_accept and it won't block. That's the way select() is implemented for the socket API.

You then only have to be able to cancle your waiting-for-the-callback from your other thread and you're done.

Simon


Bertrand Van Kempen wrote:
Hello,
I'm using the netconn API to implement a HTTP server.
All works fine but I don't found how to cancel the "netconn listening" to exit 
properly in my application.
I tried to call netconn_close and netconn_delete but the working thread still 
wait on netconn_accept(m_pConn);
Thanks in advance for your help, Bertrand van Kempen I do the following: I initialize an TCP connection from the main thread: m_pConn = netconn_new(NETCONN_TCP);

netconn_bind(m_pConn, IP_ADDR_ANY, 80)
netconn_listen(m_pConn);

and, from another thread I call the following in a loop:

while(m_bContinue)

{

struct netconn *newconn;

MTAL_DP("{");

newconn = netconn_accept(m_pConn);

if(newconn){

http_server_serve(newconn);

netconn_delete(newconn);

}

}

Then, I tried to do the following form the main thread:

m_bThreadContinue = false;

if(m_pConn)

{

netconn_close(m_pConn);

netconn_delete(m_pConn);
m_pConn = NULL;

}



_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]