mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 02:59:01 +08:00
Merge pull request #2169 from cesanta/udp-printf
Fix mg_xprint() for UDP in MIP
This commit is contained in:
commit
20e613b444
20
mongoose.c
20
mongoose.c
@ -7943,14 +7943,20 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||||
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
|
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
|
||||||
struct connstate *s = (struct connstate *) (c + 1);
|
struct connstate *s = (struct connstate *) (c + 1);
|
||||||
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
if (c->is_udp) {
|
||||||
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
size_t max_headers_len = 14 + 24 /* max IP */ + 8 /* UDP */;
|
||||||
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
mg_htonl(s->seq), mg_htonl(s->ack), buf, len) > 0) {
|
tx_udp(ifp, s->mac, ifp->ip, c->loc.port, c->rem.ip, c->rem.port, buf, len);
|
||||||
s->seq += (uint32_t) len;
|
|
||||||
if (s->ttype == MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_KEEPALIVE);
|
|
||||||
} else {
|
} else {
|
||||||
return MG_IO_ERR;
|
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
||||||
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
|
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
||||||
|
mg_htonl(s->seq), mg_htonl(s->ack), buf, len) > 0) {
|
||||||
|
s->seq += (uint32_t) len;
|
||||||
|
if (s->ttype == MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_KEEPALIVE);
|
||||||
|
} else {
|
||||||
|
return MG_IO_ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (long) len;
|
return (long) len;
|
||||||
}
|
}
|
||||||
|
@ -497,14 +497,20 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
|||||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||||
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
|
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
|
||||||
struct connstate *s = (struct connstate *) (c + 1);
|
struct connstate *s = (struct connstate *) (c + 1);
|
||||||
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
if (c->is_udp) {
|
||||||
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
size_t max_headers_len = 14 + 24 /* max IP */ + 8 /* UDP */;
|
||||||
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
mg_htonl(s->seq), mg_htonl(s->ack), buf, len) > 0) {
|
tx_udp(ifp, s->mac, ifp->ip, c->loc.port, c->rem.ip, c->rem.port, buf, len);
|
||||||
s->seq += (uint32_t) len;
|
|
||||||
if (s->ttype == MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_KEEPALIVE);
|
|
||||||
} else {
|
} else {
|
||||||
return MG_IO_ERR;
|
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
||||||
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
|
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
||||||
|
mg_htonl(s->seq), mg_htonl(s->ack), buf, len) > 0) {
|
||||||
|
s->seq += (uint32_t) len;
|
||||||
|
if (s->ttype == MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_KEEPALIVE);
|
||||||
|
} else {
|
||||||
|
return MG_IO_ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (long) len;
|
return (long) len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user