libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-transport-sequencer.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2026 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24#if !defined(__LWS_TRANSPORT_SEQUENCER_H__)
25#define __LWS_TRANSPORT_SEQUENCER_H__
26
27#include <stdint.h>
28#include <stddef.h>
29
30#if defined(LWS_WITH_TRANSPORT_SEQUENCER)
31
32
41
42struct lws_transport_sequencer;
43
44typedef int (*lws_transport_sequencer_cb_t)(struct lws_transport_sequencer *ts,
45 uint64_t offset, uint8_t *buf,
46 size_t *len);
47
48typedef struct lws_transport_sequencer_sack_block {
49 uint64_t start;
50 uint32_t len;
51} lws_transport_sequencer_sack_block_t;
52
53/*
54 * Lifetime: tx_chunk and tx_ack are called in the middle of the sequencer's
55 * work and must not destroy it. on_rx_data and on_state_change are always
56 * the last thing the sequencer does before returning to its caller, and it
57 * does not touch ts after them, so they (or what they call) may destroy it.
58 * A caller of lws_transport_sequencer_rx(), _acknowledge(), or
59 * _acknowledge_sack() must not use ts after it returns, unless it knows its
60 * callbacks did not destroy it.
61 */
62
63typedef struct lws_transport_sequencer_ops {
64 const char *name;
65
66 int (*tx_chunk)(struct lws_transport_sequencer *ts, uint64_t offset,
67 const uint8_t *buf, size_t len);
70
71 int (*tx_ack)(struct lws_transport_sequencer *ts, uint64_t offset,
72 size_t len);
75
76 int (*on_rx_data)(struct lws_transport_sequencer *ts, uint64_t offset,
77 const uint8_t *buf, size_t len);
82
83 void (*on_state_change)(struct lws_transport_sequencer *ts, int state, int status);
88
89 void (*on_writeable)(struct lws_transport_sequencer *ts);
96
97} lws_transport_sequencer_ops_t;
98
99typedef struct lws_transport_sequencer_stats {
100 uint32_t tx_packets;
101 uint32_t tx_retries;
102 uint32_t rx_packets;
103 uint32_t rx_duplicates;
104 uint64_t tx_bytes;
105 uint64_t rx_bytes;
106 uint64_t ack_offset;
109 uint64_t rx_offset;
112 uint64_t tx_offset;
115} lws_transport_sequencer_stats_t;
116
117typedef struct lws_transport_sequencer_info {
118 struct lws_context *cx;
119 const lws_transport_sequencer_ops_t *ops;
120 const lws_retry_bo_t *retry_policy;
121 void *user_data;
122
123 uint32_t window_size;
125
126 const char *peer;
129
130 uint8_t unproven_peer:1;
140} lws_transport_sequencer_info_t;
141
147LWS_VISIBLE LWS_EXTERN struct lws_transport_sequencer *
148lws_transport_sequencer_create(const lws_transport_sequencer_info_t *i);
149
156lws_transport_sequencer_destroy(struct lws_transport_sequencer **pts);
157
161enum lws_transport_sequencer_write_result {
162 LWS_TSW_QUEUED = 0,
164 LWS_TSW_FAILED = 1,
166 LWS_TSW_BUSY = 2,
170};
171
187lws_transport_sequencer_write(struct lws_transport_sequencer *ts,
188 const uint8_t *buf, size_t len);
189
203lws_transport_sequencer_write_at(struct lws_transport_sequencer *ts,
204 uint64_t offset, const uint8_t *buf, size_t len);
205
217lws_transport_sequencer_acknowledge(struct lws_transport_sequencer *ts,
218 uint64_t offset, size_t len, int status);
219
244lws_transport_sequencer_acknowledge_sack(struct lws_transport_sequencer *ts,
245 uint64_t cumulative_offset,
246 const lws_transport_sequencer_sack_block_t *blocks,
247 size_t num_blocks, int status);
248
265lws_transport_sequencer_resend(struct lws_transport_sequencer *ts);
266
287lws_transport_sequencer_tx_rebase(struct lws_transport_sequencer *ts);
288
289LWS_VISIBLE LWS_EXTERN const lws_transport_sequencer_stats_t *
290lws_transport_sequencer_get_stats(struct lws_transport_sequencer *ts);
291
312lws_transport_sequencer_rx(struct lws_transport_sequencer *ts,
313 uint64_t offset, const uint8_t *buf, size_t len);
314
328lws_transport_sequencer_rx_reset(struct lws_transport_sequencer *ts);
329
340lws_transport_sequencer_get_sack_blocks(struct lws_transport_sequencer *ts,
341 lws_transport_sequencer_sack_block_t *blocks,
342 size_t max_blocks);
343
344LWS_VISIBLE LWS_EXTERN const lws_transport_sequencer_info_t *
345lws_transport_sequencer_get_info(struct lws_transport_sequencer *ts);
346
348
349#endif /* LWS_WITH_TRANSPORT_SEQUENCER */
350
351#endif /* __LWS_TRANSPORT_SEQUENCER_H__ */
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
struct lws_retry_bo lws_retry_bo_t