Skip to content

Commit 8cd0de6

Browse files
author
Lluís Vilanova
committed
drivers/unix_socket: Code cleanup
1 parent c8e9e98 commit 8cd0de6

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

core/drivers/unix_socket.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
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

103109
CommandResponse 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

core/drivers/unix_socket.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,12 @@
3131
#ifndef BESS_DRIVERS_UNIXSOCKET_H_
3232
#define BESS_DRIVERS_UNIXSOCKET_H_
3333

34-
#include <assert.h>
35-
#include <atomic>
36-
#include <errno.h>
37-
#include <poll.h>
38-
#include <stdio.h>
39-
#include <string.h>
4034
#include <sys/socket.h>
4135
#include <sys/un.h>
42-
#include <thread>
4336
#include <unistd.h>
4437

45-
#include <glog/logging.h>
38+
#include <atomic>
39+
#include <thread>
4640

4741
#include "../message.h"
4842
#include "../port.h"

0 commit comments

Comments
 (0)