exception in the second call to netconn_bind

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

exception in the second call to netconn_bind

David Shmelzer
Hi,
I'm getting a processor exception in the second call to netconn_bind.
Here is the simplified version of the code that reproduces the problem:

  conn=netconn_new( NETCONN_TCP );
  netconn_bind(conn, NULL, portnum);
  netconn_listen( conn );
  netconn_delete(conn);
  conn=netconn_new( NETCONN_TCP );
  netconn_bind(conn, NULL, portnum);

I left out the netconn_accept() call because it doesn't make a
difference.
What is the correct way of deleting a listening connection?
Is there an example somewhere? The BasicWeb.c examples never close the
listening connection.

Thanks,
Dave



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: exception in the second call to netconn_bind

Jonathan Larmour
David Shmelzer wrote:

> Hi,
> I'm getting a processor exception in the second call to netconn_bind.
> Here is the simplified version of the code that reproduces the problem:
>
>   conn=netconn_new( NETCONN_TCP );
>   netconn_bind(conn, NULL, portnum);
>   netconn_listen( conn );
>   netconn_delete(conn);
>   conn=netconn_new( NETCONN_TCP );
>   netconn_bind(conn, NULL, portnum);
> What is the correct way of deleting a listening connection?

That looks right. It might be worth checking for any error returns from
the above. In particular if conn is non-NULL second time round. I assume
all this gets called from a single thread.

> Is there an example somewhere? The BasicWeb.c examples never close the
> listening connection.

There's an example in http://www.sics.se/~adam/lwip/doc/lwip.pdf section
16.0.22 (just after the documentation of netconn_bind).

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

exception in the second call to netconn_bind

David Shmelzer
In reply to this post by David Shmelzer
Thanks for pointing me to the example in lwIP.pdf

I copied the example from the lwIP.pdf verbatim into a test function
that I execute twice. The second time through I get an exception in
netconn_bind().

The exception occurs in the first 'for' loop in tcp_bind().
The cause of the exception is cpcb->next ends up as 0x00000400 instead
of NULL.

  for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
      cpcb != NULL; cpcb = cpcb->next) {

That's as far as I've debugged for now.
Any ideas as to where I should look next?

I am using the raw API as well as the netconn API. Is this allowed?
I first open a listening port using the raw API, then attempt to open
and close another listening port using the netconn API as described
above.

-Dave



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: exception in the second call to netconn_bind

Jonathan Larmour
David Shmelzer wrote:

> Thanks for pointing me to the example in lwIP.pdf
>
> I copied the example from the lwIP.pdf verbatim into a test function
> that I execute twice. The second time through I get an exception in
> netconn_bind().
>
> The exception occurs in the first 'for' loop in tcp_bind().
> The cause of the exception is cpcb->next ends up as 0x00000400 instead
> of NULL.
>
>   for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
>       cpcb != NULL; cpcb = cpcb->next) {
>
> That's as far as I've debugged for now.
> Any ideas as to where I should look next?
>
> I am using the raw API as well as the netconn API. Is this allowed?

I expect the way you're using it... no. The lwIP core code is not
thread-safe. If you are using the netconn API and the raw API together,
you would have to make sure your raw API stuff happens in the context of
the lwIP tcpip thread so stuff can only happen in that thread's context.
You could probably use the tcpip_init_done callback (the one passed in to
tcpip_init()) to set up your own callbacks for that sort of thing.

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: exception in the second call to netconn_bind

David Shmelzer
In reply to this post by David Shmelzer
I converted all my code to netconn api and it works, but is a bit
slower.

If I wanted to convert it all to the raw API how do I send to the raw
API from a separate task?
Can I safely call tcp_write from a separate task?
I noticed there's work being done on "locking" the core code to make it
thread safe. Is this safe to use yet?

Dave

>
>
> ------------------------------
>
> Message: 2
> Date: Sat, 31 Jan 2009 22:16:41 +0000
> From: Jonathan Larmour <[hidden email]>
> Subject: Re: [lwip-users] exception in the second call to netconn_bind
> To: Mailing list for lwIP users <[hidden email]>
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> David Shmelzer wrote:
> > Thanks for pointing me to the example in lwIP.pdf
> >
> > I copied the example from the lwIP.pdf verbatim into a test
> function
> > that I execute twice. The second time through I get an exception in
> > netconn_bind().
> >
> > The exception occurs in the first 'for' loop in tcp_bind().
> > The cause of the exception is cpcb->next ends up as
> 0x00000400 instead
> > of NULL.
> >
> >   for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
> >       cpcb != NULL; cpcb = cpcb->next) {
> >
> > That's as far as I've debugged for now.
> > Any ideas as to where I should look next?
> >
> > I am using the raw API as well as the netconn API. Is this allowed?
>
> I expect the way you're using it... no. The lwIP core code is
> not thread-safe. If you are using the netconn API and the raw
> API together, you would have to make sure your raw API stuff
> happens in the context of the lwIP tcpip thread so stuff can
> only happen in that thread's context.
> You could probably use the tcpip_init_done callback (the one
> passed in to
> tcpip_init()) to set up your own callbacks for that sort of thing.
>
> Jifl
> --


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: exception in the second call to netconn_bind

goldsimon@gmx.de
David Shmelzer wrote:
> I converted all my code to netconn api and it works, but is a bit
> slower.
>
> If I wanted to convert it all to the raw API how do I send to the raw
> API from a separate task?
> Can I safely call tcp_write from a separate task?
>  

Absolutely not!

> I noticed there's work being done on "locking" the core code to make it
> thread safe. Is this safe to use yet?
>  

That's another issue! To keep it simple, the core is not (and never will
be) protected agains concurrent access (apart from the memory allocation
functions). The locking you read about is just the method how higher
layer APIs use the core. Until now, the core is handled from one single
thread only (aka the tcpip_thread, because of the loop-function's name)
and application threads using the socket/netconn API communicate with it
through message boxes. Although Frédéric started another approach by
taking a big lock when using the core functions, this is not really
supported yet *and it will never be* for the raw API, I guess.

What you can do to use the raw API from another thread is to get
tcpip_callback call a function (with void argument) in the core thread's
thread-context. This is the same mechanism the other APIs use the core.
However, you cannot mix the socket/netconn/raw APIs, and you should be
aware that raw API callbacks are always called from the tcpip_thread.

Simon


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users