aboutsummaryrefslogtreecommitdiff
path: root/lib/roles/h1
AgeCommit message (Collapse)Author
2021-10-16http: sse: check POLLIN during DOING_TRANSACTIONAndy Green
When the client goes away, on some platforms all we get is POLLIN revent stuck on... we have to read it to find out a zero length result and understand it's gone. Add SSE mode's DOING_TRANSACTION to the list of states we will read for.
2021-08-19server: http-proxy: fix POSTAndy Green
2021-05-23sse: server: handle close found as HUPAndy Green
2021-03-08lws_metricsAndy Green
There are a few build options that are trying to keep and report various statistics - DETAILED_LATENCY - SERVER_STATUS - WITH_STATS remove all those and establish a generic rplacement, lws_metrics. lws_metrics makes its stats available via an lws_system ops function pointer that the user code can set. Openmetrics export is supported, for, eg, prometheus scraping.
2021-02-20HUP: mark socket unusableAndy Green
2021-01-29bsd: POLLHUP always bound to POLLINAndy Green
On OSX, POLLHUP is always |POLLIN, even if you did not wait on POLLIN. This causes a loop because we don't want to ack the POLLHUP until we cleared any pollin (but there is no pending POLLIN...)
2021-01-05type comparisons: fixesAndy Green
This is a huge patch that should be a global NOP. For unix type platforms it enables -Wconversion to issue warnings (-> error) for all automatic casts that seem less than ideal but are normally concealed by the toolchain. This is things like passing an int to a size_t argument. Once enabled, I went through all args on my default build (which build most things) and tried to make the removed default cast explicit. With that approach it neither change nor bloat the code, since it compiles to whatever it was doing before, just with the casts made explicit... in a few cases I changed some length args from int to size_t but largely left the causes alone. From now on, new code that is relying on less than ideal casting will complain and nudge me to improve it by warnings.
2021-01-04lws_lifecycleAndy Green
This adds some new objects and helpers for keeping and logging info on grouped allocations, a group is, eg, SS handles or client wsis. Allocated objects get a context-unique "tag" string intended to replace %p / wsi pointers etc. Pointers quickly become confusing when allocations are freed and reused, the tag string won't repeat until you produce 2^64 objects in a context. In addition the tag string documents the object group, with prefixes like "wsi-" or "vh-" and contain object-specific additional information like the vhost name, address / port or the role of the wsi. At creation time the lws code can use a format string and args to add whatever group-specific info makes sense, eg, a wsi bound to a secure stream can also append the guid of the secure stream, it's copied into the new object tag and so is still available cleanly after the stream is destroyed if the wsi outlives it.
2020-12-24h2: post: add states to wait for bodyAndy Green
2020-12-24h2: post: handle no content length betterAndy Green
http content-length is not mandatory on POST, making a whole bunch of difficulties. On h2, the client will set the stream half-closed by DATA with END_STREAM flag when it is done. Improve the post data tracking to understand that situation properly.
2020-11-28roles: compress role ops structsAndy Green
role ops are usually only sparsely filled, there are currently 20 function pointers but several roles only fill in two. No single role has more than 14 of the ops. On a 32/64 bit build this part of the ops struct takes a fixed 80 / 160 bytes then. First reduce the type of the callback reason part from uint16_t to uint8_t, this saves 12 bytes unconditionally. Change to a separate function pointer array with a nybble index array, it costs 10 bytes for the index and a pointer to the separate array, for 32-bit the cost is 2 + (4 x ops_used) and for 64-bit 6 + (8 x ops_used) for 2 x ops_used it means 32-bit: 10 vs 80 / 64-bit: 22 vs 160 For a typical system with h1 (9), h2 (14), listen (2), netlink (2), pipe (1), raw_skt (3), ws (12), == 43 ops_used out of 140, it means the .rodata for this reduced from 32-bit: 560 -> 174 (386 byte saving) and 64-bit: 1120 -> 350 (770 byte saving) This doesn't account for the changed function ops calling code, two ways were tried, a preprocessor macro and explicit functions For an x86_64 gcc 10 build with most options, release mode, .text + .rodata before patch: 553282 accessor macro: 552714 (568 byte saving) accessor functions: 553674 (392 bytes worse than without patch) therefore we went with the macros
2020-10-06h1: explicitly close when post txn completesAndy Green
https://github.com/warmcat/libwebsockets/issues/2072
2020-09-21client: move staged connect pieces into core-netAndy Green
They have been in lib/roles/http for historical reasons, and all ended up in client-handshake.c that doesn't describe what they actually do any more. Separate out the staged client connect related stage functions into lib/core-net/client/client2.c: lws_client_connect_2_dnsreq() lib/core-net/client/client3.c: lws_client_connect_3_connect() lib/core-net/client/client4.c: lws_client_connect_4_established() Move a couple of other functions from there that don't belong out to tls-client.c and client-http.c, which is related to http and remains in the http role dir.
2020-08-31h2: fix breakage with LWS_WITH_HTTP2=0Andy Green
2020-08-19coverity: 10417: move goto inside preprocessor conditional that needs itAndy Green
Otherwise coverity sees it with !defined(LWS_ROLE_WS) sitting there doing nothing
2020-07-28ss-server-rawAndy Green
Add an example and some small changes for secure streams serving raw data over a listening tcp socket
2020-07-20fakewsi: replace with smaller substructureAndy Green
Currently we always reserve a fakewsi per pt so events that don't have a related actual wsi, like vhost-protocol-init or vhost cert init via protocol callback can make callbacks that look reasonable to user protocol handler code expecting a valid wsi every time. This patch splits out stuff that user callbacks often unconditionally expect to be in a wsi, like context pointer, vhost pointer etc into a substructure, which is composed into struct lws at the top of it. Internal references (struct lws is opaque, so there are only internal references) are all updated to go via the substructre, the compiler should make that a NOP. Helpers are added when fakewsi is used and referenced. If not PLAT_FREERTOS, we continue to provide a full fakewsi in the pt as before, although the helpers improve consistency by zeroing down the substructure. There is a huge amount of user code out there over the last 10 years that did not always have the minimal examples to follow, some of it does some unexpected things. If it is PLAT_FREERTOS, that is a newer thing in lws and users have the benefit of being able to follow the minimal examples' approach. For PLAT_FREERTOS we don't reserve the fakewsi in the pt any more, saving around 800 bytes. The helpers then create a struct lws_a (the substructure) on the stack, zero it down (but it is only like 4 pointers) and prepare it with whatever we know like the context. Then we cast it to a struct lws * and use it in the user protocol handler call. In this case, the remainder of the struct lws is undefined. However the amount of old protocol handlers that might touch things outside of the substructure in PLAT_FREERTOS is very limited compared to legacy lws user code and the saving is significant on constrained devices. User handlers should not be touching everything in a wsi every time anyway, there are several cases where there is no valid wsi to do the call with. Dereference of things outside the substructure should only happen when the callback reason shows there is a valid wsi bound to the activity (as in all the minimal examples).
2020-05-27cmakelist: Augean Stables refactorAndy Green
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
2020-05-08h2: add prior knowledge supportKyle Greenwell
2020-04-19ctest: fixes-and-changesAndy Green
2020-03-26h1: handle LRS_FLUSHING_BEFORE_CLOSE at ops readAndy Green
read has a tight leash on the states it's happy to turn up there, it's good to be like that but it turns out LRS_FLUSHING_BEFORE_CLOSE should be whitelisted since it can happen under some transient conditions and is valid. https://github.com/warmcat/libwebsockets/issues/1872
2020-03-04rtos diet: make raw_file role optionalAndy Green
2020-02-21lws_spawn_piped: break out from cgiAndy Green
The vfork optimized spawn, stdxxx and terminal handling in the cgi implementation is quite mature and sophisticated, and useful for other things unrelated to cgi. Break it out into its own public api under LWS_WITH_SPAWN, off by default. Expand it so the parent wsi is optional, and the role and protocol bindings for stdxxx pipes can be set. Allow optional sul timeout and external lws_dll2 owner for extant children. Remove inline style from minimal http-server-cgi
2020-02-21minimal-http-client-multi: add POSTAndy Green
This adds support for POST in both h1 and h2 queues / stream binding. The previous queueing tried to keep the "leader" wsi who made the actual connection around and have it act on the transaction queue tail if it had done its own thing. This refactors it so instead, who is the "leader" moves down the queue and the queued guys inherit the fd, SSL * and queue from the old leader as they take over. This lets them operate in their own wsi identity directly and gets rid of all the "effective wsi" checks, which was applied incompletely and getting out of hand considering the separate lws_mux checks for h2 and other muxed protocols alongside it. This change also allows one wsi at a time to own the transaction for POST. --post is added as an option to lws-minimal-http-client-multi and 6 extra selftests with POST on h1/h2, pipelined or not and staggered or not are added to the CI.
2020-02-04http client: allow HEAD method at h1 client bindZevv
2020-01-20lws_buflist_aware_read: restrict to incoming ebuf length if non-NULL ↵Andy Green
ebuf.token incoming (Includes fixes from Yichen Gu) Currently the incoming ebuf is always replaced to point to either a whole buflist segment, or up to the (pt_serv_buf - LWS_PRE) length in the pt_serv_buf. This is called on path for handling http read... some user code reasonably wants to restrict the read size to what it can handle. Change the other lws_buflist_aware_read() callers to zero ebuf before calling, and for those have it keep the current behaviour; but if non-NULL ebuf.token on incoming, as in http read path case, restrict both reported len of buflist content and the read length to the incoming ebuf.len so the user code can control what it will get at one time. Additionally muxed protocol wsi have no choice but to read what was sent to them since it's HOL-blocking for other streams and its own WINDOW_UPDATEs. So add an internal param to lws_buflist_aware_read() forcing read even if buflist content is available.
2020-01-17linkit: support build using public sdkAndy Green
This provides support to build lws using the linkit 7697 public SDK from here https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/downloads This toolchain has some challenges, its int32_t / uint32_t are long, so assumptions about format strings for those being %u / %d / %x all break. This fixes all the cases for the features enabled by the default cmake settings.
2020-01-15role structs to constAndy Green
Indicate these are immutable (they're already treated as such) and can go in .rodata
2020-01-05cleaningAndy Green
2019-12-29mux children: generalize helpers out of h2 implementationAndy Green
This should be a NOP for h2 support and only affects internal apis. But it lets us reuse the working and reliable h2 mux arrangements directly in other protocols later, and share code so building for h2 + new protocols can take advantage of common mux child handling struct and code. Break out common mux handling struct into its own type. Convert all uses of members that used to be in wsi->h2 to wsi->mux Audit all references to the members and break out generic helpers for anything that is useful for other mux-capable protocols to reuse wsi->mux related features.
2019-09-22lws_validity: unified connection validity trackingAndy Green
Refactor everything around ping / pong handling in ws and h2, so there is instead a protocol-independent validity lws_sul tracking how long it has been since the last exchange that confirms the operation of the network connection in both directions. Clean out periodic role callback and replace the last two role users with discrete lws_sul for each pt.
2019-09-22client: use block parse and buflistAndy Green
With http, the protocol doesn't indicate where the headers end and the next transaction or body begin. Until now, we handled that for client header response parsing by reading from the tls buffer bytewise. This modernizes the code to read in up to 256-byte chunks and parse the chunks in one hit (the parse API is already set up for doing this elsewhere). Now we have a generic input buflist, adapt the parser loop to go through that and arrange that any leftovers are placed on there.
2019-09-22buflist: add static reason logging to internal aware apisAndy Green
2019-08-26freertos: rename esp32 plat to freertosAndy Green
2019-08-26clean: internally use LWS_WITH_CLIENT and _SERVERAndy Green
Remove some more things in LWS_WITH_SERVER=0 case
2019-08-19client: do client stash in a single allocAndy Green
Improve the code around stash, getting rid of the strdups for a net code reduction. Remove the special destroy helper for stash since it becomes a one-liner. Trade several stack allocs in the client reset function for a single sized brief heap alloc to reduce peak stack alloc by around 700 bytes.
2019-08-15private.h: rename to contain dirAndy Green
Having unique private header names is a requirement of a particular platform build system it's desirable to work with
2019-08-14license: switch LGPLv2.1+SLE parts to MITAndy Green
2019-08-12stats: move to pt and improve presentationAndy Green
2019-08-09sul: all timed objects use a single pt sul listAndy Green
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
2019-07-16COVA11782: comment NOP statementAndy Green
2019-07-13COVA10299: check lws_change_pollfdAndy Green
2019-07-13COVA10417: help coverity see no problemAndy Green
This isn't strange if coverity could understand the preprocessor options
2019-07-05http: body: make sure to consume body before transaction completeAndy Green
https://github.com/warmcat/libwebsockets/issues/1625 "dead bodies" that were sent but not processed by lws as server will clog up and destroy transaction tracking if repeated POSTs with keepalive are sent to nonexistant paths. This patch introduces a DISCARD_BODY state that follows BODY except the payload is not signalled to the protocol callback. Calling transaction_completed() with pending body makes lws enter DISCARD_BODY and retry transaction completed only after the pending body is exhausted.
2019-07-01buflist: ensure all use callers have nonzero lenAndy Green
2019-05-30Change some struct members to unsigned charOrgad Shaneh
Enables removal of superfluous casts, and fixes strict-aliasing warnings with GCC 4.1.
2019-05-06generic-sessions updateAndy Green
Generic sessions has been overdue some love to align it with the progress in the rest of lws. 1) Strict Content Security Policy 2) http2 compatibility 3) fixes and additions for use in a separate process via unix domain socket 4) work on ws and http proxying in lws 5) add minimal example
2019-04-06post: only report BODY_COMPLETION onceAndy Green
2019-03-22http proxy: support POSTAndy Green
2019-03-10ws: setting default protocol index to an illegal index disables default ws ↵Andy Green
binding On lwsws, incoming ws connections to the default vhost are not rejected by the dummy protocol handler and not really serviced either, leading to bots connecting to it to get immortal, idle ws connections with no timeout (since it's an established ws connection). Rejecting these connections by default by adding a handler for ESTABLISHED in the dummy handler will solve it nicely, but it will break an unknown number of dumb. protocol-less user implementations that rely on this behaviour by using break; from their own ESTABLISHED handler and calling through to the currently NOP dummy handler one. Add support to assertively disable the default protocol index used for subprotocol-less ws connections instead.