netconn vs. BSD sockets

1,745 views
Skip to first unread message

Michael Jacobsen

unread,
Sep 19, 2015, 6:10:20 AM9/19/15
to esp-open-rtos mailing list
Hi Angus,

Noticed that in some of your examples you are using the netconn API. Can you elaborate on the advantages on using netconn instead of BSD sockets?

/michael

Angus Gratton

unread,
Sep 20, 2015, 3:59:49 AM9/20/15
to Michael Jacobsen, esp-open-rtos mailing list
On Sat, Sep 19, 2015 at 03:10:20AM -0700, Michael Jacobsen wrote:
> Noticed that in some of your examples you are using the netconn API. Can you elaborate on the advantages on using netconn instead of BSD sockets?

Hi Michael,

Sure! I've taken to writing new esp-specific code that way, and I think that's my preference except for when porting existing BSD sockets code that already just works.

The LWIP docs are a bit patchy but the LWIP developer's guide is probably the best overview of the 3 APIs (raw, netconn, sockets):
http://lwip.wikia.com/wiki/Application_API_layers

It's not possible to use the lowest level "raw" API (ie the one the Espressif IoT SDK uses) in esp-open-rtos at the moment, because the LWIP initialisation call happens in user_init. However once the open source startup code is merged it should be possible to use that API as well - initialise LWIP yourself from a single Task and then only ever access it from that task.

My reasons for preferring netconn to BSD, where it's sensible do so, are:

* I find the API more readable for simple TCP/UDP operations, compared to BSD sockets which have a lot of *nix baggage that isn't immediately useful in an embedded context (ie you're never going to want a Unix domain socket!)

* Less RAM & other overhead, according to docs. I haven't measured exactly how much (I think it's marginal compared to just using "raw"), but still a benefit.

* Can do zerocopy reads & writes in some circumstances. I think there's no genuine zerocopy on ESP (yet) as I'm pretty sure the data is still copied to/from a WiFi-side buffer by the MAC layer, but at least with "zerocopy" it's only copied once not twice.

The big downside is the obvious one, no longer being compatible with non-LWIP network layers.


Angus

Michael Jacobsen

unread,
Sep 21, 2015, 3:55:05 PM9/21/15
to esp-open-rtos mailing list
Understood. Thx.

/michael
Reply all
Reply to author
Forward
0 new messages