X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet.c;h=0b617bd08ac3bffaf420c570eb56de7563607f26;hb=5dde6461a321ee47b06e33f8203f2acf00a31a51;hp=c893f1e41c07c5027eda0b9c2cfca33932007fd0;hpb=f80bf14f28925df6eaa56f3ed77adaf418ab9890;p=tinc diff --git a/src/net.c b/src/net.c index c893f1e4..0b617bd0 100644 --- a/src/net.c +++ b/src/net.c @@ -13,11 +13,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "system.h" @@ -48,8 +46,7 @@ time_t now = 0; /* Purge edges and subnets of unreachable nodes. Use carefully. */ -static void purge(void) -{ +static void purge(void) { avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; node_t *n; edge_t *e; @@ -112,8 +109,7 @@ static void purge(void) put all file descriptors in an fd_set array While we're at it, purge stuff that needs to be removed. */ -static int build_fdset(fd_set *readset, fd_set *writeset) -{ +static int build_fdset(fd_set *readset, fd_set *writeset) { avl_node_t *node, *next; connection_t *c; int i, max = 0; @@ -149,7 +145,8 @@ static int build_fdset(fd_set *readset, fd_set *writeset) max = listen_socket[i].udp; } - FD_SET(device_fd, readset); + if(device_fd >= 0) + FD_SET(device_fd, readset); if(device_fd > max) max = device_fd; @@ -163,8 +160,7 @@ static int build_fdset(fd_set *readset, fd_set *writeset) - Check if we need to retry making an outgoing connection - Deactivate the host */ -void terminate_connection(connection_t *c, bool report) -{ +void terminate_connection(connection_t *c, bool report) { cp(); if(c->status.remove) @@ -227,8 +223,7 @@ void terminate_connection(connection_t *c, bool report) end does not reply in time, we consider them dead and close the connection. */ -static void check_dead_connections(void) -{ +static void check_dead_connections(void) { avl_node_t *node, *next; connection_t *c; @@ -283,8 +278,7 @@ static void check_dead_connections(void) check all connections to see if anything happened on their sockets */ -static void check_network_activity(fd_set * readset, fd_set * writeset) -{ +static void check_network_activity(fd_set * readset, fd_set * writeset) { connection_t *c; avl_node_t *node; int result, i; @@ -294,7 +288,7 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) cp(); /* check input from kernel */ - if(FD_ISSET(device_fd, readset)) { + if(device_fd >= 0 && FD_ISSET(device_fd, readset)) { if(read_packet(&packet)) { packet.priority = 0; route(myself, &packet); @@ -351,8 +345,7 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) /* this is where it all happens... */ -int main_loop(void) -{ +int main_loop(void) { fd_set readset, writeset; struct timeval tv; int r, maxfd; @@ -378,7 +371,13 @@ int main_loop(void) maxfd = build_fdset(&readset, &writeset); +#ifdef HAVE_MINGW + LeaveCriticalSection(&mutex); +#endif r = select(maxfd + 1, &readset, &writeset, NULL, &tv); +#ifdef HAVE_MINGW + EnterCriticalSection(&mutex); +#endif if(r < 0) { if(errno != EINTR && errno != EAGAIN) {