summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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;