diff --git a/moxerver.h b/moxerver.h index af52bb9..0792ab2 100644 --- a/moxerver.h +++ b/moxerver.h @@ -13,7 +13,7 @@ /* Global variables used throughout the application. */ server_t server; /* main server */ -client_t client; /* connected client */ //TODO working with only 1 client, this can be expanded into a list +client_t client; /* connected client */ client_t new_client; /* reserved for a new client request */ tty_t tty_dev; /* connected tty device */ diff --git a/server.c b/server.c index 99f7a4f..8e6f5a0 100644 --- a/server.c +++ b/server.c @@ -52,8 +52,8 @@ int server_setup(server_t *server, unsigned int port) server->port = port; fprintf(stderr,"[%s] assigned port %u\n", __func__, server->port); // ntohs(server->address.sin_port) - /* listen for a client connection, allow some connections in queue */ - if (listen(server->socket, 1) == -1) + /* listen for a client connection, allow (max-1) connections in queue */ + if (listen(server->socket, (SERVER_MAX_CONNECTIONS - 1)) == -1) { fprintf(stderr, "[%s:%d] error %d: %s\n", __func__, __LINE__, errno, strerror(errno)); diff --git a/server.h b/server.h index 4bd951b..bb4241f 100644 --- a/server.h +++ b/server.h @@ -5,6 +5,10 @@ #include #include +/* The serial-server scenario makes sense only for 1 connected client. + * Allow 1 extra connection to reject new clients with an explanation. */ +#define SERVER_MAX_CONNECTIONS 2 + typedef struct { int socket; /* server socket */