X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fupnp.c;h=93c207fa34db0b00f7dd18ed73420e53ae800e93;hb=04d8a8e34e1fe7f33f1946863b36a24ee358175f;hp=5e41d1b653996d16dbf0e81016341fa17a2e95ab;hpb=1c475ecb575367a6b3f9328b0f643ad636155341;p=tinc diff --git a/src/upnp.c b/src/upnp.c index 5e41d1b6..93c207fa 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -1,6 +1,6 @@ /* upnp.c -- UPnP-IGD client - Copyright (C) 2015 Guus Sliepen , + Copyright (C) 2015-2018 Guus Sliepen , 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 @@ -19,7 +19,9 @@ #include "upnp.h" +#ifndef HAVE_MINGW #include +#endif #include "miniupnpc/miniupnpc.h" #include "miniupnpc/upnpcommands.h" @@ -159,7 +161,9 @@ static void *upnp_thread(void *data) { time_t now = time(NULL); if(now < refresh_time) { - sleep(refresh_time - now); + nanosleep(&(struct timespec) { + refresh_time - now, 0 + }, NULL); } } @@ -173,13 +177,23 @@ void upnp_init(bool tcp, bool udp) { upnp_tcp = tcp; upnp_udp = udp; - get_config_int(lookup_config(config_tree, "UPnPDiscoverWait"), &upnp_discover_wait); - get_config_int(lookup_config(config_tree, "UPnPRefreshPeriod"), &upnp_refresh_period); + get_config_int(lookup_config(&config_tree, "UPnPDiscoverWait"), &upnp_discover_wait); + get_config_int(lookup_config(&config_tree, "UPnPRefreshPeriod"), &upnp_refresh_period); + +#ifdef HAVE_MINGW + HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)upnp_thread, NULL, 0, NULL); + + if(!handle) { + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread"); + } +#else pthread_t thread; int error = pthread_create(&thread, NULL, upnp_thread, NULL); if(error) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread: [%d] %s", error, strerror(error)); } + +#endif }