This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/infra/tcp_reassembly/tcp_reassembly.h

64 lines
1.6 KiB
C
Raw Normal View History

#pragma once
2024-03-21 19:27:41 +08:00
2024-04-21 11:30:41 +08:00
#ifdef __cplusplus
2024-03-21 19:27:41 +08:00
extern "C"
{
#endif
#include <stdint.h>
2024-08-28 19:00:32 +08:00
#include <stdbool.h>
2024-03-21 19:27:41 +08:00
struct tcp_segment
2024-03-21 19:27:41 +08:00
{
uint32_t len;
const void *data;
2024-03-21 19:27:41 +08:00
};
struct tcp_segment *tcp_segment_new(uint32_t seq, const void *data, uint32_t len);
void tcp_segment_free(struct tcp_segment *seg);
2024-03-21 19:27:41 +08:00
struct tcp_reassembly *tcp_reassembly_new(uint64_t max_timeout, uint64_t max_seg_num);
void tcp_reassembly_free(struct tcp_reassembly *tcp_reass);
2024-03-21 19:27:41 +08:00
/*
* return: 1: push tcp segment success (segment overlap)
* return: 0: push tcp segment success
* return: -1: push tcp segment failed (no space)
* return: -2: push tcp segment failed (segment repeat)
*/
int tcp_reassembly_push(struct tcp_reassembly *tcp_reass, struct tcp_segment *seg, uint64_t now);
struct tcp_segment *tcp_reassembly_pop(struct tcp_reassembly *tcp_reass);
struct tcp_segment *tcp_reassembly_expire(struct tcp_reassembly *tcp_reass, uint64_t now);
2024-03-21 19:27:41 +08:00
void tcp_reassembly_inc_recv_next(struct tcp_reassembly *tcp_reass, uint32_t offset);
void tcp_reassembly_set_recv_next(struct tcp_reassembly *tcp_reass, uint32_t seq);
uint32_t tcp_reassembly_get_recv_next(struct tcp_reassembly *tcp_reass);
2024-03-21 19:27:41 +08:00
/*
* The next routines deal with comparing 32 bit unsigned ints
* and worry about wraparound (automatic with unsigned arithmetic).
*/
static inline bool uint32_before(uint32_t seq1, uint32_t seq2)
{
return (int32_t)(seq1 - seq2) < 0;
}
static inline uint32_t uint32_add(uint32_t seq, uint32_t inc)
{
if (seq > UINT32_MAX - inc)
{
seq = ((uint64_t)seq + (uint64_t)inc) % (4294967296);
}
else
{
seq += inc;
}
return seq;
}
2024-04-21 11:30:41 +08:00
#ifdef __cplusplus
2024-03-21 19:27:41 +08:00
}
#endif