summaryrefslogtreecommitdiff
path: root/toxcore/network.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-27 02:07:59 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-05-20 15:42:42 +0000
commitbe797d4b039b40d2c876f0a71cd1e48454a74065 (patch)
treec759c0f15a3ac0285e0bd941dc3edad06ade015d /toxcore/network.h
parent291a849a5a0afb4450bcd0d0c50b7aeccaac04f5 (diff)
Move system header includes from network.h to network.c
Diffstat (limited to 'toxcore/network.h')
-rw-r--r--toxcore/network.h84
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 34extern "C" {
51// mingw32 headers happy, we include winsock2.h first. 35#endif
52#include <winsock2.h>
53 36
54#include <windows.h> 37typedef uint8_t Family;
55#include <ws2tcpip.h>
56 38
57#else // UNIX includes 39typedef struct Socket {
40 int socket;
41} Socket;
58 42
59#include <sys/socket.h> 43Socket 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 */
50int sock_valid(Socket sock);
66 51
67#ifdef __cplusplus 52extern const Socket net_invalid_socket;
68extern "C" {
69#endif
70 53
71typedef short Family; 54/**
55 * Calls send(sockfd, buf, len, MSG_NOSIGNAL).
56 */
57int net_send(Socket sockfd, const void *buf, size_t len);
58/**
59 * Calls recv(sockfd, buf, len, MSG_NOSIGNAL).
60 */
61int net_recv(Socket sockfd, void *buf, size_t len);
62/**
63 * Calls listen(sockfd, backlog).
64 */
65int net_listen(Socket sockfd, int backlog);
66/**
67 * Calls accept(sockfd, nullptr, nullptr).
68 */
69Socket net_accept(Socket sockfd);
72 70
73typedef int Socket; 71/**
74Socket 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 */
75size_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 */
327int networking_at_startup(void); 328int 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 */
334int sock_valid(Socket sock);
335
336/* Close the socket. 330/* Close the socket.
337 */ 331 */
338void kill_sock(Socket sock); 332void kill_sock(Socket sock);