-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackethandler.h
58 lines (47 loc) · 1.26 KB
/
packethandler.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
/*
* packethandler.h
*
* Created on: 17 Sep 2017
* Author: Bibl
*/
#ifndef PACKETHANDLER_H_
#define PACKETHANDLER_H_
#include <winsock2.h>
//#include "packetqueue.h"
#define DATA_BUF_LEN 1024 * 8
struct connection {
int idx;
SOCKET socket;
char __write_buf[DATA_BUF_LEN], __read_buf[DATA_BUF_LEN];
WSABUF write_buf, read_buf;
// struct packet_queue send_queue, recv_queue;
};
struct packet_factory {
void (*parse_packet)(struct connection *conn);
};
#define MAX_CLIENTS FD_SETSIZE-1
struct server_config {
WSADATA wsadata;
SOCKADDR_IN addr;
struct packet_factory packet_factory;
void (*exit_callback)(void);
/* server controlled variables,
* is_live indicates whether the
* server is currently running.
*
* is_error indicates that the
* handler exited because of an
* error. if it is set, error_msg
* contains a description of the
* error.
*/
int is_live;
int is_error;
char *error_msg;
};
int is_live_connection(struct connection *conn);
void dissolve_connection(struct connection **connptr);
struct connection *create_connection(struct connection *connections[], SOCKET *accept_socket);
// thread entry method
void *handler_start(void *arg);
#endif /* PACKETHANDLER_H_ */