B"H allow disable ports, doc disable net heartbeat

This commit is contained in:
hhm 2014-06-24 23:58:46 -04:00
parent 189e726792
commit 59984ac8af
2 changed files with 52 additions and 45 deletions

View file

@ -415,7 +415,7 @@ void showHelp(void) {
"--net-bo-port <port> TCP Beast output listen port (default: 30005)\n" "--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-size <size> TCP raw output minimum size (default: 0)\n"
"--net-ro-rate <rate> TCP raw output memory flush rate (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" "--net-buffer <n> TCP buffer size 64Kb * (2^n) (default: n=0, 64Kb)\n"
"--lat <latitude> Reference/receiver latitude for surface posn (opt)\n" "--lat <latitude> Reference/receiver latitude for surface posn (opt)\n"
"--lon <longitude> Reference/receiver longitude for surface posn (opt)\n" "--lon <longitude> Reference/receiver longitude for surface posn (opt)\n"

View file

@ -46,21 +46,29 @@
// //
// Networking "stack" initialization // Networking "stack" initialization
// //
struct service {
char *descr;
int *socket;
int port;
int enabled;
};
struct service services[MODES_NET_SERVICES_NUM];
void modesInitNet(void) { 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; 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; Modes.clients = NULL;
#ifdef _WIN32 #ifdef _WIN32
@ -75,14 +83,19 @@ void modesInitNet(void) {
#endif #endif
for (j = 0; j < MODES_NET_SERVICES_NUM; j++) { for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
int s = anetTcpServer(Modes.aneterr, services[j].port, NULL); services[j].enabled = (services[j].port != 0);
if (s == -1) { if (services[j].enabled) {
fprintf(stderr, "Error opening the listening port %d (%s): %s\n", int s = anetTcpServer(Modes.aneterr, services[j].port, NULL);
services[j].port, services[j].descr, strerror(errno)); if (s == -1) {
exit(1); fprintf(stderr, "Error opening the listening port %d (%s): %s\n",
} services[j].port, services[j].descr, strerror(errno));
anetNonBlock(Modes.aneterr, s); exit(1);
*services[j].socket = s; }
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 #ifndef _WIN32
@ -99,36 +112,30 @@ struct client * modesAcceptClients(void) {
int fd, port; int fd, port;
unsigned int j; unsigned int j;
struct client *c; 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++) { for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
fd = anetTcpAccept(Modes.aneterr, services[j], NULL, &port); if (services[j].enabled) {
if (fd == -1) continue; fd = anetTcpAccept(Modes.aneterr, *services[j].socket, NULL, &port);
if (fd == -1) continue;
anetNonBlock(Modes.aneterr, fd); anetNonBlock(Modes.aneterr, fd);
c = (struct client *) malloc(sizeof(*c)); c = (struct client *) malloc(sizeof(*c));
c->service = services[j]; c->service = *services[j].socket;
c->next = Modes.clients; c->next = Modes.clients;
c->fd = fd; c->fd = fd;
c->buflen = 0; c->buflen = 0;
Modes.clients = c; Modes.clients = c;
anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size)); anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size));
if (services[j] == Modes.sbsos) Modes.stat_sbs_connections++; if (*services[j].socket == Modes.sbsos) Modes.stat_sbs_connections++;
if (services[j] == Modes.ros) Modes.stat_raw_connections++; if (*services[j].socket == Modes.ros) Modes.stat_raw_connections++;
if (services[j] == Modes.bos) Modes.stat_beast_connections++; if (*services[j].socket == Modes.bos) Modes.stat_beast_connections++;
j--; // Try again with the same listening port j--; // Try again with the same listening port
if (Modes.debug & MODES_DEBUG_NET) if (Modes.debug & MODES_DEBUG_NET)
printf("Created new client %d\n", fd); printf("Created new client %d\n", fd);
}
} }
return Modes.clients; return Modes.clients;
} }