diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 17:22:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 20:21:42 +0000 |
commit | beeb9b4335d9ca6f947a52528453753a51f194f3 (patch) | |
tree | 242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/TCP_server.h | |
parent | cbda01021c561bd061cb03a1c1bab58199ac2307 (diff) |
Style fixes in TCP code; remove MIN and PAIR from util.h.
* Moved PAIR to toxav, where it's used (but really this should die).
* Replace most MIN calls with typed `min_*` calls. Didn't replace the
ones where the desired semantics are unclear. Moved the MIN macro to
the one place where it's still used.
* Avoid assignments in `while` loops. Instead, factored out the loop body
into a separate `bool`-returning function.
* Use named types for callbacks (`_cb` types).
* Avoid assignments in `if` conditions.
* Removed `MAKE_REALLOC` and expanded its two calls. We can't have
templates in C, and this fake templating is ugly and hard to analyse
and debug (it expands on a single line).
* Moved epoll system include to the .c file, out of the .h file.
* Avoid assignments in expressions (`a = b = c;`).
* Avoid multiple declarators per struct member declaration.
* Fix naming inconsistencies.
* Replace `net_to_host` macro with function.
Diffstat (limited to 'toxcore/TCP_server.h')
-rw-r--r-- | toxcore/TCP_server.h | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index c8cbeda0..632a5e79 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h | |||
@@ -28,10 +28,6 @@ | |||
28 | #include "list.h" | 28 | #include "list.h" |
29 | #include "onion.h" | 29 | #include "onion.h" |
30 | 30 | ||
31 | #ifdef TCP_SERVER_USE_EPOLL | ||
32 | #include <sys/epoll.h> | ||
33 | #endif | ||
34 | |||
35 | #define MAX_INCOMING_CONNECTIONS 256 | 31 | #define MAX_INCOMING_CONNECTIONS 256 |
36 | 32 | ||
37 | #define TCP_MAX_BACKLOG MAX_INCOMING_CONNECTIONS | 33 | #define TCP_MAX_BACKLOG MAX_INCOMING_CONNECTIONS |
@@ -63,25 +59,19 @@ | |||
63 | #define TCP_PING_FREQUENCY 30 | 59 | #define TCP_PING_FREQUENCY 30 |
64 | #define TCP_PING_TIMEOUT 10 | 60 | #define TCP_PING_TIMEOUT 10 |
65 | 61 | ||
66 | #ifdef TCP_SERVER_USE_EPOLL | 62 | typedef enum TCP_Status { |
67 | #define TCP_SOCKET_LISTENING 0 | ||
68 | #define TCP_SOCKET_INCOMING 1 | ||
69 | #define TCP_SOCKET_UNCONFIRMED 2 | ||
70 | #define TCP_SOCKET_CONFIRMED 3 | ||
71 | #endif | ||
72 | |||
73 | enum { | ||
74 | TCP_STATUS_NO_STATUS, | 63 | TCP_STATUS_NO_STATUS, |
75 | TCP_STATUS_CONNECTED, | 64 | TCP_STATUS_CONNECTED, |
76 | TCP_STATUS_UNCONFIRMED, | 65 | TCP_STATUS_UNCONFIRMED, |
77 | TCP_STATUS_CONFIRMED, | 66 | TCP_STATUS_CONFIRMED, |
78 | }; | 67 | } TCP_Status; |
79 | 68 | ||
80 | typedef struct TCP_Priority_List TCP_Priority_List; | 69 | typedef struct TCP_Priority_List TCP_Priority_List; |
81 | 70 | ||
82 | struct TCP_Priority_List { | 71 | struct TCP_Priority_List { |
83 | TCP_Priority_List *next; | 72 | TCP_Priority_List *next; |
84 | uint16_t size, sent; | 73 | uint16_t size; |
74 | uint16_t sent; | ||
85 | uint8_t data[]; | 75 | uint8_t data[]; |
86 | }; | 76 | }; |
87 | 77 | ||
@@ -97,11 +87,11 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin | |||
97 | 87 | ||
98 | /* Run the TCP_server | 88 | /* Run the TCP_server |
99 | */ | 89 | */ |
100 | void do_TCP_server(TCP_Server *TCP_server); | 90 | void do_TCP_server(TCP_Server *tcp_server); |
101 | 91 | ||
102 | /* Kill the TCP server | 92 | /* Kill the TCP server |
103 | */ | 93 | */ |
104 | void kill_TCP_server(TCP_Server *TCP_server); | 94 | void kill_TCP_server(TCP_Server *tcp_server); |
105 | 95 | ||
106 | /* Read the next two bytes in TCP stream then convert them to | 96 | /* Read the next two bytes in TCP stream then convert them to |
107 | * length (host byte order). | 97 | * length (host byte order). |