diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-07-02 16:00:15 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-07-02 16:00:15 +0200 |
commit | 8d75833aacaa6c5aebd4014c79ace5633d6dabf3 (patch) | |
tree | 1471bb4feee6c335496d10c48ab12bba8d657c63 /src/socket.cc | |
parent | b69bba9b089afc69df837ae69d55debf5a14ca1a (diff) |
Shut down server process nicely on SIGINT. Reopen logfile on SIGHUP
Diffstat (limited to 'src/socket.cc')
-rw-r--r-- | src/socket.cc | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/socket.cc b/src/socket.cc index 1fffc87..349ec30 100644 --- a/src/socket.cc +++ b/src/socket.cc @@ -100,9 +100,31 @@ Socket Socket::slisten() // accept new connection and get its connection descriptor int csalen = sizeof(s.socketaddr); - s.ssocket = accept(ssocket, - (struct sockaddr*)&s.socketaddr, - (socklen_t*)&csalen); + { + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(ssocket, &rfds); + int retval = select(ssocket + 1, &rfds, NULL, NULL, NULL); + + if (retval == -1) { + if(errno == EINTR) { + connected = true; + s.connected = true; + return s; + } + + ERR(socket, "select() failed! %s", strerror(errno)); + } else if(retval) { + if(FD_ISSET(ssocket, &rfds)) { + s.ssocket = accept(ssocket, + (struct sockaddr*)&s.socketaddr, + (socklen_t*)&csalen); + ERR(socket, "accept() failed! %s", strerror(errno)); + } + } else { + // We don't do timeout + } + } if (s.ssocket < 0) { s.connected = false; |