|
cwist
Modern C web framework with libttak runtime
|
CWIST over lwIP's raw TCP API; see <cwist/sys/port/lwip.h>. More...
#include <cwist/sys/port/lwip.h>#include <cwist/core/mem/alloc.h>#include <cwist/net/http/http.h>#include "lwip/opt.h"#include "lwip/sys.h"#include "lwip/tcp.h"#include <stdio.h>#include <string.h>#include <strings.h>
Go to the source code of this file.
Macros | |
| #define | CWIST_LWIP_POLL_TICKS 2 |
Typedefs | |
| typedef struct cwist_lwip_conn | cwist_lwip_conn |
Enumerations | |
| enum | frame_result { FRAME_NEED_MORE , FRAME_COMPLETE , FRAME_ERROR } |
Functions | |
| void | cwist_lwip_config_init (cwist_lwip_config *cfg) |
Fill cfg with the defaults documented on cwist_lwip_config. | |
| cwist_lwip_server * | cwist_lwip_listen (cwist_app *app, const cwist_lwip_config *cfg) |
Bind a listening tcp_pcb on cfg->port and serve app on it. | |
| void | cwist_lwip_close (cwist_lwip_server *srv) |
Stop listening, abort every open connection, and free srv. | |
| size_t | cwist_lwip_active_connections (const cwist_lwip_server *srv) |
| Number of connections the server currently holds open. | |
| cwist_lwip_tls * | cwist_lwip_tls_create (const unsigned char *cert, size_t cert_len, const unsigned char *key, size_t key_len) |
| Create a TLS server context from a certificate chain and private key. | |
| void | cwist_lwip_tls_destroy (cwist_lwip_tls *tls) |
| Free a TLS context; close every server using it first. | |
CWIST over lwIP's raw TCP API; see <cwist/sys/port/lwip.h>.
Not part of libcwist: the firmware compiles this file next to lwIP so it picks up the firmware's lwipopts.h. Uses only public CWIST API (parse, dispatch, serialize), which keeps it independent of the socket runtime.
One connection runs one exchange at a time:
recv -> rx buffer -> frame (Content-Length) -> parse -> dispatch -> serialize into tx -> tcp_write as tcp_sndbuf allows -> tcp_sent acks drain tx -> next pipelined request or close
tx is written without TCP_WRITE_FLAG_COPY, so lwIP references it until the peer acknowledges; it is freed only once tx_acked reaches tx_len.
With CWIST_LWIP_TLS and cfg.tls set, mbedTLS sits between the pcb and the same rx/tx buffers: received ciphertext queues in tin and is decrypted into rx by the pump; tx goes through mbedtls_ssl_write, whose records are copied into lwIP (TCP_WRITE_FLAG_COPY) by the BIO, so tx can be freed as soon as mbedTLS has taken all of it. The next pipelined request is then picked up from tcp_sent, as on the plaintext path.
Definition in file lwip.c.
| void cwist_lwip_close | ( | cwist_lwip_server * | srv | ) |
Stop listening, abort every open connection, and free srv.
Stop listening and abort every open connection, then free srv.
| srv | Server returned by cwist_lwip_listen(); NULL is a no-op. |
Definition at line 774 of file lwip.c.
References cap, and cwist_free().
| void cwist_lwip_config_init | ( | cwist_lwip_config * | cfg | ) |
Fill cfg with the defaults documented on cwist_lwip_config.
| cfg | Configuration to initialize. |
Definition at line 712 of file lwip.c.
References cap, cwist_lwip_config::idle_timeout_ms, cwist_lwip_config::keep_alive, cwist_lwip_config::max_body_bytes, cwist_lwip_config::max_conns, cwist_lwip_config::max_header_bytes, cwist_lwip_config::port, and cwist_lwip_config::tls.
Referenced by cwist_lwip_listen().
| cwist_lwip_server * cwist_lwip_listen | ( | cwist_app * | app, |
| const cwist_lwip_config * | cfg | ||
| ) |
Bind a listening tcp_pcb on cfg->port and serve app on it.
Bind a listening tcp_pcb on cfg->port (any address) and serve app on it.
| app | Application to dispatch to; must outlive the server. |
| cfg | Settings, copied; NULL means the defaults. |
Definition at line 729 of file lwip.c.
References cap, cwist_alloc(), cwist_free(), and cwist_lwip_config_init().
| cwist_lwip_tls * cwist_lwip_tls_create | ( | const unsigned char * | cert, |
| size_t | cert_len, | ||
| const unsigned char * | key, | ||
| size_t | key_len | ||
| ) |
Create a TLS server context from a certificate chain and private key.
| cert | Certificate chain, leaf first (PEM with its NUL counted, or DER). |
| cert_len | Length of cert. |
| key | Matching private key (PEM with its NUL counted, or DER). |
| key_len | Length of key. |
Definition at line 804 of file lwip.c.
References cap, cwist_alloc(), and cwist_lwip_tls_destroy().
| void cwist_lwip_tls_destroy | ( | cwist_lwip_tls * | tls | ) |
Free a TLS context; close every server using it first.
Free a TLS context. Close every server using it first.
| tls | Context from cwist_lwip_tls_create(); NULL is a no-op. |
Definition at line 841 of file lwip.c.
References cap, and cwist_free().
Referenced by cwist_lwip_tls_create().