-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnet.h
30 lines (20 loc) · 894 Bytes
/
net.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
#ifndef __NET_H
#define __NET_H
#include <sys/types.h>
#include <sys/socket.h>
struct tcp_socket_ops {
void *client; // by tcp_connect() or accepted by tcp_server().
void *server;
struct tcp_socket_ops *server_ops;
void (*notify_to_recv)(struct tcp_socket_ops *ops);
int (*process_event)(char *event_buf, int size, struct tcp_socket_ops *ops);
int (*disconnect)(struct tcp_socket_ops *ops);
int (*new_client)(struct tcp_socket_ops *ops);
};
void *tcp_server(const char *node, const char *service, struct tcp_socket_ops *ops);
int tcp_send(void *client, const void *buf, size_t len, int flags);
int tcp_recv(void *client, void *buf, size_t len, int flags);
int tcp_server_broadcast(void *server, const void *buf, size_t len, int flags);
void *tcp_connect(const char *node, const char *service, struct tcp_socket_ops *ops);
void tcp_close(void *tcp);
#endif