FreeCalypso > hg > freecalypso-sw
diff rvinterf/lowlevel/rvifmain.c @ 177:fef035264dd4
rvinterf: beginning of local socket handling
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 23 Nov 2013 20:15:02 +0000 |
parents | 7f727aaf5cd4 |
children | 7ab6b29e76bb |
line wrap: on
line diff
--- a/rvinterf/lowlevel/rvifmain.c Sat Nov 23 07:40:13 2013 +0000 +++ b/rvinterf/lowlevel/rvifmain.c Sat Nov 23 20:15:02 2013 +0000 @@ -9,17 +9,22 @@ #include <unistd.h> #include <time.h> #include "../pktmux.h" +#include "../localsock.h" +#include "client.h" -extern int target_fd; +extern int target_fd, listener; extern char *baudrate_name; extern u_char rxpkt[]; extern size_t rxpkt_len; +struct client *client_head; + char *logfname; FILE *logF; time_t logtime; int background; +int max_fd; main(argc, argv) char **argv; @@ -28,6 +33,7 @@ extern int optind; int c; fd_set fds; + struct client *cli, **clip; while ((c = getopt(argc, argv, "bB:d:l:")) != EOF) switch (c) { @@ -54,6 +60,7 @@ goto usage; open_target_serial(argv[optind]); } + max_fd = target_fd; set_serial_nonblock(0); setlinebuf(stdout); @@ -66,6 +73,7 @@ fprintf(logF, "*** Log of rvinterf session ***\n"); setlinebuf(logF); } + create_listener_socket(); if (background) { c = fork(); if (c < 0) { @@ -80,7 +88,18 @@ for (;;) { FD_ZERO(&fds); FD_SET(target_fd, &fds); - c = select(target_fd+1, &fds, 0, 0, 0); + FD_SET(listener, &fds); + for (clip = &client_head; cli = *clip; ) { + if (cli->rx_state == 2) { + close(cli->fd); + *clip = cli->next; + free(cli); + continue; + } + FD_SET(cli->fd, &fds); + clip = &cli->next; + } + c = select(max_fd+1, &fds, 0, 0, 0); time(&logtime); if (c < 0) { if (errno == EINTR) @@ -90,6 +109,11 @@ } if (FD_ISSET(target_fd, &fds)) process_serial_rx(); + if (FD_ISSET(listener, &fds)) + handle_listener_select(); + for (cli = client_head; cli; cli = cli->next) + if (FD_ISSET(cli->fd, &fds)) + handle_client_select(cli); } }