mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-29 21:08:24 +00:00
Merge pull request #2169 from cesanta/udp-printf
Fix mg_xprint() for UDP in MIP
This commit is contained in:
2 files changed
+12
No files matched your search
@@ -7943,6 +7943,11 @@ 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);
|
||||||
|
if (c->is_udp) {
|
||||||
|
size_t max_headers_len = 14 + 24 /* max IP */ + 8 /* UDP */;
|
||||||
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
|
tx_udp(ifp, s->mac, ifp->ip, c->loc.port, c->rem.ip, c->rem.port, buf, len);
|
||||||
|
} else {
|
||||||
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
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 (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,
|
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
||||||
@@ -7952,6 +7957,7 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
} else {
|
} else {
|
||||||
return MG_IO_ERR;
|
return MG_IO_ERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (long) len;
|
return (long) len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -497,6 +497,11 @@ 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);
|
||||||
|
if (c->is_udp) {
|
||||||
|
size_t max_headers_len = 14 + 24 /* max IP */ + 8 /* UDP */;
|
||||||
|
if (len + max_headers_len > ifp->tx.len) len = ifp->tx.len - max_headers_len;
|
||||||
|
tx_udp(ifp, s->mac, ifp->ip, c->loc.port, c->rem.ip, c->rem.port, buf, len);
|
||||||
|
} else {
|
||||||
size_t max_headers_len = 14 + 24 /* max IP */ + 60 /* max TCP */;
|
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 (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,
|
if (tx_tcp(ifp, s->mac, c->rem.ip, TH_PUSH | TH_ACK, c->loc.port, c->rem.port,
|
||||||
@@ -506,6 +511,7 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
} else {
|
} else {
|
||||||
return MG_IO_ERR;
|
return MG_IO_ERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (long) len;
|
return (long) len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user