From 347510c0a2d8820e2ad5450dd34d03e2e5d073a1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 7 Oct 2016 13:55:35 -0700 Subject: 3470 --- 091socket.cc | 7 ++++--- 1 file 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; } -- cgit 1.4.1-2-gfad0