-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockets.h
89 lines (72 loc) · 1.83 KB
/
sockets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "config.h"
#include "log.h"
#include "request.h"
#include "stats.h"
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define ISVALIDSOCKET(s) (s >= 0)
#define CLOSESOCKET(s) close(s)
#define SOCKET int
#define GETSOCKETERRNO (errno)
bool LOG_RECV;
bool LOG_SEND;
extern bool LOG_RECV;
extern bool LOG_SEND;
int connection_count;
int shield(int val);
SOCKET create_socket(const char* host, const char* port);
#define MAX_REQUEST_SIZE 2047
typedef struct Progress {
char* filename;
size_t size;
int busy;
} Progress;
struct client_info {
socklen_t address_length;
struct sockaddr_storage address;
SOCKET socket;
int received;
struct client_info* next;
char sendFilePath[1000];
char name[32];
Request* request;
Progress* progress;
char* buffer;
bool hasRequest;
long bytesSent;
long bytesReceived;
size_t bodyReceived;
int readCount;
int writeCount;
int reading;
int writing;
};
typedef struct client_info Client;
typedef struct select_result {
fd_set readers;
fd_set writers;
fd_set errors;
} select_result;
struct select_result* wait_on_clients(SOCKET server);
Client* clients;
int receive(Client* client, char* buff, size_t buffSize);
int sendAll(Client* client, char* data);
int sendAllN(Client* client, char* data, size_t toSend);
void resetProgress(Progress* progress);
void resetClient(Client* client);
Client* get_client(SOCKET s);
const char* get_client_address(struct client_info* ci);
Client* accept_client(SOCKET socket);
void drop_client(struct client_info* client);
fd_set wait_on_writables(SOCKET server);
char* recv_until(int fd, char* needle);