Commit 79a38a7a authored by Damien George's avatar Damien George
Browse files

stmhal: For network drivers, convert to use MP_Exxx errno symbols.

parent 83a9a723
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "py/objlist.h" #include "py/objlist.h"
#include "py/stream.h" #include "py/stream.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mperrno.h"
#include "netutils.h" #include "netutils.h"
#include "modnetwork.h" #include "modnetwork.h"
#include "pin.h" #include "pin.h"
...@@ -125,7 +126,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin ...@@ -125,7 +126,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
if (ip == 0) { if (ip == 0) {
// unknown host // unknown host
return ENOENT; return MP_ENOENT;
} }
out_ip[0] = ip >> 24; out_ip[0] = ip >> 24;
...@@ -138,7 +139,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin ...@@ -138,7 +139,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
if (socket->u_param.domain != MOD_NETWORK_AF_INET) { if (socket->u_param.domain != MOD_NETWORK_AF_INET) {
*_errno = EAFNOSUPPORT; *_errno = MP_EAFNOSUPPORT;
return -1; return -1;
} }
...@@ -147,7 +148,7 @@ STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { ...@@ -147,7 +148,7 @@ STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
case MOD_NETWORK_SOCK_STREAM: type = SOCK_STREAM; break; case MOD_NETWORK_SOCK_STREAM: type = SOCK_STREAM; break;
case MOD_NETWORK_SOCK_DGRAM: type = SOCK_DGRAM; break; case MOD_NETWORK_SOCK_DGRAM: type = SOCK_DGRAM; break;
case MOD_NETWORK_SOCK_RAW: type = SOCK_RAW; break; case MOD_NETWORK_SOCK_RAW: type = SOCK_RAW; break;
default: *_errno = EINVAL; return -1; default: *_errno = MP_EINVAL; return -1;
} }
// open socket // open socket
...@@ -201,7 +202,7 @@ STATIC int cc3k_socket_accept(mod_network_socket_obj_t *socket, mod_network_sock ...@@ -201,7 +202,7 @@ STATIC int cc3k_socket_accept(mod_network_socket_obj_t *socket, mod_network_sock
socklen_t addr_len = sizeof(addr); socklen_t addr_len = sizeof(addr);
if ((fd = CC3000_EXPORT(accept)(socket->u_state, &addr, &addr_len)) < 0) { if ((fd = CC3000_EXPORT(accept)(socket->u_state, &addr, &addr_len)) < 0) {
if (fd == SOC_IN_PROGRESS) { if (fd == SOC_IN_PROGRESS) {
*_errno = EAGAIN; *_errno = MP_EAGAIN;
} else { } else {
*_errno = -fd; *_errno = -fd;
} }
...@@ -239,7 +240,7 @@ STATIC int cc3k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_ui ...@@ -239,7 +240,7 @@ STATIC int cc3k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_ui
STATIC mp_uint_t cc3k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { STATIC mp_uint_t cc3k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
if (cc3k_get_fd_closed_state(socket->u_state)) { if (cc3k_get_fd_closed_state(socket->u_state)) {
CC3000_EXPORT(closesocket)(socket->u_state); CC3000_EXPORT(closesocket)(socket->u_state);
*_errno = EPIPE; *_errno = MP_EPIPE;
return -1; return -1;
} }
...@@ -266,7 +267,7 @@ STATIC mp_uint_t cc3k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, m ...@@ -266,7 +267,7 @@ STATIC mp_uint_t cc3k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, m
fd_set rfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(socket->u_state, &rfds); FD_SET(socket->u_state, &rfds);
timeval tv; cc3000_timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1; tv.tv_usec = 1;
int nfds = CC3000_EXPORT(select)(socket->u_state + 1, &rfds, NULL, NULL, &tv); int nfds = CC3000_EXPORT(select)(socket->u_state + 1, &rfds, NULL, NULL, &tv);
...@@ -382,7 +383,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request ...@@ -382,7 +383,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
} }
// call cc3000 select with minimum timeout // call cc3000 select with minimum timeout
timeval tv; cc3000_timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1; tv.tv_usec = 1;
int nfds = CC3000_EXPORT(select)(fd + 1, &rfds, &wfds, &xfds, &tv); int nfds = CC3000_EXPORT(select)(fd + 1, &rfds, &wfds, &xfds, &tv);
...@@ -404,7 +405,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request ...@@ -404,7 +405,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
ret |= MP_IOCTL_POLL_HUP; ret |= MP_IOCTL_POLL_HUP;
} }
} else { } else {
*_errno = EINVAL; *_errno = MP_EINVAL;
ret = -1; ret = -1;
} }
return ret; return ret;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/objlist.h" #include "py/objlist.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h" #include "py/mphal.h"
#include "netutils.h" #include "netutils.h"
#include "modnetwork.h" #include "modnetwork.h"
...@@ -92,20 +93,20 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, ...@@ -92,20 +93,20 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len,
return 0; return 0;
} else { } else {
// failure // failure
return ENOENT; return MP_ENOENT;
} }
} }
STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
if (socket->u_param.domain != MOD_NETWORK_AF_INET) { if (socket->u_param.domain != MOD_NETWORK_AF_INET) {
*_errno = EAFNOSUPPORT; *_errno = MP_EAFNOSUPPORT;
return -1; return -1;
} }
switch (socket->u_param.type) { switch (socket->u_param.type) {
case MOD_NETWORK_SOCK_STREAM: socket->u_param.type = Sn_MR_TCP; break; case MOD_NETWORK_SOCK_STREAM: socket->u_param.type = Sn_MR_TCP; break;
case MOD_NETWORK_SOCK_DGRAM: socket->u_param.type = Sn_MR_UDP; break; case MOD_NETWORK_SOCK_DGRAM: socket->u_param.type = Sn_MR_UDP; break;
default: *_errno = EINVAL; return -1; default: *_errno = MP_EINVAL; return -1;
} }
if (socket->u_param.fileno == -1) { if (socket->u_param.fileno == -1) {
...@@ -119,7 +120,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) ...@@ -119,7 +120,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno)
} }
if (socket->u_param.fileno == -1) { if (socket->u_param.fileno == -1) {
// too many open sockets // too many open sockets
*_errno = EMFILE; *_errno = MP_EMFILE;
return -1; return -1;
} }
} }
...@@ -198,7 +199,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_ ...@@ -198,7 +199,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_
} }
if (sr == SOCK_CLOSED || sr == SOCK_CLOSE_WAIT) { if (sr == SOCK_CLOSED || sr == SOCK_CLOSE_WAIT) {
wiznet5k_socket_close(socket); wiznet5k_socket_close(socket);
*_errno = ENOTCONN; // ?? *_errno = MP_ENOTCONN; // ??
return -1; return -1;
} }
HAL_Delay(1); HAL_Delay(1);
...@@ -276,13 +277,13 @@ STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte ...@@ -276,13 +277,13 @@ STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte
STATIC int wiznet5k_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) { STATIC int wiznet5k_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) {
// TODO // TODO
*_errno = EINVAL; *_errno = MP_EINVAL;
return -1; return -1;
} }
STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) { STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) {
// TODO // TODO
*_errno = EINVAL; *_errno = MP_EINVAL;
return -1; return -1;
/* /*
...@@ -296,7 +297,7 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_ ...@@ -296,7 +297,7 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_
STATIC int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { STATIC int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) {
// TODO // TODO
*_errno = EINVAL; *_errno = MP_EINVAL;
return -1; return -1;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment