diff options
author | Aki <please@ignore.pl> | 2020-05-08 17:02:31 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-05-08 17:02:31 +0200 |
commit | 5ba3cb56c2832f5885bd05be9ed88a9434451c21 (patch) | |
tree | 6331a764742bd641bbc37c357319e3363fdc3d98 | |
parent | 7fc6a70725d54cf767a250a4c6b3f3fcc9eff85a (diff) | |
download | plop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.zip plop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.tar.gz plop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.tar.bz2 |
Server socket should be now reusable
-rw-r--r-- | plop.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -36,6 +36,7 @@ int make_server(const char * node, const char * service) } int server; + int optval = 1; for (it = result; it != NULL; it = it->ai_next) { @@ -44,6 +45,12 @@ int make_server(const char * node, const char * service) if (-1 == server) continue; + if (-1 == setsockopt(server, SOL_SOCKET, SO_REUSEADDR, (char *) &optval, sizeof(optval))) + { + close(server); + continue; + } + if (-1 == fcntl(server, F_SETFL, (fcntl(server, F_GETFL, 0) | O_NONBLOCK))) { close(server); @@ -177,6 +184,11 @@ int main(int argc, char ** argv) fdv[0].events = POLLIN; fdc++; + if (-1 == fdv[0].fd) + { + return 1; // TODO: Document error codes/print usage information + } + while (0 < fdc && -1 != poll(fdv, fdc, -1)) { int shift_by = 0; |