Skip to content

Commit 5da8de2

Browse files
committed
extmod/modlwip: Fix error codes for duplicate calls to connect().
If socket is already connected, POSIX requires returning EISCONN. If connection was requested, but not yet complete (for non-blocking socket), error code is EALREADY. http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
1 parent a0dbbbe commit 5da8de2

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

extmod/modlwip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
800800
case MOD_NETWORK_SOCK_STREAM: {
801801
if (socket->state != STATE_NEW) {
802802
if (socket->state == STATE_CONNECTED) {
803-
mp_raise_OSError(MP_EALREADY);
803+
mp_raise_OSError(MP_EISCONN);
804804
} else {
805-
mp_raise_OSError(MP_EINPROGRESS);
805+
mp_raise_OSError(MP_EALREADY);
806806
}
807807
}
808808
// Register our receive callback.

py/mperrno.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define MP_ECONNABORTED (103) // Software caused connection abort
7474
#define MP_ECONNRESET (104) // Connection reset by peer
7575
#define MP_ENOBUFS (105) // No buffer space available
76+
#define MP_EISCONN (106) // Transport endpoint is already connected
7677
#define MP_ENOTCONN (107) // Transport endpoint is not connected
7778
#define MP_ETIMEDOUT (110) // Connection timed out
7879
#define MP_ECONNREFUSED (111) // Connection refused
@@ -127,6 +128,7 @@
127128
#define MP_ECONNABORTED ECONNABORTED
128129
#define MP_ECONNRESET ECONNRESET
129130
#define MP_ENOBUFS ENOBUFS
131+
#define MP_EISCONN EISCONN
130132
#define MP_ENOTCONN ENOTCONN
131133
#define MP_ETIMEDOUT ETIMEDOUT
132134
#define MP_ECONNREFUSED ECONNREFUSED

0 commit comments

Comments
 (0)