mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-20 19:41:58 +00:00
Add JS net api test
PUBLISHED_FROM=f2821b104f8f2fc196ce4064b7c9f35ea152368d
This commit is contained in:
1 parent
cfd28a4f7a
commit
4d0cc95ff4
1 file changed
+6
-3
+6
-3
@@ -14636,17 +14636,20 @@ static int mg_lwip_udp_send(struct mg_connection *nc, const void *data,
|
|||||||
}
|
}
|
||||||
struct udp_pcb *upcb = cs->pcb.udp;
|
struct udp_pcb *upcb = cs->pcb.udp;
|
||||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||||
ip_addr_t *ip = (ip_addr_t *) &nc->sa.sin.sin_addr.s_addr;
|
#if defined(LWIP_IPV4) && LWIP_IPV4 && defined(LWIP_IPV6) && LWIP_IPV6
|
||||||
|
ip_addr_t ip = { .u_addr.ip4.addr = nc->sa.sin.sin_addr.s_addr, .type = 0 };
|
||||||
|
#else
|
||||||
|
ip_addr_t ip = { .addr = nc->sa.sin.sin_addr.s_addr };
|
||||||
|
#endif
|
||||||
u16_t port = ntohs(nc->sa.sin.sin_port);
|
u16_t port = ntohs(nc->sa.sin.sin_port);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
DBG(("OOM"));
|
DBG(("OOM"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(p->payload, data, len);
|
memcpy(p->payload, data, len);
|
||||||
struct udp_sendto_ctx ctx = {.upcb = upcb, .p = p, .ip = ip, .port = port};
|
struct udp_sendto_ctx ctx = {.upcb = upcb, .p = p, .ip = &ip, .port = port};
|
||||||
tcpip_callback(udp_sendto_tcpip, &ctx);
|
tcpip_callback(udp_sendto_tcpip, &ctx);
|
||||||
cs->err = ctx.ret;
|
cs->err = ctx.ret;
|
||||||
DBG(("%p udp_sendto = %d", nc, cs->err));
|
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
return (cs->err == ERR_OK ? len : -1);
|
return (cs->err == ERR_OK ? len : -1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user