From 98c7c73d0647f7551cf98434ab7cf0009c8f91ec Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 1 Oct 2014 12:17:51 +0100 Subject: [PATCH 1/3] Only use O_BINARY on Win32 --- dump1090.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dump1090.c b/dump1090.c index f88d03b..7a7addd 100644 --- a/dump1090.c +++ b/dump1090.c @@ -710,7 +710,13 @@ int main(int argc, char **argv) { } else { if (Modes.filename[0] == '-' && Modes.filename[1] == '\0') { Modes.fd = STDIN_FILENO; - } else if ((Modes.fd = open(Modes.filename, (O_RDONLY | O_BINARY))) == -1) { + } else if ((Modes.fd = open(Modes.filename, +#ifdef _WIN32 + (O_RDONLY | O_BINARY) +#else + (O_RDONLY) +#endif + )) == -1) { perror("Opening data file"); exit(1); } From a513c3677ba72faff5bf32afb56b1f879678fc2f Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 1 Oct 2014 12:29:16 +0100 Subject: [PATCH 2/3] Detect client EOF properly. Handle EWOULDBLOCK. Client disconnection appears as a read of 0 bytes. Without a test for this, dump1090 continues to poll that client forever. Also, read() may return EWOULDBLOCK as well as EAGAIN for "no data right now", so handle that. I don't know if there is an equivalent Win32 bug here as the Win32 interfaces seem subtly different to vanilla POSIX. The following test/break can probably be removed if Win32 needs the same fix. --- net_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net_io.c b/net_io.c index 2b0ed9a..0283394 100644 --- a/net_io.c +++ b/net_io.c @@ -851,11 +851,12 @@ void modesReadFromClient(struct client *c, char *sep, bContinue = 0; } #ifndef _WIN32 - if ( (nread < 0) && (errno != EAGAIN)) { // Error, or end of file + if ( (nread < 0 && errno != EAGAIN && errno != EWOULDBLOCK) || nread == 0 ) { // Error, or end of file #else if ( (nread < 0) && (errno != EWOULDBLOCK)) { // Error, or end of file #endif modesFreeClient(c); + return; } if (nread <= 0) { break; // Serve next client From 186cac5c25075381f7c4f1793983f09131406909 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 1 Oct 2014 12:37:29 +0100 Subject: [PATCH 3/3] Use the anet-reported error string when reporting bind errors. errno may have been modified by the time you see it. --- net_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net_io.c b/net_io.c index 2b0ed9a..4aa2a54 100644 --- a/net_io.c +++ b/net_io.c @@ -88,7 +88,7 @@ void modesInitNet(void) { int s = anetTcpServer(Modes.aneterr, services[j].port, NULL); if (s == -1) { fprintf(stderr, "Error opening the listening port %d (%s): %s\n", - services[j].port, services[j].descr, strerror(errno)); + services[j].port, services[j].descr, Modes.aneterr); exit(1); } anetNonBlock(Modes.aneterr, s);