[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] Desiderata for 2.2.0 for debian and virtualsquare
From: |
Renzo Davoli |
Subject: |
[lwip-devel] Desiderata for 2.2.0 for debian and virtualsquare |
Date: |
Sat, 1 Jul 2023 16:27:45 +0200 |
Hi Simon,
I have seen the new git tag 2.2.0 RC1.
I am proposing again the patch here attached.
It is an optimization by itself (it avoids the generation of useless events)
and it permits to reduce significantly the amount of duplicated code in the
interfacing layer between lwip an libioth (Internet of Threads).
Purpose of the patch.
---------------------
File: src/api/sockets.c, function lwip_accept.
Current code:
Line 702/720 (chunk A) generate events if data comes in when the new socket has
not
been created yet.
Line 721/748 (chunk B) copy the peer address and address len values using the
pointers
'addr' and 'addrlen' if requested (addr != NULL && addrlen != NULL).
Line 749/752 finalize the function and return the new socket number.
This patch swaps the code of chunk A and the code of chunk B.
chunk B can fail (if netconn_peer fails) so the current code can generate events
(in chunk A) for a socket that the caller of lwip_accept will never have heard
of.
Given that chunk A and B perform two independent actions they can be swapped,
in this way the events of chunk A are generated when lwip_accept cannot fail
any more, so the caller receives events only for known sockets.
Necessity of the patch.
-----------------------
While for lwip itself this is just a harmless optimization it is important for
libioth.
Libioth provides a unified API for networking stacks implemented in user space
as libraries. A program can decide to use a specific network implementation
just by setting the value of a string parameter.
Network implementations are loaded at run time as plugins. It is possible to
write
programs using different network implementations at the same time, e.g.
a program can use a socket implemented by lwip and another provided by picotcp.
libioth supports select/poll/epoll... using vpoll
https://github.com/rd235/libvpoll-eventfd
This library uses a kernel module to provide real file descriptors whose
events can be generated as required using specific functions.
Thus, libioth sockets do not need specific functions to handle select/poll
(as lwip_select or lwip_poll). Events on file descriptors can be waited for
simply using the poll/select/epoll system calls etc.
I overrride the event callback in lwip's socket.c to 'feed' vpoll.
Unfortunately without this patch lwip_accept may send events for a socket that
will never be created, and there is not even an event to notify this failure...
Without this patch I'd have to etirely reimplement socket.c in the
ioth-lwip module duplicating a large amount of code.
Thank you.
renzo
4.socket_accept_avoid_useless_events.patch
Description: Text Data
- [lwip-devel] Desiderata for 2.2.0 for debian and virtualsquare,
Renzo Davoli <=