![]() wsi timeout, wsi hrtimer, sequencer timeout and vh-protocol timer all now participate on a single sorted us list. The whole idea of polling wakes is thrown out, poll waits ignore the timeout field and always use infinite timeouts. Introduce a public api that can schedule its own callback from the event loop with us resolution (usually ms is all the platform can do). Upgrade timeouts and sequencer timeouts to also be able to use us resolution. Introduce a prepared fakewsi in the pt, so we don't have to allocate one on the heap when we need it. Directly handle vh-protocol timer if LWS_MAX_SMP == 1 |
||
---|---|---|
.. | ||
CMakeLists.txt | ||
minimal-raw-adopt-udp.c | ||
README.md |
lws minimal ws server raw adopt udp
This example demonstrates echoing packets on a UDP socket in lws.
A "foreign" UDP socket is created, bound (so it can "listen"), and adopted into lws event loop. It acts like a tcp RAW mode connection in lws and uses the same callbacks.
Writing is a bit different for UDP. By default, the system has no idea about the receiver state and so asking for a callback_on_writable() always believes that the socket is writeable... the callback will happen next time around the event loop if there are no pending partials.
With UDP, there is no "connection". You need to write with sendto() and
direct the packets to a specific destination. You can learn the source
of the last packet that arrived at the LWS_CALLBACK_RAW_RX callback by
getting a struct lws_udp *
from lws_get_udp(wsi)
. To be able to
send back to that guy, you should take a copy of the struct lws_udp *
and
use the .sa and .salen members in your sendto().
However the kernel may not accept to buffer / write everything you wanted to send. So you are responsible to watch the result of sendto() and resend the unsent part next time.
build
$ cmake . && make
usage
$ ./lws-minimal-raw-adopt-udp
$ ./lws-minimal-raw-adopt-udp
[2018/03/24 08:12:37:8869] USER: LWS minimal raw adopt udp | nc -u 127.0.0.1 7681
[2018/03/24 08:12:37:8870] NOTICE: Creating Vhost 'default' (no listener), 1 protocols, IPv6 off
[2018/03/24 08:12:37:8878] USER: LWS_CALLBACK_RAW_ADOPT
[2018/03/24 08:12:41:5656] USER: LWS_CALLBACK_RAW_RX (6)
[2018/03/24 08:12:41:5656] NOTICE:
[2018/03/24 08:12:41:5656] NOTICE: 0000: 68 65 6C 6C 6F 0A hello.
[2018/03/24 08:12:41:5656] NOTICE:
$ nc -u 127.0.0.1 7681
hello
hello