diff --git a/lib/device/adamnet/keyboard.cpp b/lib/device/adamnet/keyboard.cpp index 429f2f6cc..3855bf9a8 100644 --- a/lib/device/adamnet/keyboard.cpp +++ b/lib/device/adamnet/keyboard.cpp @@ -35,7 +35,7 @@ void adamKeyboard::adamnet_control_receive() { AdamNet.wait_for_idle(); adamnet_send(0xC1); // NAK - client = server->available(); + client = server->client(); } else if (!client.connected()) { @@ -99,4 +99,4 @@ void adamKeyboard::adamnet_process(uint8_t b) void adamKeyboard::shutdown() { } -#endif /* BUILD_ADAM */ \ No newline at end of file +#endif /* BUILD_ADAM */ diff --git a/lib/device/adamnet/modem.cpp b/lib/device/adamnet/modem.cpp index 0c72147fc..e0c1d7894 100755 --- a/lib/device/adamnet/modem.cpp +++ b/lib/device/adamnet/modem.cpp @@ -481,7 +481,7 @@ void adamModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); @@ -1269,4 +1269,4 @@ void adamModem::adamnet_process(uint8_t b) } -#endif /* BUILD_ADAM */ \ No newline at end of file +#endif /* BUILD_ADAM */ diff --git a/lib/device/comlynx/keyboard.cpp b/lib/device/comlynx/keyboard.cpp index 2d4091509..d09400742 100644 --- a/lib/device/comlynx/keyboard.cpp +++ b/lib/device/comlynx/keyboard.cpp @@ -35,7 +35,7 @@ void lynxKeyboard::comlynx_control_receive() { ComLynx.wait_for_idle(); comlynx_send(0xC1); // NAK - client = server->available(); + client = server->client(); } else if (!client.connected()) { diff --git a/lib/device/comlynx/modem.cpp b/lib/device/comlynx/modem.cpp index 636576fa6..49c74b973 100755 --- a/lib/device/comlynx/modem.cpp +++ b/lib/device/comlynx/modem.cpp @@ -481,7 +481,7 @@ void lynxModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/drivewire/modem.cpp b/lib/device/drivewire/modem.cpp index e12781221..c23a951f5 100644 --- a/lib/device/drivewire/modem.cpp +++ b/lib/device/drivewire/modem.cpp @@ -459,7 +459,7 @@ void drivewireModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/h89/modem.cpp b/lib/device/h89/modem.cpp index fdd0a7e5d..77d09cc0c 100644 --- a/lib/device/h89/modem.cpp +++ b/lib/device/h89/modem.cpp @@ -455,7 +455,7 @@ void H89Modem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/iwm/modem.cpp b/lib/device/iwm/modem.cpp index fe2c4647c..f08f064ac 100644 --- a/lib/device/iwm/modem.cpp +++ b/lib/device/iwm/modem.cpp @@ -565,7 +565,7 @@ void iwmModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/mac/modem.cpp b/lib/device/mac/modem.cpp index a5cf4a533..21bcd08ab 100644 --- a/lib/device/mac/modem.cpp +++ b/lib/device/mac/modem.cpp @@ -596,7 +596,7 @@ void iwmModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/new/keyboard.cpp b/lib/device/new/keyboard.cpp index b9170014d..87a37cb48 100644 --- a/lib/device/new/keyboard.cpp +++ b/lib/device/new/keyboard.cpp @@ -35,7 +35,7 @@ void adamKeyboard::adamnet_control_receive() { AdamNet.wait_for_idle(); adamnet_send(0xC1); // NAK - client = server->available(); + client = server->client(); } else if (!client.connected()) { diff --git a/lib/device/new/modem.cpp b/lib/device/new/modem.cpp index d2843e2c0..88f220772 100755 --- a/lib/device/new/modem.cpp +++ b/lib/device/new/modem.cpp @@ -481,7 +481,7 @@ void adamModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/new/serial.cpp b/lib/device/new/serial.cpp index 757f3d362..a7f3ab006 100644 --- a/lib/device/new/serial.cpp +++ b/lib/device/new/serial.cpp @@ -65,7 +65,7 @@ void adamSerial::adamnet_response_status() if (!client.connected() && server->hasClient()) { // Accept waiting connection - client = server->available(); + client = server->client(); } if (client.available()) diff --git a/lib/device/rc2014/modem.cpp b/lib/device/rc2014/modem.cpp index 39ae005f7..7f0f28cc8 100644 --- a/lib/device/rc2014/modem.cpp +++ b/lib/device/rc2014/modem.cpp @@ -524,7 +524,7 @@ void rc2014Modem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/rs232/modem.cpp b/lib/device/rs232/modem.cpp index 9814c6e6b..fcfa5e770 100755 --- a/lib/device/rs232/modem.cpp +++ b/lib/device/rs232/modem.cpp @@ -1017,7 +1017,7 @@ void rs232Modem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/s100spi/modem.cpp b/lib/device/s100spi/modem.cpp index 2f0b9809f..13a01424e 100644 --- a/lib/device/s100spi/modem.cpp +++ b/lib/device/s100spi/modem.cpp @@ -481,7 +481,7 @@ void s100spiModem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/device/sio/modem.cpp b/lib/device/sio/modem.cpp index 38190c924..7e0946b11 100755 --- a/lib/device/sio/modem.cpp +++ b/lib/device/sio/modem.cpp @@ -1058,7 +1058,7 @@ void modem::at_handle_answer() Debug_printf("HANDLE ANSWER !!!\n"); if (tcpServer.hasClient()) { - tcpClient = tcpServer.available(); + tcpClient = tcpServer.client(); tcpClient.setNoDelay(true); // try to disable naggle // tcpServer.stop(); answerTimer = fnSystem.millis(); diff --git a/lib/network-protocol/TCP.cpp b/lib/network-protocol/TCP.cpp index f89c9a4d3..db7e833ea 100755 --- a/lib/network-protocol/TCP.cpp +++ b/lib/network-protocol/TCP.cpp @@ -362,7 +362,7 @@ bool NetworkProtocolTCP::special_accept_connection() unsigned char remotePort; char *remoteIPString; - client = server->available(); + client = server->client(); if (client.connected()) { @@ -422,4 +422,4 @@ bool NetworkProtocolTCP::special_close_client_connection() client.stop(); return false; -} \ No newline at end of file +} diff --git a/lib/tcpip/fnTcpServer.cpp b/lib/tcpip/fnTcpServer.cpp index d438e9a0c..a0fc80c89 100644 --- a/lib/tcpip/fnTcpServer.cpp +++ b/lib/tcpip/fnTcpServer.cpp @@ -31,17 +31,6 @@ int fnTcpServer::begin(uint16_t port) return 0; } - // Bind socket to our interface - struct sockaddr_in server; - server.sin_family = AF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = htons(_port); - if (bind(_sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) - { - Debug_printf("fnTcpServer::begin failed to bind socket, err %d\r\n", compat_getsockerr()); - return 0; - } - int enable = 1; #if defined(_WIN32) if (setsockopt(_sockfd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &enable, sizeof(enable)) != 0) @@ -59,6 +48,17 @@ int fnTcpServer::begin(uint16_t port) Debug_printf("Max clients is currently %u\r\n",_max_clients); + // Bind socket to our interface + struct sockaddr_in server; + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(_port); + if (bind(_sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) + { + Debug_printf("fnTcpServer::begin failed to bind socket, err %d\r\n", compat_getsockerr()); + return 0; + } + // Now listen in on this socket if (listen(_sockfd, _max_clients) < 0) { @@ -107,7 +107,7 @@ bool fnTcpServer::hasClient() // Returns a new fnTcpClient initialized with the client currently connected to the socket // or disconnected (uninitialized) fnTcpClient -fnTcpClient fnTcpServer::available() +fnTcpClient fnTcpServer::client() { // Return initialized fnTcpClient if we're not in listening mode if (!_listening) diff --git a/lib/tcpip/fnTcpServer.h b/lib/tcpip/fnTcpServer.h index 9ec638145..fe0309418 100644 --- a/lib/tcpip/fnTcpServer.h +++ b/lib/tcpip/fnTcpServer.h @@ -23,14 +23,14 @@ class fnTcpServer int begin(uint16_t port=0); - fnTcpClient accept(){ return available(); } + fnTcpClient accept(){ return client(); } void setNoDelay(bool nodelay) { _noDelay = nodelay; }; bool getNoDelay() {return _noDelay; }; int setTimeout(uint32_t seconds); void setMaxClients(int maxClients) { _max_clients = maxClients; } bool hasClient(); - fnTcpClient available(); + fnTcpClient client(); void stop();