@@ -4407,12 +4407,13 @@ static struct ip *tx_ip(struct mg_tcpip_if *ifp, uint8_t *mac_dst,
44074407 return ip;
44084408}
44094409
4410- static void tx_udp(struct mg_tcpip_if *ifp, uint8_t *mac_dst, uint32_t ip_src,
4410+ static bool tx_udp(struct mg_tcpip_if *ifp, uint8_t *mac_dst, uint32_t ip_src,
44114411 uint16_t sport, uint32_t ip_dst, uint16_t dport,
44124412 const void *buf, size_t len) {
44134413 struct ip *ip =
44144414 tx_ip(ifp, mac_dst, 17, ip_src, ip_dst, len + sizeof(struct udp));
44154415 struct udp *udp = (struct udp *) (ip + 1);
4416+ size_t eth_len;
44164417 // MG_DEBUG(("UDP XX LEN %d %d", (int) len, (int) ifp->tx.len));
44174418 udp->sport = sport;
44184419 udp->dport = dport;
@@ -4426,7 +4427,8 @@ static void tx_udp(struct mg_tcpip_if *ifp, uint8_t *mac_dst, uint32_t ip_src,
44264427 udp->csum = csumfin(cs);
44274428 memmove(udp + 1, buf, len);
44284429 // MG_DEBUG(("UDP LEN %d %d", (int) len, (int) ifp->frame_len));
4429- ether_output(ifp, sizeof(struct eth) + sizeof(*ip) + sizeof(*udp) + len);
4430+ eth_len = sizeof(struct eth) + sizeof(*ip) + sizeof(*udp) + len;
4431+ return (ether_output(ifp, eth_len) == eth_len);
44304432}
44314433
44324434static void tx_dhcp(struct mg_tcpip_if *ifp, uint8_t *mac_dst, uint32_t ip_src,
@@ -4801,7 +4803,9 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
48014803 uint32_t dst_ip = *(uint32_t *) c->rem.ip;
48024804 len = trim_len(c, len);
48034805 if (c->is_udp) {
4804- tx_udp(ifp, s->mac, ifp->ip, c->loc.port, dst_ip, c->rem.port, buf, len);
4806+ if (!tx_udp(ifp, s->mac, ifp->ip, c->loc.port, dst_ip, c->rem.port, buf,
4807+ len))
4808+ return MG_IO_WAIT;
48054809 } else { // TCP, cap to peer's MSS
48064810 size_t sent;
48074811 if (len > s->dmss) len = s->dmss; // RFC-6691: reduce if sending opts
@@ -5421,8 +5425,8 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
54215425 } else if (c->is_udp) {
54225426 struct connstate *s = (struct connstate *) (c + 1);
54235427 len = trim_len(c, len); // Trimming length if necessary
5424- tx_udp(ifp, s->mac, ifp->ip, c->loc.port, rem_ip, c->rem.port, buf, len);
5425- res = true ;
5428+ res = tx_udp(ifp, s->mac, ifp->ip, c->loc.port, rem_ip, c->rem.port, buf,
5429+ len) ;
54265430 } else {
54275431 res = mg_iobuf_add(&c->send, c->send.len, buf, len);
54285432 }
0 commit comments