summaryrefslogtreecommitdiffhomepage
path: root/plop.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-05-08 17:02:31 +0200
committerAki <please@ignore.pl>2020-05-08 17:02:31 +0200
commit5ba3cb56c2832f5885bd05be9ed88a9434451c21 (patch)
tree6331a764742bd641bbc37c357319e3363fdc3d98 /plop.c
parent7fc6a70725d54cf767a250a4c6b3f3fcc9eff85a (diff)
downloadplop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.zip
plop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.tar.gz
plop-5ba3cb56c2832f5885bd05be9ed88a9434451c21.tar.bz2
Server socket should be now reusable
Diffstat (limited to 'plop.c')
-rw-r--r--plop.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/plop.c b/plop.c
index d676c4f..e90c3b0 100644
--- a/plop.c
+++ b/plop.c
@@ -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;