Skip to content

Commit d82bbb1

Browse files
committed
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 ARMmbed#284, fixes ARMmbed#285, fixes ARMmbed#166
1 parent df5c05f commit d82bbb1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

LWIPInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int LWIPInterface::connect()
110110

111111
// Wait for an IP Address
112112
// -1: error, 0: timeout
113-
if (netif_up.wait(2500) < 0) {
113+
if (netif_up.wait(2500) <= 0) {
114114
return NSAPI_ERROR_DHCP_FAILURE;
115115
}
116116

@@ -291,10 +291,10 @@ int LWIPInterface::socket_connect(void *handle, const SocketAddress &addr)
291291
Semaphore connected(0);
292292
s->sem = &connected;
293293

294-
tcp_connect(s->tcp, &ip_addr, addr.get_port(), tcp_connect_irq);
294+
err_t err = tcp_connect(s->tcp, &ip_addr, addr.get_port(), tcp_connect_irq);
295295

296296
// Wait for connection
297-
if (connected.wait(1500) < 0) {
297+
if (err || connected.wait(1500) <= 0) {
298298
return NSAPI_ERROR_NO_CONNECTION;
299299
}
300300

0 commit comments

Comments
 (0)