blob: 98dba7150047143fad165f32b767895dffe62a40 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_tcp.h Interface to Transport Control Protocol
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6struct sa;
7struct tcp_sock;
8struct tcp_conn;
9
10
11/**
12 * Defines the incoming TCP connection handler
13 *
14 * @param peer Network address of peer
15 * @param arg Handler argument
16 */
17typedef void (tcp_conn_h)(const struct sa *peer, void *arg);
18
19/**
20 * Defines the TCP connection established handler
21 *
22 * @param arg Handler argument
23 */
24typedef void (tcp_estab_h)(void *arg);
25
26/**
27 * Defines the TCP connection data send handler
28 *
29 * @param arg Handler argument
30 */
31typedef void (tcp_send_h)(void *arg);
32
33/**
34 * Defines the TCP connection data receive handler
35 *
36 * @param mb Buffer with data
37 * @param arg Handler argument
38 */
39typedef void (tcp_recv_h)(struct mbuf *mb, void *arg);
40
41/**
42 * Defines the TCP connection close handler
43 *
44 * @param err Error code
45 * @param arg Handler argument
46 */
47typedef void (tcp_close_h)(int err, void *arg);
48
49
50/* TCP Socket */
51int tcp_sock_alloc(struct tcp_sock **tsp, const struct sa *local,
52 tcp_conn_h *ch, void *arg);
53int tcp_sock_bind(struct tcp_sock *ts, const struct sa *local);
54int tcp_sock_listen(struct tcp_sock *ts, int backlog);
55int tcp_accept(struct tcp_conn **tcp, struct tcp_sock *ts, tcp_estab_h *eh,
56 tcp_recv_h *rh, tcp_close_h *ch, void *arg);
57void tcp_reject(struct tcp_sock *ts);
58int tcp_sock_local_get(const struct tcp_sock *ts, struct sa *local);
59
60
61/* TCP Connection */
62int tcp_conn_alloc(struct tcp_conn **tcp, const struct sa *peer,
63 tcp_estab_h *eh, tcp_recv_h *rh, tcp_close_h *ch,
64 void *arg);
65int tcp_conn_bind(struct tcp_conn *tc, const struct sa *local);
66int tcp_conn_connect(struct tcp_conn *tc, const struct sa *peer);
67int tcp_send(struct tcp_conn *tc, struct mbuf *mb);
68int tcp_set_send(struct tcp_conn *tc, tcp_send_h *sendh);
69void tcp_set_handlers(struct tcp_conn *tc, tcp_estab_h *eh, tcp_recv_h *rh,
70 tcp_close_h *ch, void *arg);
71void tcp_conn_rxsz_set(struct tcp_conn *tc, size_t rxsz);
72void tcp_conn_txqsz_set(struct tcp_conn *tc, size_t txqsz);
73int tcp_conn_local_get(const struct tcp_conn *tc, struct sa *local);
74int tcp_conn_peer_get(const struct tcp_conn *tc, struct sa *peer);
75int tcp_conn_fd(const struct tcp_conn *tc);
76size_t tcp_conn_txqsz(const struct tcp_conn *tc);
77
78
79/* High-level API */
80int tcp_listen(struct tcp_sock **tsp, const struct sa *local,
81 tcp_conn_h *ch, void *arg);
82int tcp_connect(struct tcp_conn **tcp, const struct sa *peer,
83 tcp_estab_h *eh, tcp_recv_h *rh, tcp_close_h *ch, void *arg);
84int tcp_local_get(const struct tcp_sock *ts, struct sa *local);
85
86
87/* Helper API */
88typedef bool (tcp_helper_estab_h)(int *err, bool active, void *arg);
89typedef bool (tcp_helper_send_h)(int *err, struct mbuf *mb, void *arg);
90typedef bool (tcp_helper_recv_h)(int *err, struct mbuf *mb, bool *estab,
91 void *arg);
92
93struct tcp_helper;
94
95
96int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,
97 int layer,
98 tcp_helper_estab_h *eh, tcp_helper_send_h *sh,
99 tcp_helper_recv_h *rh, void *arg);
100int tcp_send_helper(struct tcp_conn *tc, struct mbuf *mb,
101 struct tcp_helper *th);