Skip to content

Commit 0055457

Browse files
committed
extmod/modlwip: Convert errno's to use MP_Exxx symbols.
1 parent c9a7430 commit 0055457

1 file changed

Lines changed: 57 additions & 57 deletions

File tree

extmod/modlwip.c

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
*/
2727

2828
#include <string.h>
29-
#include <errno.h>
3029
#include <stdio.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/objlist.h"
3433
#include "py/runtime.h"
3534
#include "py/stream.h"
35+
#include "py/mperrno.h"
3636
#include "py/mphal.h"
3737

3838
#include "netutils.h"
@@ -172,45 +172,45 @@ STATIC const mp_obj_type_t lwip_slip_type = {
172172
// investigate in more detail.
173173
#if LWIP_VERSION < 0x01040100
174174
static const int error_lookup_table[] = {
175-
0, /* ERR_OK 0 No error, everything OK. */
176-
ENOMEM, /* ERR_MEM -1 Out of memory error. */
177-
ENOBUFS, /* ERR_BUF -2 Buffer error. */
178-
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
179-
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
180-
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
181-
EINVAL, /* ERR_VAL -6 Illegal value. */
182-
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
183-
184-
ECONNABORTED, /* ERR_ABRT -8 Connection aborted. */
185-
ECONNRESET, /* ERR_RST -9 Connection reset. */
186-
ENOTCONN, /* ERR_CLSD -10 Connection closed. */
187-
ENOTCONN, /* ERR_CONN -11 Not connected. */
188-
EIO, /* ERR_ARG -12 Illegal argument. */
189-
EADDRINUSE, /* ERR_USE -13 Address in use. */
190-
-1, /* ERR_IF -14 Low-level netif error */
191-
EALREADY, /* ERR_ISCONN -15 Already connected. */
192-
EBADF, /* _ERR_BADF -16 Closed socket (null pcb) */
175+
0, /* ERR_OK 0 No error, everything OK. */
176+
MP_ENOMEM, /* ERR_MEM -1 Out of memory error. */
177+
MP_ENOBUFS, /* ERR_BUF -2 Buffer error. */
178+
MP_EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
179+
MP_EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
180+
MP_EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
181+
MP_EINVAL, /* ERR_VAL -6 Illegal value. */
182+
MP_EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
183+
184+
MP_ECONNABORTED, /* ERR_ABRT -8 Connection aborted. */
185+
MP_ECONNRESET, /* ERR_RST -9 Connection reset. */
186+
MP_ENOTCONN, /* ERR_CLSD -10 Connection closed. */
187+
MP_ENOTCONN, /* ERR_CONN -11 Not connected. */
188+
MP_EIO, /* ERR_ARG -12 Illegal argument. */
189+
MP_EADDRINUSE, /* ERR_USE -13 Address in use. */
190+
-1, /* ERR_IF -14 Low-level netif error */
191+
MP_EALREADY, /* ERR_ISCONN -15 Already connected. */
192+
MP_EBADF, /* _ERR_BADF -16 Closed socket (null pcb) */
193193
};
194194
#else
195195
static const int error_lookup_table[] = {
196-
0, /* ERR_OK 0 No error, everything OK. */
197-
ENOMEM, /* ERR_MEM -1 Out of memory error. */
198-
ENOBUFS, /* ERR_BUF -2 Buffer error. */
199-
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
200-
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
201-
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
202-
EINVAL, /* ERR_VAL -6 Illegal value. */
203-
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
204-
205-
EADDRINUSE, /* ERR_USE -8 Address in use. */
206-
EALREADY, /* ERR_ISCONN -9 Already connected. */
207-
ECONNABORTED, /* ERR_ABRT -10 Connection aborted. */
208-
ECONNRESET, /* ERR_RST -11 Connection reset. */
209-
ENOTCONN, /* ERR_CLSD -12 Connection closed. */
210-
ENOTCONN, /* ERR_CONN -13 Not connected. */
211-
EIO, /* ERR_ARG -14 Illegal argument. */
212-
-1, /* ERR_IF -15 Low-level netif error */
213-
EBADF, /* _ERR_BADF -16 Closed socket (null pcb) */
196+
0, /* ERR_OK 0 No error, everything OK. */
197+
MP_ENOMEM, /* ERR_MEM -1 Out of memory error. */
198+
MP_ENOBUFS, /* ERR_BUF -2 Buffer error. */
199+
MP_EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
200+
MP_EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
201+
MP_EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
202+
MP_EINVAL, /* ERR_VAL -6 Illegal value. */
203+
MP_EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
204+
205+
MP_EADDRINUSE, /* ERR_USE -8 Address in use. */
206+
MP_EALREADY, /* ERR_ISCONN -9 Already connected. */
207+
MP_ECONNABORTED, /* ERR_ABRT -10 Connection aborted. */
208+
MP_ECONNRESET, /* ERR_RST -11 Connection reset. */
209+
MP_ENOTCONN, /* ERR_CLSD -12 Connection closed. */
210+
MP_ENOTCONN, /* ERR_CONN -13 Not connected. */
211+
MP_EIO, /* ERR_ARG -14 Illegal argument. */
212+
-1, /* ERR_IF -15 Low-level netif error */
213+
MP_EBADF, /* _ERR_BADF -16 Closed socket (null pcb) */
214214
};
215215
#endif
216216

@@ -363,7 +363,7 @@ STATIC mp_uint_t lwip_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
363363
// FIXME: maybe PBUF_ROM?
364364
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
365365
if (p == NULL) {
366-
*_errno = ENOMEM;
366+
*_errno = MP_ENOMEM;
367367
return -1;
368368
}
369369

@@ -401,7 +401,7 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
401401
if (socket->incoming.pbuf != NULL) break;
402402
}
403403
if (socket->incoming.pbuf == NULL) {
404-
*_errno = ETIMEDOUT;
404+
*_errno = MP_ETIMEDOUT;
405405
return -1;
406406
}
407407
} else {
@@ -444,7 +444,7 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
444444
if (available == 0) {
445445
// Non-blocking socket
446446
if (socket->timeout == 0) {
447-
*_errno = EAGAIN;
447+
*_errno = MP_EAGAIN;
448448
return MP_STREAM_ERROR;
449449
}
450450

@@ -457,7 +457,7 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
457457
// Avoid sending too small packets, so wait until at least 16 bytes available
458458
while (socket->state >= STATE_CONNECTED && (available = tcp_sndbuf(socket->pcb.tcp)) < 16) {
459459
if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) {
460-
*_errno = ETIMEDOUT;
460+
*_errno = MP_ETIMEDOUT;
461461
return MP_STREAM_ERROR;
462462
}
463463
poll_sockets();
@@ -491,14 +491,14 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
491491
if (socket->state == STATE_PEER_CLOSED) {
492492
return 0;
493493
}
494-
*_errno = EAGAIN;
494+
*_errno = MP_EAGAIN;
495495
return -1;
496496
}
497497

498498
mp_uint_t start = mp_hal_ticks_ms();
499499
while (socket->state == STATE_CONNECTED && socket->incoming.pbuf == NULL) {
500500
if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) {
501-
*_errno = ETIMEDOUT;
501+
*_errno = MP_ETIMEDOUT;
502502
return -1;
503503
}
504504
poll_sockets();
@@ -570,11 +570,11 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args
570570
case MOD_NETWORK_SOCK_STREAM: socket->pcb.tcp = tcp_new(); break;
571571
case MOD_NETWORK_SOCK_DGRAM: socket->pcb.udp = udp_new(); break;
572572
//case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
573-
default: nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
573+
default: nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EINVAL)));
574574
}
575575

576576
if (socket->pcb.tcp == NULL) {
577-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOMEM)));
577+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOMEM)));
578578
}
579579

580580
switch (socket->type) {
@@ -670,15 +670,15 @@ STATIC mp_obj_t lwip_socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
670670
mp_int_t backlog = mp_obj_get_int(backlog_in);
671671

672672
if (socket->pcb.tcp == NULL) {
673-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EBADF)));
673+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EBADF)));
674674
}
675675
if (socket->type != MOD_NETWORK_SOCK_STREAM) {
676-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EOPNOTSUPP)));
676+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EOPNOTSUPP)));
677677
}
678678

679679
struct tcp_pcb *new_pcb = tcp_listen_with_backlog(socket->pcb.tcp, (u8_t)backlog);
680680
if (new_pcb == NULL) {
681-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOMEM)));
681+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOMEM)));
682682
}
683683
socket->pcb.tcp = new_pcb;
684684
tcp_accept(new_pcb, _lwip_tcp_accept);
@@ -691,15 +691,15 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
691691
lwip_socket_obj_t *socket = self_in;
692692

693693
if (socket->pcb.tcp == NULL) {
694-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EBADF)));
694+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EBADF)));
695695
}
696696
if (socket->type != MOD_NETWORK_SOCK_STREAM) {
697-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EOPNOTSUPP)));
697+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EOPNOTSUPP)));
698698
}
699699
// I need to do this because "tcp_accepted", later, is a macro.
700700
struct tcp_pcb *listener = socket->pcb.tcp;
701701
if (listener->state != LISTEN) {
702-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
702+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EINVAL)));
703703
}
704704

705705
// accept incoming connection
@@ -710,7 +710,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
710710
if (socket->incoming.connection != NULL) break;
711711
}
712712
if (socket->incoming.connection == NULL) {
713-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ETIMEDOUT)));
713+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ETIMEDOUT)));
714714
}
715715
} else {
716716
while (socket->incoming.connection == NULL) {
@@ -757,7 +757,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
757757
lwip_socket_obj_t *socket = self_in;
758758

759759
if (socket->pcb.tcp == NULL) {
760-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EBADF)));
760+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EBADF)));
761761
}
762762

763763
// get address
@@ -772,9 +772,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
772772
case MOD_NETWORK_SOCK_STREAM: {
773773
if (socket->state != STATE_NEW) {
774774
if (socket->state == STATE_CONNECTED) {
775-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EALREADY)));
775+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EALREADY)));
776776
} else {
777-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINPROGRESS)));
777+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EINPROGRESS)));
778778
}
779779
}
780780
// Register our recieve callback.
@@ -794,7 +794,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
794794
if (socket->state != STATE_CONNECTING) break;
795795
}
796796
if (socket->state == STATE_CONNECTING) {
797-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ETIMEDOUT)));
797+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ETIMEDOUT)));
798798
}
799799
} else {
800800
while (socket->state == STATE_CONNECTING) {
@@ -982,7 +982,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
982982
// most useful behavior is: check whether we will be able to send all of input
983983
// data without EAGAIN, and if won't be, raise it without sending any.
984984
if (bufinfo.len > tcp_sndbuf(socket->pcb.tcp)) {
985-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EAGAIN)));
985+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EAGAIN)));
986986
}
987987
}
988988
// TODO: In CPython3.5, socket timeout should apply to the

0 commit comments

Comments
 (0)