Skip to content

Commit

Permalink
stmhal: For network drivers, convert to use MP_Exxx errno symbols.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed May 10, 2016
1 parent 83a9a72 commit 79a38a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions stmhal/modnwcc3k.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions stmhal/modnwwiznet5k.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

/*
Expand All @@ -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;
}

Expand Down

0 comments on commit 79a38a7

Please sign in to comment.