socket_send: Don't send more than MTU allows.
As Zephyr currently doesn't handle MTU itself (ZEP-1998), limit amount of data we send on our side. Also, if we get unsuccessful result from net_nbuf_append(), calculate how much data it has added still. This works around ZEP-1984.
This commit is contained in:
parent
5b8122f2bb
commit
209eaec599
|
@ -308,14 +308,22 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||||
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
|
||||||
|
|
||||||
struct net_buf *send_buf = net_nbuf_get_tx(socket->ctx, K_FOREVER);
|
struct net_buf *send_buf = net_nbuf_get_tx(socket->ctx, K_FOREVER);
|
||||||
// TODO: Probably should limit how much data we send in one call still
|
|
||||||
if (!net_nbuf_append(send_buf, bufinfo.len, bufinfo.buf, K_FOREVER)) {
|
unsigned len = net_if_get_mtu(net_context_get_iface(socket->ctx));
|
||||||
mp_raise_OSError(ENOSPC);
|
// Arbitrary value to account for protocol headers
|
||||||
|
len -= 64;
|
||||||
|
if (len > bufinfo.len) {
|
||||||
|
len = bufinfo.len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!net_nbuf_append(send_buf, len, bufinfo.buf, K_FOREVER)) {
|
||||||
|
len = net_buf_frags_len(send_buf);
|
||||||
|
//mp_raise_OSError(ENOSPC);
|
||||||
}
|
}
|
||||||
|
|
||||||
RAISE_ERRNO(net_context_send(send_buf, /*cb*/NULL, K_FOREVER, NULL, NULL));
|
RAISE_ERRNO(net_context_send(send_buf, /*cb*/NULL, K_FOREVER, NULL, NULL));
|
||||||
|
|
||||||
return mp_obj_new_int_from_uint(bufinfo.len);
|
return mp_obj_new_int_from_uint(len);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue