return 0;
}
-int event_register(void *data)
+event_t event_register(void *data)
{
int fds[2];
if (pipe(fds) != 0) {
UNIXERR("pipe");
- return -1;
+ return INVALID_EVENT;
}
if (setnonblock(fds[0]) != 0) {
close(fds[0]);
close(fds[1]);
- return -1;
+ return INVALID_EVENT;
}
server_t *tmp = server_acquire();
return tmp->fd2;
}
-bool event_fire(int event)
+bool event_fire(event_t event)
{
static const char *data = "";
return write(event, data, 1) == 0;
static bool event_cancel(int event)
{
- static char buff[1];
+ char buff[32];
while (true) {
- ssize_t res = read(event, buff, 64);
+ ssize_t res = read(event, buff, 32);
if (res == -1 && errno != EAGAIN && errno != EINTR) {
UNIXERR("read");
return false;
} else if (res == -1 && errno == EINTR) {
continue;
- } else if (res != 1) {
+ } else if (res != 32) {
return true;
}
}
#include "buffer.h"
typedef struct server_t server_t;
+typedef int event_t;
+
+#define INVALID_EVENT (-1)
typedef void *(*start_listener_t)(void);
typedef void (*delete_client_t)(void*);
int start_server(int port, start_listener_t starter, delete_client_t deleter);
-int event_register(void *data);
-bool event_fire(int event);
+event_t event_register(void *data);
+bool event_fire(event_t event);
int server_loop(start_client_t starter, delete_client_t deleter,
run_client_t runner, event_handler_t handler,