base,dev: Simplify the ListenSocket::accept method.

Remove the nodelay option which is always set to the same thing, and
simplify the logic of the method itself.

Change-Id: I78cd91f99cbaec9abddedbc7dcddc563daedb81f
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69158
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Reviewed-by: Yu-hsin Wang <yuhsingw@google.com>
This commit is contained in:
Gabe Black
2023-03-18 06:28:16 -07:00
committed by Gabe Black
parent 79cfef2650
commit 2e1d24d048
6 changed files with 12 additions and 12 deletions

View File

@@ -438,7 +438,7 @@ BaseRemoteGDB::connect()
pollQueue.remove(incomingConnectionEvent);
int sfd = listener.accept(true);
int sfd = listener.accept();
if (sfd != -1) {
if (isAttached())

View File

@@ -239,17 +239,17 @@ ListenSocket::listen(int port, bool reuse)
// Open a connection. Accept will block, so if you don't want it to,
// make sure a connection is ready before you call accept.
int
ListenSocket::accept(bool nodelay)
ListenSocket::accept()
{
struct sockaddr_in sockaddr;
socklen_t slen = sizeof (sockaddr);
int sfd = acceptCloexec(fd, (struct sockaddr *)&sockaddr, &slen);
if (sfd != -1 && nodelay) {
int i = 1;
if (::setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (char *)&i,
sizeof(i)) < 0)
warn("ListenSocket(accept): setsockopt() TCP_NODELAY failed!");
}
if (sfd == -1)
return -1;
int i = 1;
int ret = ::setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i));
warn_if(ret < 0, "ListenSocket(accept): setsockopt() TCP_NODELAY failed!");
return sfd;
}

View File

@@ -104,7 +104,7 @@ class ListenSocket
ListenSocket();
virtual ~ListenSocket();
virtual int accept(bool nodelay = true);
virtual int accept();
virtual bool listen(int port, bool reuse = true);

View File

@@ -190,7 +190,7 @@ VncServer::accept()
if (!listener.islistening())
panic("%s: cannot accept a connection if not listening!", name());
int fd = listener.accept(true);
int fd = listener.accept();
if (fd < 0) {
warn("%s: failed to accept VNC connection!", name());
return;

View File

@@ -280,7 +280,7 @@ TapListener::accept()
if (!listener.islistening())
panic("TapListener(accept): cannot accept if we're not listening!");
int sfd = listener.accept(true);
int sfd = listener.accept();
if (sfd != -1)
tap->attach(sfd);
}

View File

@@ -195,7 +195,7 @@ Terminal::accept()
if (!listener.islistening())
panic("%s: cannot accept a connection if not listening!", name());
int fd = listener.accept(true);
int fd = listener.accept();
if (data_fd != -1) {
char message[] = "terminal already attached!\n";
atomic_write(fd, message, sizeof(message));