]> git.meshlink.io Git - utcp/blob - utcp.h
Remove unconditional debug messages.
[utcp] / utcp.h
1 /*
2     utcp.h -- Userspace TCP
3     Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef UTCP_H
21 #define UTCP_H
22
23 #include <unistd.h>
24 #include <stdint.h>
25 #include <stdbool.h>
26 // TODO: Windows
27 #include <sys/time.h>
28
29 #ifndef UTCP_INTERNAL
30 struct utcp {
31         void *priv;
32 };
33
34 struct utcp_connection {
35         void *priv;
36         struct utcp *utcp;
37 };
38 #else
39 struct utcp;
40 struct utcp_connection;
41 #endif
42
43 typedef bool (*utcp_pre_accept_t)(struct utcp *utcp, uint16_t port);
44 typedef void (*utcp_accept_t)(struct utcp_connection *utcp_connection, uint16_t port);
45
46 typedef ssize_t (*utcp_send_t)(struct utcp *utcp, const void *data, size_t len);
47 typedef ssize_t (*utcp_recv_t)(struct utcp_connection *connection, const void *data, size_t len);
48
49 typedef void (*utcp_poll_t)(struct utcp_connection *connection, size_t len);
50
51 extern struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv);
52 extern void utcp_exit(struct utcp *utcp);
53
54 extern struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv);
55 extern void utcp_accept(struct utcp_connection *utcp, utcp_recv_t recv, void *priv);
56 extern ssize_t utcp_send(struct utcp_connection *connection, const void *data, size_t len);
57 extern ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len);
58 extern int utcp_close(struct utcp_connection *connection);
59 extern int utcp_abort(struct utcp_connection *connection);
60 extern int utcp_shutdown(struct utcp_connection *connection, int how);
61 extern struct timeval utcp_timeout(struct utcp *utcp);
62 extern void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv);
63 extern void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll);
64
65 // Global socket options
66
67 extern int utcp_get_user_timeout(struct utcp *utcp);
68 extern void utcp_set_user_timeout(struct utcp *utcp, int seconds);
69
70 extern uint16_t utcp_get_mtu(struct utcp *utcp);
71 extern void utcp_set_mtu(struct utcp *utcp, uint16_t mtu);
72
73 // Per-socket options
74
75 extern size_t utcp_get_sndbuf(struct utcp_connection *connection);
76 extern void utcp_set_sndbuf(struct utcp_connection *connection, size_t size);
77
78 extern size_t utcp_get_sndbuf_free(struct utcp_connection *connection);
79
80 extern bool utcp_get_nodelay(struct utcp_connection *connection);
81 extern void utcp_set_nodelay(struct utcp_connection *connection, bool nodelay);
82
83 extern bool utcp_get_keepalive(struct utcp_connection *connection);
84 extern void utcp_set_keepalive(struct utcp_connection *connection, bool keepalive);
85
86 extern size_t utcp_get_outq(struct utcp_connection *connection);
87
88 #endif