Skip to content
Snippets Groups Projects
Commit 4649f3a4 authored by sphere's avatar sphere
Browse files

Merge branch '1173-next-moved-upnp-to-it-s-own-thread' into 'next'

Resolve "[NEXT] moved UPnP to it's own thread"

Closes #1173

See merge request !2263
parents 225f0859 8073ac65
No related branches found
No related tags found
2 merge requests!2355fix newer versions of mixerx,!2263Resolve "[NEXT] moved UPnP to it's own thread"
Pipeline #2130 passed
...@@ -134,6 +134,7 @@ typedef union ...@@ -134,6 +134,7 @@ typedef union
#include "d_netfil.h" #include "d_netfil.h"
#include "i_tcp.h" #include "i_tcp.h"
#include "../m_argv.h" #include "../m_argv.h"
#include "../i_threads.h"
#include "../doomstat.h" #include "../doomstat.h"
...@@ -263,12 +264,33 @@ static const char* inet_ntopA(short af, const void *cp, char *buf, socklen_t len ...@@ -263,12 +264,33 @@ static const char* inet_ntopA(short af, const void *cp, char *buf, socklen_t len
#ifdef HAVE_MINIUPNPC // based on old XChat patch #ifdef HAVE_MINIUPNPC // based on old XChat patch
static void I_ShutdownUPnP(void); static void I_ShutdownUPnP(void);
static void I_InitUPnP(void);
I_mutex upnp_mutex;
static struct UPNPUrls urls; static struct UPNPUrls urls;
static struct IGDdatas data; static struct IGDdatas data;
static char lanaddr[64]; static char lanaddr[64];
struct upnpdata
{
int upnpc_started;
};
static struct upnpdata *upnpuser;
static void init_upnpc_once(struct upnpdata *upnpdata);
static void I_InitUPnP(void)
{
upnpuser = malloc(sizeof *upnpuser);
upnpuser->upnpc_started = 0;
I_spawn_thread("init_upnpc_once", (I_thread_fn)init_upnpc_once, upnpuser);
}
static inline void I_InitUPnP(void) static void
init_upnpc_once(struct upnpdata *upnpuserdata)
{ {
if (upnpuserdata->upnpc_started != 0)
return;
I_lock_mutex(&upnp_mutex);
const char * const deviceTypes[] = { const char * const deviceTypes[] = {
"urn:schemas-upnp-org:device:InternetGatewayDevice:2", "urn:schemas-upnp-org:device:InternetGatewayDevice:2",
"urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
...@@ -311,35 +333,43 @@ static inline void I_InitUPnP(void) ...@@ -311,35 +333,43 @@ static inline void I_InitUPnP(void)
I_AddExitFunc(I_ShutdownUPnP); I_AddExitFunc(I_ShutdownUPnP);
} }
freeUPNPDevlist(devlist); freeUPNPDevlist(devlist);
I_unlock_mutex(upnp_mutex);
} }
else if (upnp_error == UPNPDISCOVER_SOCKET_ERROR) else if (upnp_error == UPNPDISCOVER_SOCKET_ERROR)
{ {
CONS_Printf(M_GetText("No UPnP devices discovered\n")); CONS_Printf(M_GetText("No UPnP devices discovered\n"));
} }
upnpuserdata->upnpc_started =1;
} }
static inline void I_UPnP_add(const char * addr, const char *port, const char * servicetype) static inline void I_UPnP_add(const char * addr, const char *port, const char * servicetype)
{ {
I_lock_mutex(&upnp_mutex);
if (addr == NULL) if (addr == NULL)
addr = lanaddr; addr = lanaddr;
if (!urls.controlURL || urls.controlURL[0] == '\0') if (!urls.controlURL || urls.controlURL[0] == '\0')
return; return;
UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
port, port, addr, "SRB2", servicetype, NULL, NULL); port, port, addr, "SRB2", servicetype, NULL, NULL);
I_unlock_mutex(upnp_mutex);
} }
static inline void I_UPnP_rem(const char *port, const char * servicetype) static inline void I_UPnP_rem(const char *port, const char * servicetype)
{ {
I_lock_mutex(&upnp_mutex);
if (!urls.controlURL || urls.controlURL[0] == '\0') if (!urls.controlURL || urls.controlURL[0] == '\0')
return; return;
UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype,
port, servicetype, NULL); port, servicetype, NULL);
I_unlock_mutex(upnp_mutex);
} }
static void I_ShutdownUPnP(void) static void I_ShutdownUPnP(void)
{ {
I_UPnP_rem(serverport_name, "UDP"); I_UPnP_rem(serverport_name, "UDP");
I_lock_mutex(&upnp_mutex);
FreeUPNPUrls(&urls); FreeUPNPUrls(&urls);
I_unlock_mutex(upnp_mutex);
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment