From d4bdb947817f3d0f7400d15c2c90bd425bab3309 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 9 Jun 2016 23:46:03 -0500 Subject: [PATCH] Fixed incorrect semaphore handling on lwip connect and socket_connect - Semaphore returns 0 on timeout, and negative was incorrect used for errors - Correctly checked error code on tcp_connect thanks to @LiyouZhou fixes #284, fixes #285, fixes #166 --- net/LWIPInterface/LWIPInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/LWIPInterface/LWIPInterface.cpp b/net/LWIPInterface/LWIPInterface.cpp index 8e192cb8f8..5edead76fc 100644 --- a/net/LWIPInterface/LWIPInterface.cpp +++ b/net/LWIPInterface/LWIPInterface.cpp @@ -110,7 +110,7 @@ int LWIPInterface::connect() // Wait for an IP Address // -1: error, 0: timeout - if (netif_up.wait(2500) < 0) { + if (netif_up.wait(2500) <= 0) { return NSAPI_ERROR_DHCP_FAILURE; } @@ -291,10 +291,10 @@ int LWIPInterface::socket_connect(void *handle, const SocketAddress &addr) Semaphore connected(0); s->sem = &connected; - tcp_connect(s->tcp, &ip_addr, addr.get_port(), tcp_connect_irq); + err_t err = tcp_connect(s->tcp, &ip_addr, addr.get_port(), tcp_connect_irq); // Wait for connection - if (connected.wait(1500) < 0) { + if (err || connected.wait(1500) <= 0) { return NSAPI_ERROR_NO_CONNECTION; }