Skip to content

Commit 64d0051

Browse files
committed
zephyr/modusocket: Implement send().
1 parent 88582e3 commit 64d0051

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

zephyr/modusocket.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
130130
}
131131
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
132132

133+
STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
134+
socket_obj_t *socket = self_in;
135+
socket_check_closed(socket);
136+
137+
mp_buffer_info_t bufinfo;
138+
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
139+
140+
struct net_buf *send_buf = net_nbuf_get_tx(socket->ctx, K_FOREVER);
141+
// TODO: Probably should limit how much data we send in one call still
142+
if (!net_nbuf_append(send_buf, bufinfo.len, bufinfo.buf, K_FOREVER)) {
143+
mp_raise_OSError(ENOSPC);
144+
}
145+
146+
RAISE_ERRNO(net_context_send(send_buf, /*cb*/NULL, K_FOREVER, NULL, NULL));
147+
148+
return mp_obj_new_int_from_uint(bufinfo.len);
149+
}
150+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
151+
133152
STATIC mp_obj_t socket_close(mp_obj_t self_in) {
134153
socket_obj_t *socket = self_in;
135154
if (socket->ctx != NULL) {
@@ -145,6 +164,7 @@ STATIC const mp_map_elem_t socket_locals_dict_table[] = {
145164
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },
146165
{ MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&socket_bind_obj },
147166
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&socket_connect_obj },
167+
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&socket_send_obj },
148168
};
149169
STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
150170

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy