From f9ab8e266b93aa3be772374ef4a8fdb06e376568 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 1 Mar 2013 17:15:26 +0100 Subject: [PATCH] Flush output buffers in the tap reader thread on Windows. This is basically a port of commit 50fcfea1 to 1.1. --- src/event.c | 6 ++++++ src/event.h | 1 + src/mingw/device.c | 1 + src/net_socket.c | 3 +++ 4 files changed, 11 insertions(+) diff --git a/src/event.c b/src/event.c index 6b730f6d..095e7c33 100644 --- a/src/event.c +++ b/src/event.c @@ -245,6 +245,12 @@ bool event_loop(void) { return true; } +void event_flush_output(void) { + for splay_each(io_t, io, &io_tree) + if(FD_ISSET(io->fd, &writefds)) + io->cb(io->data, IO_WRITE); +} + void event_exit(void) { running = false; } diff --git a/src/event.h b/src/event.h index d0129d0c..bd91b7b9 100644 --- a/src/event.h +++ b/src/event.h @@ -65,6 +65,7 @@ extern void signal_add(signal_t *sig, signal_cb_t cb, void *data, int signum); extern void signal_del(signal_t *sig); extern bool event_loop(void); +extern void event_flush_output(void); extern void event_exit(void); #endif diff --git a/src/mingw/device.c b/src/mingw/device.c index aa059720..ac83d8c3 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -80,6 +80,7 @@ static DWORD WINAPI tapreader(void *bla) { packet.len = len; packet.priority = 0; route(myself, &packet); + event_flush_output(); LeaveCriticalSection(&mutex); } } diff --git a/src/net_socket.c b/src/net_socket.c index a28be54a..0ee36553 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -349,6 +349,9 @@ static void do_outgoing_pipe(connection_t *c, char *command) { } static void handle_meta_write(connection_t *c) { + if(c->outbuf.len <= c->outbuf.offset) + return; + ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, 0); if(outlen <= 0) { if(!errno || errno == EPIPE) {