Skip to content

Commit a243d6b

Browse files
author
Daniel Campora
committed
cc3200: Make socket stream methods return POSIX error codes.
1 parent f738424 commit a243d6b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

cc3200/mods/modusocket.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,24 @@ MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
418418

419419
STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
420420
mod_network_socket_obj_t *self = self_in;
421-
return wlan_socket_recv(self, buf, size, errcode);
421+
mp_int_t ret = wlan_socket_recv(self, buf, size, errcode);
422+
if (ret < 0) {
423+
ret = MP_STREAM_ERROR;
424+
// needed to convert simplelink's negative error codes to POSIX
425+
(*errcode) *= -1;
426+
}
427+
return ret;
422428
}
423429

424430
STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
425431
mod_network_socket_obj_t *self = self_in;
426-
return wlan_socket_send(self, buf, size, errcode);
432+
mp_int_t ret = wlan_socket_send(self, buf, size, errcode);
433+
if (ret < 0) {
434+
ret = MP_STREAM_ERROR;
435+
// needed to convert simplelink's negative error codes to POSIX
436+
(*errcode) *= -1;
437+
}
438+
return ret;
427439
}
428440

429441
STATIC mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {

cc3200/mods/modwlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t
13571357
}
13581358
} else {
13591359
*_errno = EINVAL;
1360-
ret = -1;
1360+
ret = MP_STREAM_ERROR;
13611361
}
13621362
return ret;
13631363
}

0 commit comments

Comments
 (0)