projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mingw: fix static linking with recent ncurses
[tinc]
/
src
/
event.c
diff --git
a/src/event.c
b/src/event.c
index
c547c46
..
2710a8b
100644
(file)
--- a/
src/event.c
+++ b/
src/event.c
@@
-1,6
+1,6
@@
/*
event.c -- I/O, timeout and signal event handling
/*
event.c -- I/O, timeout and signal event handling
- Copyright (C) 2012-202
1
Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2012-202
2
Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-18,7
+18,8
@@
*/
#include "system.h"
*/
#include "system.h"
-#include "dropin.h"
+
+#include <assert.h>
#ifdef HAVE_SYS_EPOLL_H
#include <sys/epoll.h>
#ifdef HAVE_SYS_EPOLL_H
#include <sys/epoll.h>
@@
-29,7
+30,7
@@
#include "net.h"
struct timeval now;
#include "net.h"
struct timeval now;
-#ifndef HAVE_
MINGW
+#ifndef HAVE_
WINDOWS
#ifdef HAVE_SYS_EPOLL_H
static int epollset = 0;
#ifdef HAVE_SYS_EPOLL_H
static int epollset = 0;
@@
-46,7
+47,7
@@
static DWORD event_count = 0;
static bool running;
#ifdef HAVE_SYS_EPOLL_H
static bool running;
#ifdef HAVE_SYS_EPOLL_H
-static inline int event_epoll_init() {
+static inline int event_epoll_init(
void
) {
/* NOTE: 1024 limit is only used on ancient (pre 2.6.27) kernels.
Decent kernels will ignore this value making it unlimited.
epoll_create1 might be better, but these kernels would not be supported
/* NOTE: 1024 limit is only used on ancient (pre 2.6.27) kernels.
Decent kernels will ignore this value making it unlimited.
epoll_create1 might be better, but these kernels would not be supported
@@
-57,7
+58,7
@@
static inline int event_epoll_init() {
#endif
static int io_compare(const io_t *a, const io_t *b) {
#endif
static int io_compare(const io_t *a, const io_t *b) {
-#ifndef HAVE_
MINGW
+#ifndef HAVE_
WINDOWS
return a->fd - b->fd;
#else
return a->fd - b->fd;
#else
@@
-113,7
+114,7
@@
void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags) {
}
io->fd = fd;
}
io->fd = fd;
-#ifdef HAVE_
MINGW
+#ifdef HAVE_
WINDOWS
if(io->fd != -1) {
io->event = WSACreateEvent();
if(io->fd != -1) {
io->event = WSACreateEvent();
@@
-140,7
+141,7
@@
void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags) {
#endif
}
#endif
}
-#ifdef HAVE_
MINGW
+#ifdef HAVE_
WINDOWS
void io_add_event(io_t *io, io_cb_t cb, void *data, WSAEVENT event) {
io->event = event;
io_add(io, cb, data, -1, 0);
void io_add_event(io_t *io, io_cb_t cb, void *data, WSAEVENT event) {
io->event = event;
io_add(io, cb, data, -1, 0);
@@
-166,7
+167,7
@@
void io_set(io_t *io, int flags) {
return;
}
return;
}
-#ifndef HAVE_
MINGW
+#ifndef HAVE_
WINDOWS
#ifdef HAVE_SYS_EPOLL_H
epoll_ctl(epollset, EPOLL_CTL_DEL, io->fd, NULL);
#ifdef HAVE_SYS_EPOLL_H
epoll_ctl(epollset, EPOLL_CTL_DEL, io->fd, NULL);
@@
-229,7
+230,7
@@
void io_del(io_t *io) {
}
io_set(io, 0);
}
io_set(io, 0);
-#ifdef HAVE_
MINGW
+#ifdef HAVE_
WINDOWS
if(io->fd != -1 && WSACloseEvent(io->event) == FALSE) {
abort();
if(io->fd != -1 && WSACloseEvent(io->event) == FALSE) {
abort();
@@
-280,7
+281,7
@@
void timeout_del(timeout_t *timeout) {
};
}
};
}
-#ifndef HAVE_
MINGW
+#ifndef HAVE_
WINDOWS
// From Matz's Ruby
#ifndef NSIG
// From Matz's Ruby
#ifndef NSIG
@@
-290,11
+291,14
@@
void timeout_del(timeout_t *timeout) {
static io_t signalio;
static int pipefd[2] = {-1, -1};
static io_t signalio;
static int pipefd[2] = {-1, -1};
-static signal_t *signal_handle[NSIG + 1] = {};
+static signal_t *signal_handle[NSIG + 1] = {
NULL
};
static void signal_handler(int signum) {
unsigned char num = signum;
static void signal_handler(int signum) {
unsigned char num = signum;
- write(pipefd[1], &num, 1);
+
+ if(write(pipefd[1], &num, 1) != 1) {
+ // Pipe full or broken, nothing we can do about it.
+ }
}
static void signalio_handler(void *data, int flags) {
}
static void signalio_handler(void *data, int flags) {
@@
-375,7
+379,7
@@
static struct timeval *timeout_execute(struct timeval *diff) {
bool event_loop(void) {
running = true;
bool event_loop(void) {
running = true;
-#ifndef HAVE_
MINGW
+#ifndef HAVE_
WINDOWS
#ifdef HAVE_SYS_EPOLL_H
#ifdef HAVE_SYS_EPOLL_H
@@
-480,6
+484,7
@@
bool event_loop(void) {
}
#else
}
#else
+ assert(WSA_WAIT_EVENT_0 == 0);
while(running) {
struct timeval diff;
while(running) {
struct timeval diff;
@@
-541,12
+546,12
@@
bool event_loop(void) {
break;
}
break;
}
- if(result
< WSA_WAIT_EVENT_0 || result >= WSA_WAIT_EVENT_0 +
event_count - event_offset) {
+ if(result
>=
event_count - event_offset) {
return false;
}
/* Look up io in the map by index. */
return false;
}
/* Look up io in the map by index. */
- event_index = result
- WSA_WAIT_EVENT_0
+ event_offset;
+ event_index = result + event_offset;
io_t *io = io_map[event_index];
if(io->fd == -1) {
io_t *io = io_map[event_index];
if(io->fd == -1) {