![]() Establish a new distributed CMake architecture with CMake code related to a source directory moving to be in the subdir in its own CMakeLists.txt. In particular, there's now one in ./lib which calls through to ones further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc. This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction, and it's much easier to maintain sub-CMakeLists.txt that are in the same directory as the sources they manage, and conceal all the details that that level. Child CMakelists.txt become responsible for: - include_directories() definition (this is not supported by CMake directly, it passes it back up via PARENT_SCOPE vars in helper macros) - Addition child CMakeLists.txt inclusion, for example toplevel -> role -> role subdir - Source file addition to the build - Dependent library path resolution... this is now a private thing in the child CMakeLists.txt, it just passes back any adaptations to include_directories() and the LIB_LIST without filling the parent namespace with the details |
||
---|---|---|
.. | ||
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