diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-27 02:07:59 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-05-20 15:42:42 +0000 |
commit | be797d4b039b40d2c876f0a71cd1e48454a74065 (patch) | |
tree | c759c0f15a3ac0285e0bd941dc3edad06ade015d /toxcore/network.h | |
parent | 291a849a5a0afb4450bcd0d0c50b7aeccaac04f5 (diff) |
Move system header includes from network.h to network.c
Diffstat (limited to 'toxcore/network.h')
-rw-r--r-- | toxcore/network.h | 84 |
1 files changed, 39 insertions, 45 deletions
diff --git a/toxcore/network.h b/toxcore/network.h index 10ddef02..bdfebd7e 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -24,54 +24,55 @@ | |||
24 | #ifndef NETWORK_H | 24 | #ifndef NETWORK_H |
25 | #define NETWORK_H | 25 | #define NETWORK_H |
26 | 26 | ||
27 | #ifdef PLAN9 | ||
28 | #include <u.h> // Plan 9 requires this is imported first | ||
29 | // Comment line here to avoid reordering by source code formatters. | ||
30 | #include <libc.h> | ||
31 | #endif | ||
32 | |||
33 | #include "ccompat.h" | ||
34 | #include "logger.h" | 27 | #include "logger.h" |
35 | 28 | ||
36 | #include <stdbool.h> | 29 | #include <stdbool.h> // bool |
37 | #include <stdint.h> | 30 | #include <stddef.h> // size_t |
38 | #include <stdio.h> | 31 | #include <stdint.h> // uint*_t |
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | #include <time.h> | ||
42 | |||
43 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) /* Put win32 includes here */ | ||
44 | #ifndef WINVER | ||
45 | //Windows XP | ||
46 | #define WINVER 0x0501 | ||
47 | #endif | ||
48 | 32 | ||
49 | // The mingw32/64 Windows library warns about including winsock2.h after | 33 | #ifdef __cplusplus |
50 | // windows.h even though with the above it's a valid thing to do. So, to make | 34 | extern "C" { |
51 | // mingw32 headers happy, we include winsock2.h first. | 35 | #endif |
52 | #include <winsock2.h> | ||
53 | 36 | ||
54 | #include <windows.h> | 37 | typedef uint8_t Family; |
55 | #include <ws2tcpip.h> | ||
56 | 38 | ||
57 | #else // UNIX includes | 39 | typedef struct Socket { |
40 | int socket; | ||
41 | } Socket; | ||
58 | 42 | ||
59 | #include <sys/socket.h> | 43 | Socket net_socket(Family domain, int type, int protocol); |
60 | #include <netinet/in.h> | ||
61 | #include <arpa/inet.h> | ||
62 | #include <netdb.h> | ||
63 | #include <unistd.h> | ||
64 | 44 | ||
65 | #endif | 45 | /* Check if socket is valid. |
46 | * | ||
47 | * return 1 if valid | ||
48 | * return 0 if not valid | ||
49 | */ | ||
50 | int sock_valid(Socket sock); | ||
66 | 51 | ||
67 | #ifdef __cplusplus | 52 | extern const Socket net_invalid_socket; |
68 | extern "C" { | ||
69 | #endif | ||
70 | 53 | ||
71 | typedef short Family; | 54 | /** |
55 | * Calls send(sockfd, buf, len, MSG_NOSIGNAL). | ||
56 | */ | ||
57 | int net_send(Socket sockfd, const void *buf, size_t len); | ||
58 | /** | ||
59 | * Calls recv(sockfd, buf, len, MSG_NOSIGNAL). | ||
60 | */ | ||
61 | int net_recv(Socket sockfd, void *buf, size_t len); | ||
62 | /** | ||
63 | * Calls listen(sockfd, backlog). | ||
64 | */ | ||
65 | int net_listen(Socket sockfd, int backlog); | ||
66 | /** | ||
67 | * Calls accept(sockfd, nullptr, nullptr). | ||
68 | */ | ||
69 | Socket net_accept(Socket sockfd); | ||
72 | 70 | ||
73 | typedef int Socket; | 71 | /** |
74 | Socket net_socket(int domain, int type, int protocol); | 72 | * return the amount of data in the tcp recv buffer. |
73 | * return 0 on failure. | ||
74 | */ | ||
75 | size_t net_socket_data_recv_buffer(Socket sock); | ||
75 | 76 | ||
76 | #define MAX_UDP_PACKET_SIZE 2048 | 77 | #define MAX_UDP_PACKET_SIZE 2048 |
77 | 78 | ||
@@ -326,13 +327,6 @@ uint16_t net_port(const Networking_Core *net); | |||
326 | */ | 327 | */ |
327 | int networking_at_startup(void); | 328 | int networking_at_startup(void); |
328 | 329 | ||
329 | /* Check if socket is valid. | ||
330 | * | ||
331 | * return 1 if valid | ||
332 | * return 0 if not valid | ||
333 | */ | ||
334 | int sock_valid(Socket sock); | ||
335 | |||
336 | /* Close the socket. | 330 | /* Close the socket. |
337 | */ | 331 | */ |
338 | void kill_sock(Socket sock); | 332 | void kill_sock(Socket sock); |