miniupnpd: add sendto() queuing

This commit is contained in:
Thomas Bernard 2014-02-25 11:10:05 +01:00
parent 1985cbf3ef
commit cbc1a3c96a
4 changed files with 40 additions and 3 deletions

View File

@ -80,7 +80,7 @@ STDOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \ upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \ options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \
upnpevents.o upnputils.o getconnstatus.o \ upnpevents.o upnputils.o getconnstatus.o \
upnppinhole.o upnppinhole.o asyncsendto.o
BSDOBJS = bsd/getifstats.o bsd/ifacewatcher.o bsd/getroute.o BSDOBJS = bsd/getifstats.o bsd/ifacewatcher.o bsd/getroute.o
SUNOSOBJS = solaris/getifstats.o bsd/ifacewatcher.o bsd/getroute.o SUNOSOBJS = solaris/getifstats.o bsd/ifacewatcher.o bsd/getroute.o
MACOBJS = mac/getifstats.o bsd/ifacewatcher.o bsd/getroute.o MACOBJS = mac/getifstats.o bsd/ifacewatcher.o bsd/getroute.o

View File

@ -47,7 +47,7 @@ BASEOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \ upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \ options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \
upnpevents.o upnputils.o getconnstatus.o \ upnpevents.o upnputils.o getconnstatus.o \
upnppinhole.o pcplearndscp.o upnppinhole.o pcplearndscp.o asyncsendto.o
LNXOBJS = linux/getifstats.o linux/ifacewatcher.o linux/getroute.o LNXOBJS = linux/getifstats.o linux/ifacewatcher.o linux/getroute.o
NETFILTEROBJS = netfilter/iptcrdr.o netfilter/iptpinhole.o netfilter/nfct_get.o NETFILTEROBJS = netfilter/iptcrdr.o netfilter/iptpinhole.o netfilter/nfct_get.o

View File

@ -32,7 +32,8 @@ FWNAME = $(shell [ `uname -r | cut -d. -f1` -ge 11 ] && echo "pf" || echo "ipfw
STD_OBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \ STD_OBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \ upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
options.o upnppermissions.o minissdp.o natpmp.o \ options.o upnppermissions.o minissdp.o natpmp.o \
upnpevents.o getconnstatus.o upnputils.o upnpevents.o getconnstatus.o upnputils.o \
asyncsendto.o
MAC_OBJS = mac/getifstats.o bsd/ifacewatcher.o MAC_OBJS = mac/getifstats.o bsd/ifacewatcher.o
IPFW_OBJS = ipfw/ipfwrdr.o ipfw/ipfwaux.o IPFW_OBJS = ipfw/ipfwrdr.o ipfw/ipfwaux.o
PF_OBJS = pf/obsdrdr.o pf/pfpinhole.o PF_OBJS = pf/obsdrdr.o pf/pfpinhole.o

View File

@ -63,6 +63,7 @@
#include "miniupnpdtypes.h" #include "miniupnpdtypes.h"
#include "daemonize.h" #include "daemonize.h"
#include "upnpevents.h" #include "upnpevents.h"
#include "asyncsendto.h"
#ifdef ENABLE_NATPMP #ifdef ENABLE_NATPMP
#include "natpmp.h" #include "natpmp.h"
#ifdef ENABLE_PCP #ifdef ENABLE_PCP
@ -1756,6 +1757,38 @@ main(int argc, char * * argv)
upnpevents_selectfds(&readset, &writeset, &max_fd); upnpevents_selectfds(&readset, &writeset, &max_fd);
#endif #endif
/* queued "sendto" */
{
struct timeval next_send;
i = get_next_scheduled_send(&next_send);
if(i > 0) {
#ifdef DEBUG
syslog(LOG_DEBUG, "%d queued sendto", i);
#endif
i = get_sendto_fds(&writeset, &max_fd, &timeofday);
if(timeofday.tv_sec > next_send.tv_sec ||
(timeofday.tv_sec == next_send.tv_sec && timeofday.tv_usec >= next_send.tv_usec)) {
if(i > 0) {
timeout.tv_sec = 0;
timeout.tv_usec = 0;
}
} else {
struct timeval tmp_timeout;
tmp_timeout.tv_sec = (next_send.tv_sec - timeofday.tv_sec);
tmp_timeout.tv_usec = (next_send.tv_usec - timeofday.tv_usec);
if(tmp_timeout.tv_usec < 0) {
tmp_timeout.tv_usec += 1000000;
tmp_timeout.tv_sec--;
}
if(timeout.tv_sec > tmp_timeout.tv_sec
|| (timeout.tv_sec == tmp_timeout.tv_sec && timeout.tv_usec > tmp_timeout.tv_usec)) {
timeout.tv_sec = tmp_timeout.tv_sec;
timeout.tv_usec = tmp_timeout.tv_usec;
}
}
}
}
if(select(max_fd+1, &readset, &writeset, 0, &timeout) < 0) if(select(max_fd+1, &readset, &writeset, 0, &timeout) < 0)
{ {
if(quitting) goto shutdown; if(quitting) goto shutdown;
@ -1764,6 +1797,9 @@ main(int argc, char * * argv)
syslog(LOG_ERR, "Failed to select open sockets. EXITING"); syslog(LOG_ERR, "Failed to select open sockets. EXITING");
return 1; /* very serious cause of error */ return 1; /* very serious cause of error */
} }
if(try_sendto(&writeset) < 0) {
syslog(LOG_ERR, "try_sendto: %m");
}
#ifdef USE_MINIUPNPDCTL #ifdef USE_MINIUPNPDCTL
for(ectl = ctllisthead.lh_first; ectl;) for(ectl = ctllisthead.lh_first; ectl;)
{ {