-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockets.h
58 lines (42 loc) · 1.49 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
#ifndef COOLSTUFF
#define COOLSTUFF
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <stdint.h>
#include <unistd.h>
#define BUFFSIZE 1024
#define BOTH SO_REUSEADDR | SO_REUSEPORT
#define READDR SO_REUSEADDR
#define RERORT SO_REUSEPORT
typedef struct socklen_t SOCK_T;
struct server{
int serverfd;
struct sockaddr_in address;
unsigned int address_length;
int operation;
int operation_length;
int (*create)(struct server *self, int domain, int type, int protocal);
int (*set)(struct server *self, int level, int opration_name, int operation_val,
int family, uint32_t add, int port);
int (*bin)(struct server *self);
int (*lis)(struct server *self, int max_lis);
int (*acc)(struct server *self);
int (*r)(struct server *self, int fd, char *string, int nbytes);
int (*s)(struct server *self, int fd, char *string, int nbytes, int flags);
};
struct client{
int fd;
struct sockaddr_in server_address;
unsigned int server_address_length;
int (*create)(struct client *self, int domain, int type, int protocal);
int (*connect)(struct client *self, int family, int port, char address[BUFFSIZE]);
int (*r)(struct client *self, int fd, char *string, int nbytes);
int (*s)(struct client *self, int fd, char *string, int nbytes, int flags);
};
typedef struct server SERVER;
typedef struct client CLIENT;
int __server_init__(SERVER *self);
int __client_init__(CLIENT *self);
#endif