Skip to content

Commit 5ebf397

Browse files
author
Daniel Campora
committed
cc3200: Correct socket settimeout time format.
1 parent 9780e55 commit 5ebf397

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

cc3200/mods/modusocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
358358
if (timeout_in == mp_const_none) {
359359
timeout = -1;
360360
} else {
361-
timeout = 1000 * mp_obj_get_int(timeout_in);
361+
timeout = mp_obj_get_int(timeout_in);
362362
}
363363
int _errno;
364364
if (wlan_socket_settimeout(self, timeout, &_errno) != 0) {

cc3200/mods/modwlan.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,21 +1279,24 @@ int wlan_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp
12791279
return 0;
12801280
}
12811281

1282-
int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_ms, int *_errno) {
1282+
int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
12831283
int ret;
1284-
if (timeout_ms == 0 || timeout_ms == -1) {
1285-
int optval;
1286-
if (timeout_ms == 0) {
1284+
if (timeout_s == 0 || timeout_s == -1) {
1285+
SlSockNonblocking_t option;
1286+
if (timeout_s == 0) {
12871287
// set non-blocking mode
1288-
optval = 1;
1288+
option.NonblockingEnabled = 1;
12891289
} else {
12901290
// set blocking mode
1291-
optval = 0;
1291+
option.NonblockingEnabled = 0;
12921292
}
1293-
ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_NONBLOCKING, &optval, sizeof(optval));
1293+
ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_NONBLOCKING, &option, sizeof(option));
12941294
} else {
12951295
// set timeout
1296-
ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_RCVTIMEO, &timeout_ms, sizeof(timeout_ms));
1296+
struct SlTimeval_t timeVal;
1297+
timeVal.tv_sec = timeout_s; // seconds
1298+
timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution
1299+
ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_RCVTIMEO, &timeVal, sizeof(timeVal));
12971300
}
12981301

12991302
if (ret != 0) {

cc3200/mods/modwlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extern int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t le
7676
extern int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno);
7777
extern int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno);
7878
extern int wlan_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno);
79-
extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_ms, int *_errno);
79+
extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno);
8080
extern int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno);
8181

8282
#endif /* MODWLAN_H_ */

0 commit comments

Comments
 (0)