2 utcp.h -- Userspace TCP
3 Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 struct utcp_connection {
36 struct utcp *const utcp;
41 struct utcp_connection;
44 #define UTCP_SHUT_RD 0
45 #define UTCP_SHUT_WR 1
46 #define UTCP_SHUT_RDWR 2
48 #define UTCP_ORDERED 1
49 #define UTCP_RELIABLE 2
51 #define UTCP_DROP_LATE 8
52 #define UTCP_NO_PARTIAL 16
57 typedef bool (*utcp_pre_accept_t)(struct utcp *utcp, uint16_t port);
58 typedef void (*utcp_accept_t)(struct utcp_connection *utcp_connection, uint16_t port);
60 typedef ssize_t (*utcp_send_t)(struct utcp *utcp, const void *data, size_t len);
61 typedef ssize_t (*utcp_recv_t)(struct utcp_connection *connection, const void *data, size_t len);
63 typedef void (*utcp_poll_t)(struct utcp_connection *connection, size_t len);
65 extern struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv);
66 extern void utcp_exit(struct utcp *utcp);
68 extern struct utcp_connection *utcp_connect_ex(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv, uint32_t flags);
69 extern struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv);
70 extern void utcp_accept(struct utcp_connection *utcp, utcp_recv_t recv, void *priv);
71 extern ssize_t utcp_send(struct utcp_connection *connection, const void *data, size_t len);
72 extern ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len);
73 extern int utcp_close(struct utcp_connection *connection);
74 extern int utcp_abort(struct utcp_connection *connection);
75 extern int utcp_shutdown(struct utcp_connection *connection, int how);
76 extern struct timeval utcp_timeout(struct utcp *utcp);
77 extern void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv);
78 extern void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll);
79 extern void utcp_set_accept_cb(struct utcp *utcp, utcp_accept_t accept, utcp_pre_accept_t pre_accept);
80 extern bool utcp_is_active(struct utcp *utcp);
81 extern void utcp_abort_all_connections(struct utcp *utcp);
83 // Global socket options
85 extern int utcp_get_user_timeout(struct utcp *utcp);
86 extern void utcp_set_user_timeout(struct utcp *utcp, int seconds);
88 extern uint16_t utcp_get_mtu(struct utcp *utcp);
89 extern void utcp_set_mtu(struct utcp *utcp, uint16_t mtu);
91 extern void utcp_reset_timers(struct utcp *utcp);
93 extern void utcp_offline(struct utcp *utcp, bool offline);
97 extern size_t utcp_get_sndbuf(struct utcp_connection *connection);
98 extern void utcp_set_sndbuf(struct utcp_connection *connection, size_t size);
99 extern size_t utcp_get_sndbuf_free(struct utcp_connection *connection);
101 extern size_t utcp_get_rcvbuf(struct utcp_connection *connection);
102 extern void utcp_set_rcvbuf(struct utcp_connection *connection, size_t size);
103 extern size_t utcp_get_rcvbuf_free(struct utcp_connection *connection);
105 extern size_t utcp_get_sendq(struct utcp_connection *connection);
106 extern size_t utcp_get_recvq(struct utcp_connection *connection);
108 extern bool utcp_get_nodelay(struct utcp_connection *connection);
109 extern void utcp_set_nodelay(struct utcp_connection *connection, bool nodelay);
111 extern bool utcp_get_keepalive(struct utcp_connection *connection);
112 extern void utcp_set_keepalive(struct utcp_connection *connection, bool keepalive);
114 extern size_t utcp_get_outq(struct utcp_connection *connection);
116 extern void utcp_expect_data(struct utcp_connection *connection, bool expect);