Add support for listening sockets for outgoing data.

This commit is contained in:
Ian Gulliver
2016-02-17 13:56:13 -08:00
parent 7f8b92deaf
commit 908a364aef
7 changed files with 55 additions and 18 deletions

View File

@@ -4,6 +4,7 @@
#include <getopt.h>
#include <sys/epoll.h>
#include <string.h>
#include <signal.h>
#include "common.h"
#include "backend.h"
@@ -35,6 +36,7 @@ static void print_usage(char *argv[]) {
"\t--backend=HOST/PORT\n"
"\t--dump=FORMAT\n"
"\t--incoming=[HOST/]PORT\n"
"\t--listen=FORMAT=[HOST/]PORT\n"
, argv[0]);
}
@@ -43,24 +45,25 @@ static bool parse_opts(int argc, char *argv[], int epoll_fd) {
{"backend", required_argument, 0, 'b'},
{"dump", required_argument, 0, 'd'},
{"incoming", required_argument, 0, 'i'},
{"listen", required_argument, 0, 'l'},
{"help", no_argument, 0, 'h'},
};
int opt;
char *delim;
char *delim1, *delim2;
while ((opt = getopt_long_only(argc, argv, "", long_options, NULL)) != -1) {
switch (opt) {
case 'b':
// It would be really nice if libc had a standard way to split host:port.
delim = strrchr(optarg, '/');
if (delim == NULL) {
delim1 = strrchr(optarg, '/');
if (delim1 == NULL) {
print_usage(argv);
return false;
}
*delim = '\0';
delim++;
*delim1 = '\0';
delim1++;
backend_new(optarg, delim, epoll_fd);
backend_new(optarg, delim1, epoll_fd);
break;
case 'd':
@@ -74,13 +77,37 @@ static bool parse_opts(int argc, char *argv[], int epoll_fd) {
return false;
case 'i':
delim = strrchr(optarg, '/');
if (delim == NULL) {
incoming_new(NULL, optarg, epoll_fd, backend_new_fd);
delim1 = strrchr(optarg, '/');
if (delim1 == NULL) {
incoming_new(NULL, optarg, epoll_fd, backend_new_fd, NULL);
} else {
*delim = '\0';
delim++;
incoming_new(optarg, delim, epoll_fd, backend_new_fd);
*delim1 = '\0';
delim1++;
incoming_new(optarg, delim1, epoll_fd, backend_new_fd, NULL);
}
break;
case 'l':
delim1 = strchr(optarg, '=');
if (delim1 == NULL) {
print_usage(argv);
return false;
}
*delim1 = '\0';
delim1++;
struct serializer *serializer = client_get_serializer(optarg);
if (!serializer) {
fprintf(stderr, "Unknown format: %s\n", optarg);
return false;
}
delim2 = strrchr(delim1, '/');
if (delim2 == NULL) {
incoming_new(NULL, delim1, epoll_fd, client_new_fd, serializer);
} else {
*delim2 = '\0';
delim2++;
incoming_new(delim1, delim2, epoll_fd, client_new_fd, serializer);
}
break;
@@ -117,6 +144,8 @@ static int loop(int epoll_fd) {
}
int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
server_init();
hex_init();
airspy_adsb_init();