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

This commit is contained in:
Damien George 2016-05-10 23:45:33 +01:00
parent 83a9a723b9
commit 79a38a7a43
2 changed files with 18 additions and 16 deletions

View File

@ -35,6 +35,7 @@
#include "py/objlist.h"
#include "py/stream.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "netutils.h"
#include "modnetwork.h"
#include "pin.h"
@ -125,7 +126,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
if (ip == 0) {
// unknown host
return ENOENT;
return MP_ENOENT;
}
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
STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
if (socket->u_param.domain != MOD_NETWORK_AF_INET) {
*_errno = EAFNOSUPPORT;
*_errno = MP_EAFNOSUPPORT;
return -1;
}
@ -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_DGRAM: type = SOCK_DGRAM; break;
case MOD_NETWORK_SOCK_RAW: type = SOCK_RAW; break;
default: *_errno = EINVAL; return -1;
default: *_errno = MP_EINVAL; return -1;
}
// open socket
@ -201,7 +202,7 @@ STATIC int cc3k_socket_accept(mod_network_socket_obj_t *socket, mod_network_sock
socklen_t addr_len = sizeof(addr);
if ((fd = CC3000_EXPORT(accept)(socket->u_state, &addr, &addr_len)) < 0) {
if (fd == SOC_IN_PROGRESS) {
*_errno = EAGAIN;
*_errno = MP_EAGAIN;
} else {
*_errno = -fd;
}
@ -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) {
if (cc3k_get_fd_closed_state(socket->u_state)) {
CC3000_EXPORT(closesocket)(socket->u_state);
*_errno = EPIPE;
*_errno = MP_EPIPE;
return -1;
}
@ -266,7 +267,7 @@ STATIC mp_uint_t cc3k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, m
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(socket->u_state, &rfds);
timeval tv;
cc3000_timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 1;
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
}
// call cc3000 select with minimum timeout
timeval tv;
cc3000_timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 1;
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
ret |= MP_IOCTL_POLL_HUP;
}
} else {
*_errno = EINVAL;
*_errno = MP_EINVAL;
ret = -1;
}
return ret;

View File

@ -31,6 +31,7 @@
#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "netutils.h"
#include "modnetwork.h"
@ -92,20 +93,20 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len,
return 0;
} else {
// failure
return ENOENT;
return MP_ENOENT;
}
}
STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
if (socket->u_param.domain != MOD_NETWORK_AF_INET) {
*_errno = EAFNOSUPPORT;
*_errno = MP_EAFNOSUPPORT;
return -1;
}
switch (socket->u_param.type) {
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;
default: *_errno = EINVAL; return -1;
default: *_errno = MP_EINVAL; return -1;
}
if (socket->u_param.fileno == -1) {
@ -119,7 +120,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno)
}
if (socket->u_param.fileno == -1) {
// too many open sockets
*_errno = EMFILE;
*_errno = MP_EMFILE;
return -1;
}
}
@ -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) {
wiznet5k_socket_close(socket);
*_errno = ENOTCONN; // ??
*_errno = MP_ENOTCONN; // ??
return -1;
}
HAL_Delay(1);
@ -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) {
// TODO
*_errno = EINVAL;
*_errno = MP_EINVAL;
return -1;
}
STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) {
// TODO
*_errno = EINVAL;
*_errno = MP_EINVAL;
return -1;
/*
@ -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) {
// TODO
*_errno = EINVAL;
*_errno = MP_EINVAL;
return -1;
}