-
Notifications
You must be signed in to change notification settings - Fork 1
/
_net_socket.h
57 lines (45 loc) · 1.04 KB
/
_net_socket.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
#ifndef SOCKET_H
#define SOCKET_H
#include <netinet/in.h>
struct socket {
int id;
int type;
int fd;
int buf_len;
char *buf;
};
struct event {
struct socket *s;
int is_write;
int is_read;
};
#define SOCKET_MSG_ACCEPT 1
#define SOCKET_MSG_CONNECT 2
#define SOCKET_MSG_DATA 3
#define SOCKET_MSG_CLOSE 4
struct socket_msg_accept {
int id;
struct sockaddr_in addr;
};
struct socket_msg_connect {
int id;
struct sockaddr_in addr;
};
struct socket_msg_close {
int id;
};
struct socket_msg_data {
int id;
int buf_len;
char *buf;
};
struct socket_server;
typedef struct socket_server socket_server;
typedef void (*msg_func)(int type, void*msg, int msg_len);
socket_server *socket_server_create(msg_func f);
void socket_server_poll(socket_server* ss);
void listen_socket(socket_server *ss, int port);
void connect_socket(socket_server *ss, char *ip, int ip_len, int port);
void write_socket(socket_server *ss, int id, char *msg, int msg_len);
void close_socket(socket_server *ss, int id);
#endif