how to cancel a netconn conncetion?

View: New views
5 Messages — Rating Filter:   Alert me  

how to cancel a netconn conncetion?

by Bertrand Van Kempen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
lwip-users@...
http://lists.nongnu.org/mailman/listinfo/lwip-users

Re: how to cancel a netconn conncetion?

by Simon Goldschmidt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
> lwip-users@...
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
>  



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

RE : how to cancel a netconn conncetion?

by Bertrand Van Kempen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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: lwip-users-bounces+bvankempen=merging.com@... de la part de goldsimon@...
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
> lwip-users@...
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
>  


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




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

winmail.dat (8K) Download Attachment

Re: RE : how to cancel a netconn conncetion?

by Simon Goldschmidt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bertrand Van Kempen wrote:
> 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?

Archives are accessible via
http://lists.nongnu.org/archive/html/lwip-users/ and
http://lists.nongnu.org/archive/html/lwip-devel/

Simon


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

RE : RE : how to cancel a netconn conncetion?

by Bertrand Van Kempen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Simon,
 
until now, it works perfectly ;-)
 
Good and fast answer => I think I definitively choose the good stack :-))
 
Best regards,
 
Bertrand

________________________________

De: lwip-users-bounces+bvankempen=merging.com@... de la part de goldsimon@...
Date: lun. 09/11/2009 20:58
À: Mailing list for lwIP users
Objet : Re: RE : [lwip-users] how to cancel a netconn conncetion?



Bertrand Van Kempen wrote:
> 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?

Archives are accessible via
http://lists.nongnu.org/archive/html/lwip-users/ and
http://lists.nongnu.org/archive/html/lwip-devel/

Simon


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




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

winmail.dat (6K) Download Attachment