[hamradio-commits] [dump1090] 291/373: B"H allow disable ports, doc disable net heartbeat

Matthew Ernisse mernisse-guest at moszumanska.debian.org
Thu Oct 23 14:58:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

mernisse-guest pushed a commit to branch backport
in repository dump1090.

commit 59984ac8af30f54a9c8852905dd9e0ba42e62b52
Author: hhm <heehooman+vcs-ci at gmail.com>
Date:   Tue Jun 24 23:58:46 2014 -0400

    B"H allow disable ports, doc disable net heartbeat
---
 dump1090.c |   2 +-
 net_io.c   | 103 +++++++++++++++++++++++++++++++++----------------------------
 2 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/dump1090.c b/dump1090.c
index 585b4f8..286fb05 100644
--- a/dump1090.c
+++ b/dump1090.c
@@ -415,7 +415,7 @@ void showHelp(void) {
 "--net-bo-port <port>     TCP Beast output listen port (default: 30005)\n"
 "--net-ro-size <size>     TCP raw output minimum size (default: 0)\n"
 "--net-ro-rate <rate>     TCP raw output memory flush rate (default: 0)\n"
-"--net-heartbeat <rate>   TCP heartbeat rate in seconds (default: 60 sec)\n"
+"--net-heartbeat <rate>   TCP heartbeat rate in seconds (default: 60 sec; 0 to disable)\n"
 "--net-buffer <n>         TCP buffer size 64Kb * (2^n) (default: n=0, 64Kb)\n"
 "--lat <latitude>         Reference/receiver latitude for surface posn (opt)\n"
 "--lon <longitude>        Reference/receiver longitude for surface posn (opt)\n"
diff --git a/net_io.c b/net_io.c
index 9462154..2f4c950 100644
--- a/net_io.c
+++ b/net_io.c
@@ -46,21 +46,29 @@
 //
 // Networking "stack" initialization
 //
+struct service {
+	char *descr;
+	int *socket;
+	int port;
+	int enabled;
+};
+
+struct service services[MODES_NET_SERVICES_NUM];
+
 void modesInitNet(void) {
-    struct {
-        char *descr;
-        int *socket;
-        int port;
-    } services[MODES_NET_SERVICES_NUM] = {
-        {"Raw TCP output", &Modes.ros, Modes.net_output_raw_port},
-        {"Raw TCP input", &Modes.ris, Modes.net_input_raw_port},
-        {"Beast TCP output", &Modes.bos, Modes.net_output_beast_port},
-        {"Beast TCP input", &Modes.bis, Modes.net_input_beast_port},
-        {"HTTP server", &Modes.https, Modes.net_http_port},
-        {"Basestation TCP output", &Modes.sbsos, Modes.net_output_sbs_port}
-    };
     int j;
 
+	struct service svc[MODES_NET_SERVICES_NUM] = {
+		{"Raw TCP output", &Modes.ros, Modes.net_output_raw_port, 1},
+		{"Raw TCP input", &Modes.ris, Modes.net_input_raw_port, 1},
+		{"Beast TCP output", &Modes.bos, Modes.net_output_beast_port, 1},
+		{"Beast TCP input", &Modes.bis, Modes.net_input_beast_port, 1},
+		{"HTTP server", &Modes.https, Modes.net_http_port, 1},
+		{"Basestation TCP output", &Modes.sbsos, Modes.net_output_sbs_port, 1}
+	};
+
+	memcpy(&services, &svc, sizeof(svc));//services = svc;
+
     Modes.clients = NULL;
 
 #ifdef _WIN32
@@ -75,14 +83,19 @@ void modesInitNet(void) {
 #endif
 
     for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
-        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));
-            exit(1);
-        }
-        anetNonBlock(Modes.aneterr, s);
-        *services[j].socket = s;
+		services[j].enabled = (services[j].port != 0);
+		if (services[j].enabled) {
+			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));
+				exit(1);
+			}
+			anetNonBlock(Modes.aneterr, s);
+			*services[j].socket = s;
+		} else {
+			if (Modes.debug & MODES_DEBUG_NET) printf("%s port is disabled\n", services[j].descr);
+		}
     }
 
 #ifndef _WIN32
@@ -99,36 +112,30 @@ struct client * modesAcceptClients(void) {
     int fd, port;
     unsigned int j;
     struct client *c;
-    int services[6];
-
-    services[0] = Modes.ros;
-    services[1] = Modes.ris;
-    services[2] = Modes.bos;
-    services[3] = Modes.bis;
-    services[4] = Modes.https;
-    services[5] = Modes.sbsos;
 
     for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
-        fd = anetTcpAccept(Modes.aneterr, services[j], NULL, &port);
-        if (fd == -1) continue;
-
-        anetNonBlock(Modes.aneterr, fd);
-        c = (struct client *) malloc(sizeof(*c));
-        c->service    = services[j];
-        c->next       = Modes.clients;
-        c->fd         = fd;
-        c->buflen     = 0;
-        Modes.clients = c;
-        anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size));
-
-        if (services[j] == Modes.sbsos) Modes.stat_sbs_connections++;
-        if (services[j] == Modes.ros)   Modes.stat_raw_connections++;
-        if (services[j] == Modes.bos)   Modes.stat_beast_connections++;
-
-        j--; // Try again with the same listening port
-
-        if (Modes.debug & MODES_DEBUG_NET)
-            printf("Created new client %d\n", fd);
+		if (services[j].enabled) {
+			fd = anetTcpAccept(Modes.aneterr, *services[j].socket, NULL, &port);
+			if (fd == -1) continue;
+
+			anetNonBlock(Modes.aneterr, fd);
+			c = (struct client *) malloc(sizeof(*c));
+			c->service    = *services[j].socket;
+			c->next       = Modes.clients;
+			c->fd         = fd;
+			c->buflen     = 0;
+			Modes.clients = c;
+			anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size));
+
+			if (*services[j].socket == Modes.sbsos) Modes.stat_sbs_connections++;
+			if (*services[j].socket == Modes.ros)   Modes.stat_raw_connections++;
+			if (*services[j].socket == Modes.bos)   Modes.stat_beast_connections++;
+
+			j--; // Try again with the same listening port
+
+			if (Modes.debug & MODES_DEBUG_NET)
+				printf("Created new client %d\n", fd);
+		}
     }
     return Modes.clients;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git



More information about the pkg-hamradio-commits mailing list