summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-08-03 18:19:55 -0700
committerNathan Binkert <nate@binkert.org>2008-08-03 18:19:55 -0700
commit50ef39af82413ef463609f24173b22af13fad268 (patch)
tree44fb10aeaf17c5055c2ae315f5bc52e25180a3d3 /src/base
parentede89c2d541051c2ed647e2967712e10b3c0fab0 (diff)
downloadgem5-50ef39af82413ef463609f24173b22af13fad268.tar.xz
sockets: Add a function to disable all listening sockets.
When invoking several copies of m5 on the same machine at the same time, there can be a race for TCP ports for the terminal connections or remote gdb. Expose a function to disable those ports, and have the regression scripts disable them. There are some SimObjects that have no other function than to be used with ports (NativeTrace and EtherTap), so they will panic if the ports are disabled.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/remote_gdb.cc5
-rw-r--r--src/base/socket.cc18
-rw-r--r--src/base/socket.hh8
3 files changed, 31 insertions, 0 deletions
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 51293e118..06e04e19e 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -195,6 +195,11 @@ GDBListener::name()
void
GDBListener::listen()
{
+ if (ListenSocket::allDisabled()) {
+ warn_once("Sockets disabled, not accepting gdb connections");
+ return;
+ }
+
while (!listener.listen(port, true)) {
DPRINTF(GDBMisc, "Can't bind port %d\n", port);
port++;
diff --git a/src/base/socket.cc b/src/base/socket.cc
index adcc48735..bcc5236b0 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -43,6 +43,23 @@
using namespace std;
+bool ListenSocket::listeningDisabled = false;
+bool ListenSocket::anyListening = false;
+
+void
+ListenSocket::disableAll()
+{
+ if (anyListening)
+ panic("Too late to disable all listeners, already have a listener");
+ listeningDisabled = true;
+}
+
+bool
+ListenSocket::allDisabled()
+{
+ return listeningDisabled;
+}
+
////////////////////////////////////////////////////////////////////////
//
//
@@ -92,6 +109,7 @@ ListenSocket::listen(int port, bool reuse)
listening = true;
+ anyListening = true;
return true;
}
diff --git a/src/base/socket.hh b/src/base/socket.hh
index 8e55eae72..942318e45 100644
--- a/src/base/socket.hh
+++ b/src/base/socket.hh
@@ -34,6 +34,14 @@
class ListenSocket
{
protected:
+ static bool listeningDisabled;
+ static bool anyListening;
+
+ public:
+ static void disableAll();
+ static bool allDisabled();
+
+ protected:
bool listening;
int fd;