mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:12:45 +01:00
pkg/lwip: implement sock_udp_sendv_aux()
This commit is contained in:
parent
aa6a3cfddd
commit
b822e8a5a9
@ -573,14 +573,15 @@ int lwip_sock_recv(struct netconn *conn, uint32_t timeout, struct netbuf **buf)
|
||||
}
|
||||
#endif /* defined(MODULE_LWIP_SOCK_UDP) || defined(MODULE_LWIP_SOCK_IP) */
|
||||
|
||||
ssize_t lwip_sock_send(struct netconn *conn, const void *data, size_t len,
|
||||
ssize_t lwip_sock_sendv(struct netconn *conn, const iolist_t *snips,
|
||||
int proto, const struct _sock_tl_ep *remote, int type)
|
||||
{
|
||||
ip_addr_t remote_addr;
|
||||
struct netconn *tmp;
|
||||
struct netbuf *buf;
|
||||
struct netbuf *buf = NULL;
|
||||
size_t payload_len = 0;
|
||||
int res;
|
||||
err_t err;
|
||||
err_t err= ERR_OK;
|
||||
u16_t remote_port = 0;
|
||||
|
||||
#if LWIP_IPV6
|
||||
@ -598,11 +599,19 @@ ssize_t lwip_sock_send(struct netconn *conn, const void *data, size_t len,
|
||||
}
|
||||
|
||||
buf = netbuf_new();
|
||||
if ((buf == NULL) || (netbuf_alloc(buf, len) == NULL) ||
|
||||
(netbuf_take(buf, data, len) != ERR_OK)) {
|
||||
if (netbuf_alloc(buf, iolist_size(snips)) == NULL) {
|
||||
netbuf_delete(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (const iolist_t *snip = snips; snip != NULL; snip = snip->iol_next) {
|
||||
if (pbuf_take_at(buf->p, snip->iol_base, snip->iol_len, payload_len) != ERR_OK) {
|
||||
netbuf_delete(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
payload_len += snip->iol_len;
|
||||
}
|
||||
|
||||
if ((conn == NULL) && (remote != NULL)) {
|
||||
if ((res = _create(type, proto, 0, &tmp)) < 0) {
|
||||
netbuf_delete(buf);
|
||||
@ -625,13 +634,13 @@ ssize_t lwip_sock_send(struct netconn *conn, const void *data, size_t len,
|
||||
netbuf_delete(buf);
|
||||
return -ENOTCONN;
|
||||
}
|
||||
res = len; /* set for non-TCP calls */
|
||||
res = payload_len; /* set for non-TCP calls */
|
||||
if (remote != NULL) {
|
||||
err = netconn_sendto(tmp, buf, &remote_addr, remote_port);
|
||||
}
|
||||
#if LWIP_TCP
|
||||
else if (tmp->type & NETCONN_TCP) {
|
||||
err = netconn_write_partly(tmp, data, len, 0, (size_t *)(&res));
|
||||
err = netconn_write_partly(tmp, buf->p->payload, buf->p->len, 0, (size_t *)(&res));
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
else {
|
||||
|
@ -163,17 +163,16 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **ctx,
|
||||
return (ssize_t)buf->ptr->len;
|
||||
}
|
||||
|
||||
ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len,
|
||||
ssize_t sock_udp_sendv_aux(sock_udp_t *sock, const iolist_t *snips,
|
||||
const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
|
||||
{
|
||||
(void)aux;
|
||||
assert((sock != NULL) || (remote != NULL));
|
||||
assert((len == 0) || (data != NULL)); /* (len != 0) => (data != NULL) */
|
||||
|
||||
if ((remote != NULL) && (remote->port == 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
return lwip_sock_send((sock) ? sock->base.conn : NULL, data, len, 0,
|
||||
return lwip_sock_sendv((sock) ? sock->base.conn : NULL, snips, 0,
|
||||
(struct _sock_tl_ep *)remote, NETCONN_UDP);
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,19 @@ int lwip_sock_get_addr(struct netconn *conn, struct _sock_tl_ep *ep, u8_t local)
|
||||
#if defined(MODULE_LWIP_SOCK_UDP) || defined(MODULE_LWIP_SOCK_IP)
|
||||
int lwip_sock_recv(struct netconn *conn, uint32_t timeout, struct netbuf **buf);
|
||||
#endif
|
||||
ssize_t lwip_sock_send(struct netconn *conn, const void *data, size_t len,
|
||||
ssize_t lwip_sock_sendv(struct netconn *conn, const iolist_t *snips,
|
||||
int proto, const struct _sock_tl_ep *remote, int type);
|
||||
static inline ssize_t lwip_sock_send(struct netconn *conn,
|
||||
const void *data, size_t len,
|
||||
int proto, const struct _sock_tl_ep *remote, int type)
|
||||
{
|
||||
iolist_t snip = {
|
||||
.iol_base = (void *)data,
|
||||
.iol_len = len,
|
||||
};
|
||||
|
||||
return lwip_sock_sendv(conn, &snip, proto, remote, type);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user