Commit 5a860312 authored by iabdalkader's avatar iabdalkader Committed by Damien George

extmod/network_ninaw10: Make recv/recvfrom interchangeable.

parent 73a6b53d
...@@ -446,7 +446,15 @@ STATIC mp_uint_t network_ninaw10_socket_send(mod_network_socket_obj_t *socket, c ...@@ -446,7 +446,15 @@ STATIC mp_uint_t network_ninaw10_socket_send(mod_network_socket_obj_t *socket, c
} }
STATIC mp_uint_t network_ninaw10_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { STATIC mp_uint_t network_ninaw10_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) {
int ret = nina_socket_recv(socket->fileno, buf, len, socket->timeout); int ret = 0;
if (socket->type == MOD_NETWORK_SOCK_DGRAM) {
byte ip[4];
uint16_t port;
ret = nina_socket_recvfrom(socket->fileno, buf, len, ip, &port, socket->timeout);
} else {
ret = nina_socket_recv(socket->fileno, buf, len, socket->timeout);
}
if (ret == NINA_ERROR_TIMEOUT) { if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout. // The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT; *_errno = MP_ETIMEDOUT;
...@@ -493,12 +501,18 @@ STATIC mp_uint_t network_ninaw10_socket_sendto(mod_network_socket_obj_t *socket, ...@@ -493,12 +501,18 @@ STATIC mp_uint_t network_ninaw10_socket_sendto(mod_network_socket_obj_t *socket,
STATIC mp_uint_t network_ninaw10_socket_recvfrom(mod_network_socket_obj_t *socket, STATIC mp_uint_t network_ninaw10_socket_recvfrom(mod_network_socket_obj_t *socket,
byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
// Auto-bind the socket first if the socket is unbound. int ret = 0;
if (network_ninaw10_socket_auto_bind(socket, _errno) != 0) { if (socket->type == MOD_NETWORK_SOCK_STREAM) {
return -1; *port = 0;
*((uint32_t *)ip) = 0;
ret = nina_socket_recv(socket->fileno, buf, len, socket->timeout);
} else {
// Auto-bind the socket first if the socket is unbound.
if (network_ninaw10_socket_auto_bind(socket, _errno) != 0) {
return -1;
}
ret = nina_socket_recvfrom(socket->fileno, buf, len, ip, (uint16_t *)port, socket->timeout);
} }
int ret = nina_socket_recvfrom(socket->fileno, buf, len, ip, (uint16_t *)port, socket->timeout);
if (ret == NINA_ERROR_TIMEOUT) { if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout. // The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT; *_errno = MP_ETIMEDOUT;
......
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