miniupnpd/asyncsendto: finalize_sendto()
This commit is contained in:
parent
02165b70dc
commit
a06c695fe3
|
@ -195,3 +195,25 @@ int try_sendto(fd_set * writefds)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* empty the list */
|
||||
void finalize_sendto(void)
|
||||
{
|
||||
ssize_t n;
|
||||
struct scheduled_send * elt;
|
||||
struct scheduled_send * next;
|
||||
/* TODO : improve with a select() and a short timeout */
|
||||
for(elt = send_list.lh_first; elt != NULL; elt = next) {
|
||||
next = elt->entries.le_next;
|
||||
syslog(LOG_DEBUG, "finalize_sendto(): %d bytes on socket %d",
|
||||
(int)elt->len, elt->sockfd);
|
||||
n = sendto(elt->sockfd, elt->buf, elt->len, elt->flags,
|
||||
elt->dest_addr, elt->addrlen);
|
||||
if(n < 0) {
|
||||
syslog(LOG_WARNING, "sendto(): %m");
|
||||
}
|
||||
/* remove from the list */
|
||||
LIST_REMOVE(elt, entries);
|
||||
free(elt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,4 +32,7 @@ int try_sendto(fd_set * writefds);
|
|||
/* set writefds before select() */
|
||||
int get_sendto_fds(fd_set * writefds, int * max_fd, const struct timeval * now);
|
||||
|
||||
/* empty the list */
|
||||
void finalize_sendto(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2026,6 +2026,21 @@ main(int argc, char * * argv)
|
|||
} /* end of main loop */
|
||||
|
||||
shutdown:
|
||||
/* send good-bye */
|
||||
if (GETFLAG(ENABLEUPNPMASK))
|
||||
{
|
||||
#ifndef ENABLE_IPV6
|
||||
if(SendSSDPGoodbye(snotify, addr_count) < 0)
|
||||
#else
|
||||
if(SendSSDPGoodbye(snotify, addr_count * 2) < 0)
|
||||
#endif
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to broadcast good-bye notifications");
|
||||
}
|
||||
}
|
||||
/* try to send pending packets */
|
||||
finalize_sendto();
|
||||
|
||||
/* close out open sockets */
|
||||
while(upnphttphead.lh_first != NULL)
|
||||
{
|
||||
|
@ -2065,14 +2080,6 @@ shutdown:
|
|||
|
||||
if (GETFLAG(ENABLEUPNPMASK))
|
||||
{
|
||||
#ifndef ENABLE_IPV6
|
||||
if(SendSSDPGoodbye(snotify, addr_count) < 0)
|
||||
#else
|
||||
if(SendSSDPGoodbye(snotify, addr_count * 2) < 0)
|
||||
#endif
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to broadcast good-bye notifications");
|
||||
}
|
||||
#ifndef ENABLE_IPV6
|
||||
for(i = 0; i < addr_count; i++)
|
||||
#else
|
||||
|
@ -2081,6 +2088,7 @@ shutdown:
|
|||
close(snotify[i]);
|
||||
}
|
||||
|
||||
/* remove pidfile */
|
||||
if(pidfilename && (unlink(pidfilename) < 0))
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to remove pidfile %s: %m", pidfilename);
|
||||
|
|
Loading…
Reference in New Issue