esp32/modsocket: Remove unix socket error code translation.

The ESP-IDF has its own errno codes which should propagate out to the user.
This commit is contained in:
Thorsten von Eicken 2020-10-24 12:34:23 -07:00 committed by Damien George
parent f12462ddc4
commit 771376a0cb
1 changed files with 9 additions and 19 deletions

View File

@ -140,16 +140,6 @@ void usocket_events_handler(void) {
#endif // MICROPY_PY_USOCKET_EVENTS
NORETURN static void exception_from_errno(int _errno) {
// Here we need to convert from lwip errno values to MicroPython's standard ones
if (_errno == EADDRINUSE) {
_errno = MP_EADDRINUSE;
} else if (_errno == EINPROGRESS) {
_errno = MP_EINPROGRESS;
}
mp_raise_OSError(_errno);
}
static inline void check_for_exceptions(void) {
mp_handle_pending(true);
}
@ -277,7 +267,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, siz
sock->fd = lwip_socket(sock->domain, sock->type, sock->proto);
if (sock->fd < 0) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
_socket_settimeout(sock, UINT64_MAX);
@ -291,7 +281,7 @@ STATIC mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) {
int r = lwip_bind(self->fd, res->ai_addr, res->ai_addrlen);
lwip_freeaddrinfo(res);
if (r < 0) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
return mp_const_none;
}
@ -302,7 +292,7 @@ STATIC mp_obj_t socket_listen(const mp_obj_t arg0, const mp_obj_t arg1) {
int backlog = mp_obj_get_int(arg1);
int r = lwip_listen(self->fd, backlog);
if (r < 0) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
return mp_const_none;
}
@ -323,7 +313,7 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) {
break;
}
if (errno != EAGAIN) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
check_for_exceptions();
}
@ -365,7 +355,7 @@ STATIC mp_obj_t socket_connect(const mp_obj_t arg0, const mp_obj_t arg1) {
MP_THREAD_GIL_ENTER();
lwip_freeaddrinfo(res);
if (r != 0) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
return mp_const_none;
@ -384,7 +374,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
int val = mp_obj_get_int(args[3]);
int ret = lwip_setsockopt(self->fd, SOL_SOCKET, opt, &val, sizeof(int));
if (ret != 0) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
break;
}
@ -535,7 +525,7 @@ mp_obj_t _socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in,
int errcode;
mp_uint_t ret = _socket_read_data(self_in, vstr.buf, len, from, from_len, &errcode);
if (ret == MP_STREAM_ERROR) {
exception_from_errno(errcode);
mp_raise_OSError(errcode);
}
vstr.len = ret;
@ -569,7 +559,7 @@ int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) {
int r = lwip_write(sock->fd, data + sentlen, datalen - sentlen);
MP_THREAD_GIL_ENTER();
if (r < 0 && errno != EWOULDBLOCK) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
if (r > 0) {
sentlen += r;
@ -627,7 +617,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
return mp_obj_new_int_from_uint(ret);
}
if (ret == -1 && errno != EWOULDBLOCK) {
exception_from_errno(errno);
mp_raise_OSError(errno);
}
check_for_exceptions();
}