-
Notifications
You must be signed in to change notification settings - Fork 14
/
rocksockserver.h
52 lines (43 loc) · 1.36 KB
/
rocksockserver.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
/*
*
* author: rofl0r
*
* License: LGPL 2.1+ with static linking exception
*
*
*/
#ifndef _ROCKSOCKSERVER_H_
#define _ROCKSOCKSERVER_H_
#include <netdb.h>
#include <sys/socket.h>
#include <sys/select.h>
#if (! defined(USER_MAX_FD)) || (USER_MAX_FD > FD_SETSIZE)
#undef USER_MAX_FD
#define USER_MAX_FD FD_SETSIZE
#endif
typedef void (*perror_func)(const char*);
typedef struct {
fd_set master;
int listensocket;
int maxfd;
int numfds;
int signalfd;
void* userdata;
long sleeptime_us;
perror_func perr;
} rocksockserver;
void rocksockserver_set_sleeptime(rocksockserver* srv, long microsecs);
int rocksockserver_disconnect_client(rocksockserver* srv, int client);
int rocksockserver_init(rocksockserver* srv, const char* listenip, unsigned short port, void* userdata);
void rocksockserver_watch_fd(rocksockserver* srv, int newfd);
void rocksockserver_set_signalfd(rocksockserver* srv, int signalfd);
void rocksockserver_set_perrorfunc(rocksockserver* srv, perror_func perr);
int rocksockserver_loop(rocksockserver* srv,
char* buf, size_t bufsize,
int (*on_clientconnect) (void* userdata, struct sockaddr_storage* clientaddr, int fd),
int (*on_clientread) (void* userdata, int fd, size_t nread),
int (*on_clientwantsdata) (void* userdata, int fd),
int (*on_clientdisconnect) (void* userdata, int fd)
);
#pragma RcB2 DEP "rocksockserver*.c"
#endif