jobserver: use non-blocking accept

To allow the JobServer to shutdown properly, the accept() loop in
JobServer::run() needs to regularly check whether we're done.  This
change introduces a timed, non-blocking variant of accept() into
SocketComm to achieve this.

Change-Id: Id411096be816c4ed6c7b0b37674410e22152eb22
This commit is contained in:
Horst Schirmeier
2014-01-17 18:19:38 +01:00
parent 8671669053
commit 73adc71437
3 changed files with 31 additions and 5 deletions

View File

@ -161,11 +161,15 @@ void JobServer::run()
boost::thread* th;
while (!m_finish){
// Accept connection
int cs = accept(s, (struct sockaddr*)&clientaddr, &clen);
if (cs == -1) {
perror("accept");
// TODO: Log-level?
return;
int cs = SocketComm::timedAccept(s, (struct sockaddr*)&clientaddr, &clen, 100);
if (cs < 0) {
if (errno != EWOULDBLOCK) {
perror("poll/accept");
// TODO: Log-level?
return;
} else {
continue;
}
}
// Spawn a thread for further communication,
// and add this thread to a list threads