-
Notifications
You must be signed in to change notification settings - Fork 1
/
net_socket.h
43 lines (33 loc) · 901 Bytes
/
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
#ifndef SOCKET_H
#define SOCKET_H
#include <netinet/in.h>
#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