Commit adee2ef2
adee2ef2d900Merged
Ori Pekelman <[email protected]> · 5 months ago · 5 files · +4 added · ~1 modified
Description
sp_net: POSIX TCP/poll/process/shell primitives in libspinel_rt.a
Add lib/sp_net.{c,h} -- a vendored, audit-sized POSIX-runtime helper (TCP / poll(2) / prefork / shell), archived into libspinel_rt.a alongside sp_crypto. Same precedent + spirit as sp_crypto (#514): pure C, no spinel-runtime dependency, no OpenSSL/libsodium, static return buffers, single-threaded server model.
Motivation: HTTP-shaped Spinel frameworks (tep, roundhouse) each carry this same ~250-LoC POSIX core. tep's lib/tep/sphttp.c is the source of this extraction (see OriPekelman/tep#12, matz/spinel#1054); the surface has been stable for months. HTTP framing, WebSocket accessors, and TLS stay framework-side -- TLS deliberately so, to keep libspinel_rt.a OpenSSL-free (an optional sp_net_tls can layer over these fds later; see #1054 for the A/B discussion this PR implements option A of).
Surface (sp_net_ prefix): install_term_handlers / shutdown_requested (SIGTERM/SIGINT for prefork graceful shutdown; accept honors the flag) listen / accept / accept_nb / connect / close / set_nonblock recv_some / recv_all / write_str / write_bytes poll_reset / poll_add / poll_run / poll_ready fork / exit / getpid / wait_any shell_capture
Consumers declare the FFI surface their side (as tep does for sphttp_* today) and build their HTTP layer on top; auto-linked from the archive like sp_crypto, so no ffi_lib needed.
Makefile: build/sp_net.o rule + add to the libspinel_rt.a archive +
install lib/sp_net.h. test/sp_net_basic.rb: deterministic smoke
(shell_capture + a 127.0.0.1 TCP loopback exercising listen/connect/
accept_nb/write/recv/close + getpid); auto-discovered by make test.
Open question for review: naming (sp_net vs sp_posix_net vs a separate libspinel_net.a), and whether the term-signal trio belongs here or framework-side. Happy to adjust.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- adee2ef2d900
- Parent
- 9a43cb152fd8
MakefilemodifiedView file
@mkdir -p build $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib lib/sp_core.c -o build/sp_core.obuild/sp_net.o: lib/sp_net.c lib/sp_net.h @mkdir -p build $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib lib/sp_net.c -o build/sp_net.oSP_RT_LIB = lib/libspinel_rt.a$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o build/sp_time.o build/sp_core.o$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o build/sp_time.o build/sp_core.o build/sp_net.o ar rcs $@ $^regexp: $(SP_RT_LIB) install -m 644 lib/sp_runtime.h $(SPNLDIR)/lib/ install -m 644 lib/sp_core.h $(SPNLDIR)/lib/ install -m 644 lib/sp_time.h $(SPNLDIR)/lib/ install -m 644 lib/sp_net.h $(SPNLDIR)/lib/ install -m 644 lib/*.rb $(SPNLDIR)/lib/ install -d $(PREFIX)/bin ln -sf $(SPNLDIR)/spinel $(PREFIX)/bin/spinellib/sp_net.caddedView file
Loading diff…
lib/sp_net.haddedView file
Loading diff…
test/sp_net_basic.rbaddedView file
Loading diff…
test/sp_net_basic.rb.expectedaddedView file
Loading diff…