Nathanael Premillieu has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/32994 )

Change subject: base: avoid recreating socket at each call to listen()
......................................................................

base: avoid recreating socket at each call to listen()

A new socket was created each time listen() is called,
which is problematic when the bind or listen operation
on it are not successful (mostly because the associated port is
already in use). It can lead gem5 to open too many files and crash
for multicores configurations, a socket being created
for remote GDB for each core. The other way to deal with
this problem would be to close the socket in the case the
function return false. But I find the proposed solution
simpler.

Change-Id: I848955a10c89e1da033bf773c83556a5dc5ef9a2
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32994
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/socket.cc
1 file changed, 6 insertions(+), 3 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/socket.cc b/src/base/socket.cc
index adf8315..fce54aa 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -101,9 +101,12 @@
     if (listening)
         panic("Socket already listening!");

-    fd = ::socket(PF_INET, SOCK_STREAM, 0);
-    if (fd < 0)
-        panic("Can't create socket:%s !", strerror(errno));
+    // only create socket if not already created by a previous call
+    if (fd == -1) {
+        fd = ::socket(PF_INET, SOCK_STREAM, 0);
+        if (fd < 0)
+            panic("Can't create socket:%s !", strerror(errno));
+    }

     if (reuse) {
         int i = 1;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/32994
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I848955a10c89e1da033bf773c83556a5dc5ef9a2
Gerrit-Change-Number: 32994
Gerrit-PatchSet: 2
Gerrit-Owner: Nathanael Premillieu <nathanael.premill...@huawei.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Nathanael Premillieu <nathanael.premill...@huawei.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Jason Lowe-Power <power...@gmail.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to