Make sure threads dont exit on spurious return values from recvfrom unless we are really dying.

This commit is contained in:
Adam Ierymenko 2019-09-16 20:41:23 -07:00
parent 50009fef6f
commit 624efde7e4
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3

View file

@ -694,7 +694,10 @@ static int bindSocket(struct sockaddr *const bindAddr)
return s; return s;
} }
static void shutdownSigHandler(int sig) { s_run = false; } static void shutdownSigHandler(int sig)
{
s_run = false;
}
int main(int argc,char **argv) int main(int argc,char **argv)
{ {
@ -918,7 +921,7 @@ int main(int argc,char **argv)
printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S,reinterpret_cast<const InetAddress *>(&in6)->toString(ipstr)); printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S,reinterpret_cast<const InetAddress *>(&in6)->toString(ipstr));
} }
} }
} else if ((errno != EAGAIN)&&(errno != EWOULDBLOCK)) { } else if (!s_run) {
break; break;
} }
} }
@ -947,7 +950,7 @@ int main(int argc,char **argv)
printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S,reinterpret_cast<const InetAddress *>(&in4)->toString(ipstr)); printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S,reinterpret_cast<const InetAddress *>(&in4)->toString(ipstr));
} }
} }
} else if ((errno != EAGAIN)&&(errno != EWOULDBLOCK)) { } else if (!s_run) {
break; break;
} }
} }
@ -1292,6 +1295,7 @@ int main(int argc,char **argv)
// If we received a kill signal, close everything and wait // If we received a kill signal, close everything and wait
// for threads to die before exiting. // for threads to die before exiting.
s_run = false; // sanity check
apiServ.stop(); apiServ.stop();
for(auto s=sockets.begin();s!=sockets.end();++s) { for(auto s=sockets.begin();s!=sockets.end();++s) {
shutdown(*s,SHUT_RDWR); shutdown(*s,SHUT_RDWR);