Commit 017f7a2f authored by Edric Milaret's avatar Edric Milaret Committed by Guillaume Roguez

windows: add upnp support

Refs #71910

Change-Id: Iab724e6c9b9f6e412623a125a5bb076d3c78a57e
parent a0d2e366
......@@ -73,6 +73,9 @@ case "${host_os}" in
AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [XPG things and X/Open Unix extensions.])
AC_DEFINE([_BSD_SOURCE], [1], [ISO C, POSIX, and 4.3BSD things.])
AC_DEFINE([_SVID_SOURCE], [1], [ISO C, POSIX, and SVID things.])
AC_DEFINE([WIN32_LEAN_AND_MEAN],, [Define to limit the scope of <windows.h>.])
CPPFLAGS+="-D_WIN32_WINNT=0x0601 -DWINVER=0x0601"
LDFLAGS+="-no-undefined -avoid-version -Wl,--nxcompat -Wl,--dynamicbase"
ac_default_prefix="`pwd`/_win32"
......
--- libupnp/configure.ac.orig 2011-02-09 00:55:44.000000000 +0100
+++ libupnp/configure.ac 2011-02-10 23:39:44.154929678 +0100
@@ -397,7 +397,6 @@
AC_PROG_MAKE_SET
AC_PROG_EGREP
-#
# Default compilation flags
#
echo "--------------------- Default compilation flags -------------------------------"
@@ -531,39 +530,46 @@
# Checks for POSIX Threads
#
echo "--------------------------- pthread stuff -------------------------------------"
-ACX_PTHREAD(
- [],
- [AC_MSG_ERROR([POSIX threads are required to build this program])])
+#ACX_PTHREAD(
+# [],
+# [AC_MSG_ERROR([POSIX threads are required to build this program])])
#
+PTHREAD_LIBS=" -lpthreadGC2 -lws2_32"
+PTHREAD_CFLAGS=" -DPTW32_STATIC_LIB -DUPNP_STATIC_LIB"
# Update environment variables for pthreads
#
-CC="$PTHREAD_CC"
+#CC="$PTHREAD_CC"
CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
+
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(PTHREAD_CFLAGS)
+AC_SUBST(PTHREAD_CC)
+
#
# Determine if pthread_rwlock_t is available
#
-echo "----------------------- pthread_rwlock_t stuff --------------------------------"
-AC_MSG_CHECKING([if pthread_rwlock_t is available])
-AC_LANG([C])
-AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [#include <pthread.h>],
- [pthread_rwlock_t *x;])],
- [AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
- AC_MSG_RESULT([yes, supported without any options])],
- [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [#define _GNU_SOURCE
- #include <pthread.h>],
- [pthread_rwlock_t *x;])],
- [AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
- CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
- AC_MSG_RESULT([yes, definition of _GNU_SOURCE required])],
- [AC_DEFINE([UPNP_USE_RWLOCK], [0], [Do not use pthread_rwlock_t])
- AC_MSG_RESULT([no, needs to fallback to pthread_mutex])
- AC_MSG_ERROR([pthread_rwlock_t not available])])])
-echo "-------------------------------------------------------------------------------"
+#echo "----------------------- pthread_rwlock_t stuff --------------------------------"
+#AC_MSG_CHECKING([if pthread_rwlock_t is available])
+#AC_LANG([C])
+#AC_COMPILE_IFELSE(
+# [AC_LANG_PROGRAM(
+# [#include <pthread.h>],
+# [pthread_rwlock_t *x;])],
+# [AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
+# AC_MSG_RESULT([yes, supported without any options])],
+# [AC_COMPILE_IFELSE(
+# [AC_LANG_PROGRAM(
+# [#define _GNU_SOURCE
+# #include <pthread.h>],
+# [pthread_rwlock_t *x;])],
+# [AC_DEFINE([UPNP_USE_RWLOCK], [1], [Use pthread_rwlock_t])
+# CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+# AC_MSG_RESULT([yes, definition of _GNU_SOURCE required])],
+# [AC_DEFINE([UPNP_USE_RWLOCK], [0], [Do not use pthread_rwlock_t])
+# AC_MSG_RESULT([no, needs to fallback to pthread_mutex])
+# AC_MSG_ERROR([pthread_rwlock_t not available])])])
+#echo "-------------------------------------------------------------------------------"
AC_CONFIG_FILES([
......@@ -12,17 +12,12 @@ $(TARBALLS)/libupnp-$(UPNP_VERSION).tar.bz2:
.sum-upnp: libupnp-$(UPNP_VERSION).tar.bz2
ifdef HAVE_WIN32
DEPS_upnp += pthreads $(DEPS_pthreads)
LIBUPNP_ECFLAGS = -DPTW32_STATIC_LIB
endif
upnp: libupnp-$(UPNP_VERSION).tar.bz2 .sum-upnp
$(UNPACK)
ifdef HAVE_WIN32
$(APPLY) $(SRC)/upnp/libupnp-configure.patch
$(APPLY) $(SRC)/upnp/libupnp-win32.patch
$(APPLY) $(SRC)/upnp/libupnp-win64.patch
$(APPLY) $(SRC)/upnp/threadpool.patch
endif
$(APPLY) $(SRC)/upnp/libupnp-ipv6.patch
$(APPLY) $(SRC)/upnp/miniserver.patch
......@@ -33,7 +28,9 @@ endif
.upnp: upnp
ifdef HAVE_WIN32
$(RECONF)
cd $< && $(HOSTVARS) CFLAGS="-DUPNP_STATIC_LIB" ./configure --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
else
cd $< && $(HOSTVARS) CFLAGS="$(CFLAGS) -DUPNP_STATIC_LIB" ./configure --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
endif
cd $< && $(HOSTVARS) CFLAGS="$(CFLAGS) -DUPNP_STATIC_LIB $(LIBUPNP_ECFLAGS)" ./configure --disable-samples --without-documentation --disable-blocking_tcp_connections $(HOSTCONF)
cd $< && $(MAKE) install
touch $@
--- a/threadutil/src/ThreadPool.c 2012-04-03 09:01:15.000000000 -0400
+++ b/threadutil/src/ThreadPool.c 2015-05-07 14:37:13.168494069 -0400
@@ -264,7 +264,7 @@
setpriority(PRIO_PROCESS, 0, 0);
retVal = 0;
#elif defined(WIN32)
- retVal = sched_setscheduler(0, in);
+ retVal = 0;
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
struct sched_param current;
int sched_result;
@@ -416,7 +416,7 @@
gettimeofday(&t, NULL);
#if defined(WIN32)
- srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
+ srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
@@ -654,7 +654,7 @@
rc = ithread_detach(temp);
/* ithread_detach will return EINVAL if thread has been
successfully detached by ithread_create */
- if (rc == EINVAL)
+ if (rc == EINVAL || rc == ESRCH)
rc = 0;
tp->pendingWorkerThreadStart = 1;
/* wait until the new worker thread starts */
......@@ -93,7 +93,6 @@ libring_la_CFLAGS = \
@SAMPLERATE_CFLAGS@ \
@LIBUPNP_CFLAGS@ \
@SPEEXDSP_CFLAGS@ \
@LIBUPNP_CFLAGS@ \
@PORTAUDIO_CFLAGS@ \
$(TLS_CFLAGS)
......
......@@ -30,6 +30,9 @@
*/
#include "ip_utils.h"
#ifdef s_addr
#undef s_addr
#endif
#include "logger.h"
#include "sip/sip_utils.h"
......
......@@ -34,18 +34,17 @@
#include <pjlib.h>
#ifdef HAVE_CONFIG
#include <config.h>
#endif
#ifdef _WIN32
#include <ws2tcpip.h>
#include <config.h>
#include <winsock2.h>
//define in mingw
#ifdef interface
#undef interface
#endif
#ifdef s_addr
#undef s_addr
#endif
#else
#include <arpa/inet.h>
#include <netinet/in.h>
......
......@@ -178,8 +178,10 @@ UPnPContext::~UPnPContext()
if (deviceRegistered_)
UpnpUnRegisterRootDevice( deviceHandle_ );
// FIXME : on windows thread have already been destroyed at this point resulting in a deadlock
#ifndef _WIN32
UpnpFinish();
#endif
}
void
......@@ -283,7 +285,11 @@ static uint16_t
generateRandomPort()
{
/* obtain a random number from hardware */
#ifndef _WIN32
static std::random_device rd;
#else
static std::default_random_engine rd(std::chrono::system_clock::now().time_since_epoch().count());
#endif
/* seed the generator */
static std::mt19937 gen(rd());
/* define the range */
......
......@@ -44,6 +44,11 @@
#include <atomic>
#if HAVE_LIBUPNP
#ifdef _WIN32
#define UPNP_STATIC_LIB
#include <windows.h>
#include <wincrypt.h>
#endif
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment