add rocksock_strerror_detailed()
[rofl0r-rocksock.git] / rocksockserver.h
blob5bd59bb152d54f94e084dddca0c9b5f6e190b679
1 /*
2 *
3 * author: rofl0r
4 *
5 * License: LGPL 2.1+ with static linking exception
6 *
7 *
8 */
11 #ifndef _ROCKSOCKSERVER_H_
12 #define _ROCKSOCKSERVER_H_
14 #include <netdb.h>
15 #include <sys/socket.h>
16 #include <sys/select.h>
18 #if (! defined(USER_MAX_FD)) || (USER_MAX_FD > FD_SETSIZE)
19 #undef USER_MAX_FD
20 #define USER_MAX_FD FD_SETSIZE
21 #endif
23 typedef void (*perror_func)(const char*);
24 typedef struct {
25 fd_set master;
26 int listensocket;
27 int maxfd;
28 int numfds;
29 int signalfd;
30 void* userdata;
31 long sleeptime_us;
32 perror_func perr;
33 } rocksockserver;
35 void rocksockserver_set_sleeptime(rocksockserver* srv, long microsecs);
36 int rocksockserver_disconnect_client(rocksockserver* srv, int client);
37 int rocksockserver_init(rocksockserver* srv, const char* listenip, unsigned short port, void* userdata);
38 void rocksockserver_watch_fd(rocksockserver* srv, int newfd);
39 void rocksockserver_set_signalfd(rocksockserver* srv, int signalfd);
40 void rocksockserver_set_perrorfunc(rocksockserver* srv, perror_func perr);
41 int rocksockserver_loop(rocksockserver* srv,
42 char* buf, size_t bufsize,
43 int (*on_clientconnect) (void* userdata, struct sockaddr_storage* clientaddr, int fd),
44 int (*on_clientread) (void* userdata, int fd, size_t nread),
45 int (*on_clientwantsdata) (void* userdata, int fd),
46 int (*on_clientdisconnect) (void* userdata, int fd)
49 #endif
51 //RcB: DEP "rocksockserver*.c"