diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-07 13:55:35 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-07 13:55:35 -0700 |
commit | 347510c0a2d8820e2ad5450dd34d03e2e5d073a1 (patch) | |
tree | 2540b3ca92f164d7535efa8d0a9da636641b7d84 | |
parent | 19f47cc033fc5d4a41d1d8f679b675f09fbcccc1 (diff) | |
download | mu-347510c0a2d8820e2ad5450dd34d03e2e5d073a1.tar.gz |
3470
-rw-r--r-- | 091socket.cc | 7 |
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; } |