2828// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929// POSSIBILITY OF SUCH DAMAGE.
3030
31- #include < signal.h>
31+
32+ #include < glog/logging.h>
3233#include < poll.h>
34+ #include < signal.h>
35+
36+ #include < cerrno>
37+ #include < cstring>
3338
3439#include " unix_socket.h"
3540
@@ -56,6 +61,7 @@ void UnixSocketPort::AcceptThread() {
5661 fds[1 ].events = POLLRDHUP;
5762
5863 while (true ) {
64+ // negative FDs are ignored by ppoll()
5965 fds[1 ].fd = client_fd_;
6066 int res = ppoll (fds, 2 , nullptr , &sigset);
6167
@@ -66,7 +72,7 @@ void UnixSocketPort::AcceptThread() {
6672 if (errno == EINTR) {
6773 continue ;
6874 } else {
69- PLOG (ERROR) << " [UnixSocketPort]:epoll_wait ()" ;
75+ PLOG (ERROR) << " ppoll ()" ;
7076 }
7177
7278 } else if (fds[0 ].revents & POLLIN) {
@@ -79,9 +85,9 @@ void UnixSocketPort::AcceptThread() {
7985 }
8086 }
8187 if (fd < 0 ) {
82- PLOG (ERROR) << " [UnixSocketPort]: accept4()" ;
88+ PLOG (ERROR) << " accept4()" ;
8389 } else if (client_fd_ != kNotConnectedFd ) {
84- LOG (WARNING) << " [UnixSocketPort]: Ignoring additional client\n " ;
90+ LOG (WARNING) << " Ignoring additional client\n " ;
8591 close (fd);
8692 } else {
8793 client_fd_ = fd;
@@ -90,14 +96,14 @@ void UnixSocketPort::AcceptThread() {
9096 } else if (fds[1 ].revents & (POLLRDHUP | POLLHUP)) {
9197 // connection dropped by client
9298 int fd = client_fd_;
93- client_fd_ = - 1 ;
99+ client_fd_ = kNotConnectedFd ;
94100 close (fd);
95101 }
96102 }
97103}
98104
99- static void AcceptThreadHandler (int sig ) {
100- int arg __attribute__ ((unused)) = sig; // keep compiler happy
105+ static void AcceptThreadHandler (int ) {
106+ // empty handler, we only care about blocking syscalls being interrupted
101107}
102108
103109CommandResponse UnixSocketPort::Init (const bess::pb::UnixSocketPortArg &arg) {
@@ -161,7 +167,7 @@ CommandResponse UnixSocketPort::Init(const bess::pb::UnixSocketPortArg &arg) {
161167 }
162168
163169
164- accept_thread_ = std::thread ([& ]() {
170+ accept_thread_ = std::thread ([this ]() {
165171 this ->AcceptThread ();
166172 });
167173
0 commit comments