From d16abd3be87bdc3872c671a04dccdd5b286a208f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 22 Jul 2018 13:16:13 +0200 Subject: [PATCH] Add more error messages to test program, allow socket reuse. --- test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test.c b/test.c index 81f45a5..96ebb0c 100644 --- a/test.c +++ b/test.c @@ -198,21 +198,28 @@ int main(int argc, char *argv[]) { getaddrinfo(server ? NULL : argv[1], server ? argv[1] : argv[2], &hint, &ai); if(!ai) { + debug("Could not lookup address: %s\n", strerror(errno)); return 1; } int s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if(s == -1) { + debug("Could not create socket: %s\n", strerror(errno)); return 1; } + static const int one = 1; + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + if(server) { if(bind(s, ai->ai_addr, ai->ai_addrlen)) { + debug("Could not bind: %s\n", strerror(errno)); return 1; } } else { if(connect(s, ai->ai_addr, ai->ai_addrlen)) { + debug("Could not connect: %s\n", strerror(errno)); return 1; } @@ -224,6 +231,7 @@ int main(int argc, char *argv[]) { struct utcp *u = utcp_init(server ? do_accept : NULL, NULL, do_send, &s); if(!u) { + debug("Could not initialize UTCP\n"); return 1; } -- 2.39.5