netconn: freeing netbufs after netconn_recv

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

netconn: freeing netbufs after netconn_recv

Ivan Delamer
Hi again,

I'm trying to implement a small HTTP server with Keep-alive, so incoming TCP connections stay open for multiple interactions.

I'm now using netconn API.

Thanks to the previous answers, I am now able to properly process received segments. Code is approx.:

  do {
      char *data;
      int len;
      /* obtain a pointer to the data in the fragment */
      netbuf_data(buf, &data, &len);
      /* do something with the data */
      do_something(data, len);
  } while(netbuf_next(buf) >= 0);

Now, I have two questions/concerns:

1) do I have to manually free/delete the netbuf? I read the source code for netconn_recv and I see a buf = memp_malloc(MEMP_NETBUF)  but no "free" in the examples.

2) for how long is the data in the netbuf valid? netconn_recv sends a API_MSG_RECV so does this mean that the data may be overwritten? or does it stay valid until I free the netbuf (and underlying pbufs)?

The way I see it, I should call netbuf_delete() after I'm done processing the data, but I couldn't find any example of this.

Thanks in advance again,
Ivan

PS: anybody have an HTTPD server sample? something more complex than the example, I will use a thread pool for processing requests and hopefully implement keep-alive.


      ____________________________________________________________________________________
Yahoo! Noticias
Todo lo que tenés que saber sobre Elecciones Presidenciales 2007 encontralo en Yahoo! Noticias.
http://ar.news.yahoo.com/elecciones2007/


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

Re: netconn: freeing netbufs after netconn_recv

goldsimon@gmx.de

Am 31.10.2007 um 21:23 schrieb Ivan Delamer:

> ...
> Now, I have two questions/concerns:
>
> 1) do I have to manually free/delete the netbuf? I read the source  
> code for netconn_recv and I see a buf = memp_malloc(MEMP_NETBUF)  
> but no "free" in the examples.

Yes, look at sockets.c, lwip_recv() implementation for an example.

>
> 2) for how long is the data in the netbuf valid? netconn_recv sends  
> a API_MSG_RECV so does this mean that the data may be overwritten?  
> or does it stay valid until I free the netbuf (and underlying pbufs)?

Data stays valid until you free the netbuf. API_MSG_RECV updates the  
TCP window so that the remote side can send more data. If you don't  
free the netbuf, you will eventually run out of pbufs/netbufs.

>
> The way I see it, I should call netbuf_delete() after I'm done  
> processing the data, but I couldn't find any example of this.

As mentioned above, look at sockets.c, lwip_recv() implementation.

>
> Thanks in advance again,
> Ivan
>
> PS: anybody have an HTTPD server sample? something more complex  
> than the example, I will use a thread pool for processing requests  
> and hopefully implement keep-alive.

The only netconn HTTPD example I know of is in the CVS contrib  
module, apps directory.


Simon




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

Re: netconn: freeing netbufs after netconn_recv

Ivan Delamer
In reply to this post by Ivan Delamer
Thanks Simon,

BTW, I have never contributed code here before, but perhaps the netbuf_delete could be added to the HTTP example? How is that posted?

If the HTTP server I'm making is half decent I'll post it in case anybody is interested.

Regards
Ivan


----- Mensaje original ----
De: Simon Goldschmidt <[hidden email]>
Para: Mailing list for lwIP users <[hidden email]>
Enviado: jueves 1 de noviembre de 2007, 4:35:32
Asunto: Re: [lwip-users] netconn: freeing netbufs after netconn_recv


Am 31.10.2007 um 21:23 schrieb Ivan Delamer:

> ...
> Now, I have two questions/concerns:
>
> 1) do I have to manually free/delete the netbuf? I read the source  
> code for netconn_recv and I see a buf = memp_malloc(MEMP_NETBUF)  
> but no "free" in the examples.

Yes, look at sockets.c, lwip_recv() implementation for an example.

>
> 2) for how long is the data in the netbuf valid? netconn_recv sends  
> a API_MSG_RECV so does this mean that the data may be overwritten?  
> or does it stay valid until I free the netbuf (and underlying pbufs)?

Data stays valid until you free the netbuf. API_MSG_RECV updates the  
TCP window so that the remote side can send more data. If you don't  
free the netbuf, you will eventually run out of pbufs/netbufs.

>
> The way I see it, I should call netbuf_delete() after I'm done  
> processing the data, but I couldn't find any example of this.

As mentioned above, look at sockets.c, lwip_recv() implementation.

>
> Thanks in advance again,
> Ivan
>
> PS: anybody have an HTTPD server sample? something more complex  
> than the example, I will use a thread pool for processing requests  
> and hopefully implement keep-alive.

The only netconn HTTPD example I know of is in the CVS contrib  
module, apps directory.


Simon




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


      Los referentes más importantes en compra/ venta de autos se juntaron:
Demotores y Yahoo!
Ahora comprar o vender tu auto es más fácil. Vistá ar.autos.yahoo.com/


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

Re: netconn: freeing netbufs after netconn_recv

goldsimon@gmx.de
Ivan Delamer schrieb:
> Thanks Simon,
>
> BTW, I have never contributed code here before, but perhaps the netbuf_delete could be added to the HTTP example? How is that posted?
>  
If you take a look at the httpserver-netconn.c in the contrib module in
CVS (take a look at the current version here:
http://cvs.savannah.nongnu.org/viewvc/contrib/apps/httpserver/httpserver-netconn.c?revision=1.4&root=lwip&view=markup 
), netbuf_delete() is called at the end of the serve-function.

> If the HTTP server I'm making is half decent I'll post it in case anybody is interested.
>  
The question how to contribute is not that easily answered right now. We
haven't yet decided what to do with contributions that don't fit in the
category 'bug' or 'patch'. Only apps/ports/drivers that have an active
maintainer (with write access to CVS) are added to the repository.

We have discussed the idea for an open space for applications based on
an lwIP API or ports/drivers that are unmaintained, but that hasn't led
to a final decision, yet. As it is right now, I'm afraid the only thing
you can do is post your code here on the mailing list. I'd be happy to
take a look over it, though. But, taking part in maintaining the current
'httpserver-netconn' I don't think it will be extended in any way since
it is really only a small netconn-API example application.

Simon


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

RE: netconn: freeing netbufs after netconn_recv

Grubb, Jared
In reply to this post by Ivan Delamer
Ivan,

Any code examples are always appreciated! As Simon mentioned, post it to the list... maybe we can work it into the Scribblewiki??

Jared

-----Original Message-----
From: lwip-users-bounces+jgrubb=[hidden email] [mailto:lwip-users-bounces+jgrubb=[hidden email]] On Behalf Of Ivan Delamer
Sent: Thursday, November 01, 2007 07:51
To: Mailing list for lwIP users
Subject: Re: [lwip-users] netconn: freeing netbufs after netconn_recv

Thanks Simon,

BTW, I have never contributed code here before, but perhaps the netbuf_delete could be added to the HTTP example? How is that posted?

If the HTTP server I'm making is half decent I'll post it in case anybody is interested.

Regards
Ivan


----- Mensaje original ----
De: Simon Goldschmidt <[hidden email]>
Para: Mailing list for lwIP users <[hidden email]>
Enviado: jueves 1 de noviembre de 2007, 4:35:32
Asunto: Re: [lwip-users] netconn: freeing netbufs after netconn_recv


Am 31.10.2007 um 21:23 schrieb Ivan Delamer:

> ...
> Now, I have two questions/concerns:
>
> 1) do I have to manually free/delete the netbuf? I read the source  
> code for netconn_recv and I see a buf = memp_malloc(MEMP_NETBUF)  
> but no "free" in the examples.

Yes, look at sockets.c, lwip_recv() implementation for an example.

>
> 2) for how long is the data in the netbuf valid? netconn_recv sends  
> a API_MSG_RECV so does this mean that the data may be overwritten?  
> or does it stay valid until I free the netbuf (and underlying pbufs)?

Data stays valid until you free the netbuf. API_MSG_RECV updates the  
TCP window so that the remote side can send more data. If you don't  
free the netbuf, you will eventually run out of pbufs/netbufs.

>
> The way I see it, I should call netbuf_delete() after I'm done  
> processing the data, but I couldn't find any example of this.

As mentioned above, look at sockets.c, lwip_recv() implementation.

>
> Thanks in advance again,
> Ivan
>
> PS: anybody have an HTTPD server sample? something more complex  
> than the example, I will use a thread pool for processing requests  
> and hopefully implement keep-alive.

The only netconn HTTPD example I know of is in the CVS contrib  
module, apps directory.


Simon




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


      Los referentes más importantes en compra/ venta de autos se juntaron:
Demotores y Yahoo!
Ahora comprar o vender tu auto es más fácil. Vistá ar.autos.yahoo.com/


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


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

Re: netconn: freeing netbufs after netconn_recv

Ivan Delamer
In reply to this post by Ivan Delamer
I must have gone over httpserver-netconn.c 10 times and missed it every single time !! thanks.

I will post the HTTPD server if it is any good.

Regards
Ivan


----- Mensaje original ----
De: "[hidden email]" <[hidden email]>
Para: Mailing list for lwIP users <[hidden email]>
Enviado: jueves 1 de noviembre de 2007, 8:37:31
Asunto: Re: [lwip-users] netconn: freeing netbufs after netconn_recv

Ivan Delamer schrieb:
> Thanks Simon,
>
> BTW, I have never contributed code here before, but perhaps the netbuf_delete could be added to the HTTP example? How is that posted?
>  
If you take a look at the httpserver-netconn.c in the contrib module in
CVS (take a look at the current version here:
http://cvs.savannah.nongnu.org/viewvc/contrib/apps/httpserver/httpserver-netconn.c?revision=1.4&root=lwip&view=markup 
), netbuf_delete() is called at the end of the serve-function.

> If the HTTP server I'm making is half decent I'll post it in case anybody is interested.
>  
The question how to contribute is not that easily answered right now. We
haven't yet decided what to do with contributions that don't fit in the
category 'bug' or 'patch'. Only apps/ports/drivers that have an active
maintainer (with write access to CVS) are added to the repository.

We have discussed the idea for an open space for applications based on
an lwIP API or ports/drivers that are unmaintained, but that hasn't led
to a final decision, yet. As it is right now, I'm afraid the only thing
you can do is post your code here on the mailing list. I'd be happy to
take a look over it, though. But, taking part in maintaining the current
'httpserver-netconn' I don't think it will be extended in any way since
it is really only a small netconn-API example application.

Simon


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


      ____________________________________________________________________________________
Yahoo! Noticias
Todo lo que tenés que saber sobre Elecciones Presidenciales 2007 encontralo en Yahoo! Noticias.
http://ar.news.yahoo.com/elecciones2007/


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

Question about PHY transceivers

bonny gijzen
In reply to this post by goldsimon@gmx.de
Hi guys,


The question I have is not a true LWIP question, but it is hardware
related (PHY transceivers), so I guess you all have experience with
them.

I have used LWIP in the past for a personal project, so I follow this
mailing list since, so I decided to raise my question here (if that is
no problem to you all).

We are currently looking at the idea to add a (CAT5-6) gigabit
sender/receiver to our (FPGA) boards.
We think using a PHY transceiver gives more benefits over LDVS
transmitters, because:

*) Most PHY transceivers I've looked at use a single 25Mhz osc
*) Have all encoding (4b5b e.o.) done inside
*) Have embedded functions like polarity correction, adaptive
equaliztion, cross-talk cancellation, echo cancelation, timing recovery
and error correction.

These are some of the features which are embedded in the devices, so we
do not need to bother with them ourselves.

Do any of you use PHY transceivers (not MAC devices) on your boards?
What are your experiences with them?
What prices must I think of in unit terms of 1000 pcs annual?


Thank you for maintaining LWIP,


Bonny


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

Re: Question about PHY transceivers

timmy brolin
You cannot implement standard gigabit Ethernet without a PHY.
Simple LVDS transmitters/receivers are not compatible with gigabit
Ethernet CAT5-6 signaling.

/Timmy

bonny gijzen wrote:

>Hi guys,
>
>
>The question I have is not a true LWIP question, but it is hardware
>related (PHY transceivers), so I guess you all have experience with
>them.
>
>I have used LWIP in the past for a personal project, so I follow this
>mailing list since, so I decided to raise my question here (if that is
>no problem to you all).
>
>We are currently looking at the idea to add a (CAT5-6) gigabit
>sender/receiver to our (FPGA) boards.
>We think using a PHY transceiver gives more benefits over LDVS
>transmitters, because:
>
>*) Most PHY transceivers I've looked at use a single 25Mhz osc
>*) Have all encoding (4b5b e.o.) done inside
>*) Have embedded functions like polarity correction, adaptive
>equaliztion, cross-talk cancellation, echo cancelation, timing recovery
>and error correction.
>
>These are some of the features which are embedded in the devices, so we
>do not need to bother with them ourselves.
>
>Do any of you use PHY transceivers (not MAC devices) on your boards?
>What are your experiences with them?
>What prices must I think of in unit terms of 1000 pcs annual?
>
>
>Thank you for maintaining LWIP,
>
>
>Bonny
>
>
>_______________________________________________
>lwip-users mailing list
>[hidden email]
>http://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>  
>


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

RE: Question about PHY transceivers

bonny gijzen
Hi Timmy,

>You cannot implement standard gigabit Ethernet without a PHY.
>Simple LVDS transmitters/receivers are not compatible with gigabit
Ethernet CAT5-6 signaling.

We are trying to do the exact oposite. We don't want ethernet, just a
highspeed connection.
So why not use a standard cat5-6 system using a PHY, instead of using
lvds transceivers etc.


Bonny,


-----Oorspronkelijk bericht-----
Van: lwip-users-bounces+bonny.gijzen=[hidden email]
[mailto:lwip-users-bounces+bonny.gijzen=[hidden email]] Namens
Timmy Brolin
Verzonden: zondag 4 november 2007 20:48
Aan: Mailing list for lwIP users
Onderwerp: Re: [lwip-users] Question about PHY transceivers

You cannot implement standard gigabit Ethernet without a PHY.
Simple LVDS transmitters/receivers are not compatible with gigabit
Ethernet CAT5-6 signaling.

/Timmy

bonny gijzen wrote:

>Hi guys,
>
>
>The question I have is not a true LWIP question, but it is hardware
>related (PHY transceivers), so I guess you all have experience with
>them.
>
>I have used LWIP in the past for a personal project, so I follow this
>mailing list since, so I decided to raise my question here (if that is
>no problem to you all).
>
>We are currently looking at the idea to add a (CAT5-6) gigabit
>sender/receiver to our (FPGA) boards.
>We think using a PHY transceiver gives more benefits over LDVS
>transmitters, because:
>
>*) Most PHY transceivers I've looked at use a single 25Mhz osc
>*) Have all encoding (4b5b e.o.) done inside
>*) Have embedded functions like polarity correction, adaptive
>equaliztion, cross-talk cancellation, echo cancelation, timing recovery

>and error correction.
>
>These are some of the features which are embedded in the devices, so we

>do not need to bother with them ourselves.
>
>Do any of you use PHY transceivers (not MAC devices) on your boards?
>What are your experiences with them?
>What prices must I think of in unit terms of 1000 pcs annual?
>
>
>Thank you for maintaining LWIP,
>
>
>Bonny
>
>
>_______________________________________________
>lwip-users mailing list
>[hidden email]
>http://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>  
>


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




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