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 connce tion?


From: Bertrand Van Kempen
Subject: RE : [lwip-users] how to cancel a netconn connce tion?
Date: Mon, 9 Nov 2009 18:17:59 +0100

Thanks a lot Simon.
 
Yes, it is exactly that.
 
I'm new with lwIP and I'am sorry to ask for solved "issue".
Could you tell me how to have access to "old" post?
 
 
Best regards,
 
Bertrand
 

________________________________

De: address@hidden de la part de address@hidden
Date: lun. 09/11/2009 17:26
À: Mailing list for lwIP users
Objet : Re: [lwip-users] how to cancel a netconn conncetion?



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
>
>  



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


<<winmail.dat>>


reply via email to

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