ruby: message buffer: removes some unecessary functions.
[gem5.git] / src / base / socket.cc
index adcc48735f3dc3c0fa836536f3972c3e18c42913..c39accd7e80f0b28cefa853d49dc4da323209367 100644 (file)
  * Authors: Nathan Binkert
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-
 #include <netinet/in.h>
 #include <netinet/tcp.h>
-
-#include <errno.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 #include <unistd.h>
 
-#include "sim/host.hh"
+#include <cerrno>
+
 #include "base/misc.hh"
 #include "base/socket.hh"
+#include "base/types.hh"
 
 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;
+}
+
 ////////////////////////////////////////////////////////////////////////
 //
 //
@@ -87,11 +103,15 @@ ListenSocket::listen(int port, bool reuse)
         return false;
     }
 
-    if (::listen(fd, 1) == -1)
-        panic("ListenSocket(listen): listen() failed!");
+    if (::listen(fd, 1) == -1) {
+        if (errno != EADDRINUSE)
+            panic("ListenSocket(listen): listen() failed!");
 
-    listening = true;
+        return false;
+    }
 
+    listening = true;
+    anyListening = true;
     return true;
 }