about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--091socket.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/091socket.cc b/091socket.cc
index 5bfea078..22000c16 100644
--- a/091socket.cc
+++ b/091socket.cc
@@ -60,13 +60,14 @@ socket_t* server_socket(int portno) {
   result->addr.sin_family = AF_INET;
   result->addr.sin_addr.s_addr = INADDR_ANY;
   result->addr.sin_port = htons(portno);
-  if (bind(result->fd, (struct sockaddr*)&result->addr, sizeof(result->addr)) < 0) {
+  if (bind(result->fd, (struct sockaddr*)&result->addr, sizeof(result->addr)) >= 0) {
+    listen(result->fd, /*queue length*/5);
+  }
+  else {
     close(result->fd);
     result->fd = -1;
     raise << "Failed to bind result socket to port " << portno << ". Something's already using that port.\n" << end();
-    return result;
   }
-  listen(result->fd, /*queue length*/5);
   return result;
 }