Merge pull request #20 from hhm0/network_disabling
make network services disable-able
This commit is contained in:
commit
c0d6ea073f
|
@ -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"
|
||||||
|
|
53
net_io.c
53
net_io.c
|
@ -46,21 +46,29 @@
|
||||||
//
|
//
|
||||||
// Networking "stack" initialization
|
// Networking "stack" initialization
|
||||||
//
|
//
|
||||||
void modesInitNet(void) {
|
struct service {
|
||||||
struct {
|
|
||||||
char *descr;
|
char *descr;
|
||||||
int *socket;
|
int *socket;
|
||||||
int port;
|
int port;
|
||||||
} services[MODES_NET_SERVICES_NUM] = {
|
int enabled;
|
||||||
{"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},
|
struct service services[MODES_NET_SERVICES_NUM];
|
||||||
{"Beast TCP input", &Modes.bis, Modes.net_input_beast_port},
|
|
||||||
{"HTTP server", &Modes.https, Modes.net_http_port},
|
void modesInitNet(void) {
|
||||||
{"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,6 +83,8 @@ void modesInitNet(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
|
for (j = 0; j < MODES_NET_SERVICES_NUM; j++) {
|
||||||
|
services[j].enabled = (services[j].port != 0);
|
||||||
|
if (services[j].enabled) {
|
||||||
int s = anetTcpServer(Modes.aneterr, services[j].port, NULL);
|
int s = anetTcpServer(Modes.aneterr, services[j].port, NULL);
|
||||||
if (s == -1) {
|
if (s == -1) {
|
||||||
fprintf(stderr, "Error opening the listening port %d (%s): %s\n",
|
fprintf(stderr, "Error opening the listening port %d (%s): %s\n",
|
||||||
|
@ -83,6 +93,9 @@ void modesInitNet(void) {
|
||||||
}
|
}
|
||||||
anetNonBlock(Modes.aneterr, s);
|
anetNonBlock(Modes.aneterr, s);
|
||||||
*services[j].socket = 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,37 +112,31 @@ 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) {
|
||||||
|
fd = anetTcpAccept(Modes.aneterr, *services[j].socket, NULL, &port);
|
||||||
if (fd == -1) continue;
|
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;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue