summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc3200/mods/modusocket.c2
-rw-r--r--cc3200/mods/modwlan.c19
-rw-r--r--cc3200/mods/modwlan.h2
3 files changed, 13 insertions, 10 deletions
diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c
index e6ab2a754..87b9ebdb5 100644
--- a/cc3200/mods/modusocket.c
+++ b/cc3200/mods/modusocket.c
@@ -358,7 +358,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
if (timeout_in == mp_const_none) {
timeout = -1;
} else {
- timeout = 1000 * mp_obj_get_int(timeout_in);
+ timeout = mp_obj_get_int(timeout_in);
}
int _errno;
if (wlan_socket_settimeout(self, timeout, &_errno) != 0) {
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c
index 664bbf054..7c6732855 100644
--- a/cc3200/mods/modwlan.c
+++ b/cc3200/mods/modwlan.c
@@ -1279,21 +1279,24 @@ int wlan_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp
return 0;
}
-int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_ms, int *_errno) {
+int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) {
int ret;
- if (timeout_ms == 0 || timeout_ms == -1) {
- int optval;
- if (timeout_ms == 0) {
+ if (timeout_s == 0 || timeout_s == -1) {
+ SlSockNonblocking_t option;
+ if (timeout_s == 0) {
// set non-blocking mode
- optval = 1;
+ option.NonblockingEnabled = 1;
} else {
// set blocking mode
- optval = 0;
+ option.NonblockingEnabled = 0;
}
- ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_NONBLOCKING, &optval, sizeof(optval));
+ ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_NONBLOCKING, &option, sizeof(option));
} else {
// set timeout
- ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_RCVTIMEO, &timeout_ms, sizeof(timeout_ms));
+ struct SlTimeval_t timeVal;
+ timeVal.tv_sec = timeout_s; // seconds
+ timeVal.tv_usec = 0; // microseconds. 10000 microseconds resolution
+ ret = sl_SetSockOpt(s->sd, SOL_SOCKET, SO_RCVTIMEO, &timeVal, sizeof(timeVal));
}
if (ret != 0) {
diff --git a/cc3200/mods/modwlan.h b/cc3200/mods/modwlan.h
index 82fe4f8c6..a811afdd7 100644
--- a/cc3200/mods/modwlan.h
+++ b/cc3200/mods/modwlan.h
@@ -76,7 +76,7 @@ extern int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t le
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);
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);
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);
-extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_ms, int *_errno);
+extern int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno);
extern int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno);
#endif /* MODWLAN_H_ */