From ca80c0b8e207f28e90861eaa4eeda4dcfaa0f689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mayoral=20Vilches?= Date: Fri, 20 Jun 2014 14:19:03 +0200 Subject: [PATCH] HAL_Linux: config UART file descriptor as non-blocking --- libraries/AP_HAL_Linux/UARTDriver.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_Linux/UARTDriver.cpp b/libraries/AP_HAL_Linux/UARTDriver.cpp index 15bb8eeab8..67da8a771b 100644 --- a/libraries/AP_HAL_Linux/UARTDriver.cpp +++ b/libraries/AP_HAL_Linux/UARTDriver.cpp @@ -294,12 +294,12 @@ void LinuxUARTDriver::_tcp_start_connection(bool wait_for_connection) printf("Serial port %u on TCP port %u\n", portNumber, _base_port + portNumber); - // fflush(stdout); + fflush(stdout); } if (wait_for_connection) { printf("Waiting for connection ....\n"); - // fflush(stdout); + fflush(stdout); net_fd = accept(listen_fd, NULL, NULL); if (net_fd == -1) { printf("accept() error - %s", strerror(errno)); @@ -307,6 +307,11 @@ void LinuxUARTDriver::_tcp_start_connection(bool wait_for_connection) } setsockopt(net_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); setsockopt(net_fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); + + // always run the file descriptor non-blocking, and deal with | + // blocking IO in the higher level calls + fcntl(net_fd, F_SETFL, fcntl(net_fd, F_GETFL, 0) | O_NONBLOCK); + _connected = true; _rd_fd = net_fd; _wr_fd = net_fd;