summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-11-13 13:12:07 -0500
committerLucian Copeland <hierophect@gmail.com>2020-11-17 16:11:04 -0500
commit0bbdf05936c1b36bee6ef4f9f81bd3b9ea40fbc6 (patch)
treeb9dd750d8fba18cdafcb0aea10605e4024bd5805 /shared-bindings
parent21ca1b8c2bcf5be54117e2de0381eb956e60d0df (diff)
Implement recvfrom_into and sendto for UDP
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/socketpool/Socket.c8
-rw-r--r--shared-bindings/socketpool/Socket.h4
2 files changed, 7 insertions, 5 deletions
diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c
index 591b7d8bb..99e2c8fcc 100644
--- a/shared-bindings/socketpool/Socket.c
+++ b/shared-bindings/socketpool/Socket.c
@@ -36,6 +36,8 @@
#include "py/runtime.h"
#include "py/mperrno.h"
+#include "lib/netutils/netutils.h"
+
//| class Socket:
//| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call
//| `SocketPool.socket()`.
@@ -298,7 +300,7 @@ STATIC mp_obj_t socketpool_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_
mp_int_t port = mp_obj_get_int(addr_items[1]);
mp_int_t ret = common_hal_socketpool_socket_sendto(self, host, hostlen, port, bufinfo.buf, bufinfo.len);
- if (!ok) {
+ if (!ret) {
mp_raise_OSError(0);
}
@@ -324,11 +326,11 @@ STATIC mp_obj_t socketpool_socket_recvfrom_into(mp_obj_t self_in, mp_obj_t data_
byte ip[4];
mp_uint_t port;
mp_int_t ret = common_hal_socketpool_socket_recvfrom_into(self,
- (byte*)bufinfo.buf, len, ip, &port);
+ (byte*)bufinfo.buf, bufinfo.len, ip, &port);
mp_obj_t tuple_contents[2];
tuple_contents[0] = mp_obj_new_int_from_uint(ret);
tuple_contents[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
- return mp_obj_new_tuple(2, tuple);
+ return mp_obj_new_tuple(2, tuple_contents);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_recvfrom_into_obj, socketpool_socket_recvfrom_into);
diff --git a/shared-bindings/socketpool/Socket.h b/shared-bindings/socketpool/Socket.h
index 72a4c9e3c..54fbe59b2 100644
--- a/shared-bindings/socketpool/Socket.h
+++ b/shared-bindings/socketpool/Socket.h
@@ -36,9 +36,9 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c
mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len);
mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len);
mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t* self,
- const uint8_t* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len);
+ const char* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len);
mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self,
- const uint8_t* buf, mp_uint_t len, uint8_t* ip, uint8_t port);
+ uint8_t* buf, mp_uint_t len, uint8_t* ip, uint *port);
void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self);
bool common_hal_socketpool_socket_get_closed(socketpool_socket_obj_t* self);
bool common_hal_socketpool_socket_get_connected(socketpool_socket_obj_t* self);