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