Skip to content

Commit 4d55d88

Browse files
committed
cc3200/modusocket: Fix connect() when in non-blocking or timeout mode.
Non-blocking connect on the CC3100 has non-POSIX behaviour and needs to be modified to match standard semantics.
1 parent ad3abcd commit 4d55d88

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

cc3200/mods/modusocket.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,30 @@ STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_ob
167167
STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
168168
MAKE_SOCKADDR(addr, ip, port)
169169
uint32_t timeout_ms = s->sock_base.timeout_ms;
170+
171+
// For a non-blocking connect the CC3100 will return SL_EALREADY while the
172+
// connection is in progress.
173+
170174
for (;;) {
171175
int ret = sl_Connect(s->sock_base.sd, &addr, sizeof(addr));
172176
if (ret == 0) {
173177
return 0;
174178
}
175-
if (check_timedout(s, ret, &timeout_ms, _errno)) {
179+
180+
// Check if we are in non-blocking mode and the connection is in progress
181+
if (s->sock_base.timeout_ms == 0 && ret == SL_EALREADY) {
182+
// To match BSD we return EINPROGRESS here
183+
*_errno = MP_EINPROGRESS;
184+
return -1;
185+
}
186+
187+
// We are in blocking mode, so if the connection isn't in progress then error out
188+
if (ret != SL_EALREADY) {
189+
*_errno = convert_sl_errno(ret);
190+
return -1;
191+
}
192+
193+
if (check_timedout(s, SL_EAGAIN, &timeout_ms, _errno)) {
176194
return -1;
177195
}
178196
}

0 commit comments

Comments
 (0)