struct {
struct hdr hdr;
uint8_t data[];
- } *pkt;
-
- pkt = malloc(sizeof(pkt->hdr) + c->utcp->mtu);
-
- if(!pkt) {
- return;
- }
+ } *pkt = c->utcp->pkt;
pkt->hdr.src = c->src;
pkt->hdr.dst = c->dst;
print_packet(c->utcp, "send", pkt, sizeof(pkt->hdr) + seglen);
c->utcp->send(c->utcp, pkt, sizeof(pkt->hdr) + seglen);
} while(left);
-
- free(pkt);
}
ssize_t utcp_send(struct utcp_connection *c, const void *data, size_t len) {
struct {
struct hdr hdr;
uint8_t data[];
- } *pkt;
-
- pkt = malloc(sizeof(pkt->hdr) + c->utcp->mtu);
-
- if(!pkt) {
- return;
- }
+ } *pkt = c->utcp->pkt;
pkt->hdr.src = c->src;
pkt->hdr.dst = c->dst;
c->rtt_start.tv_sec = 0; // invalidate RTT timer
cleanup:
- free(pkt);
+ return;
}
/* Update receive buffer and SACK entries after consuming data.
utcp->pre_accept = pre_accept;
utcp->send = send;
utcp->priv = priv;
- utcp->mtu = DEFAULT_MTU;
+ utcp_set_mtu(utcp, DEFAULT_MTU);
utcp->timeout = DEFAULT_USER_TIMEOUT; // sec
utcp->rto = START_RTO; // usec
}
void utcp_set_mtu(struct utcp *utcp, uint16_t mtu) {
- // TODO: handle overhead of the header
- if(utcp) {
- utcp->mtu = mtu;
+ if (!utcp) {
+ return;
}
+
+ if (mtu <= sizeof(struct hdr)) {
+ return;
+ }
+
+ if (mtu > utcp->mtu) {
+ char *new = realloc(utcp->pkt, mtu);
+ if (!new)
+ return;
+ utcp->pkt = new;
+ }
+
+ utcp->mtu = mtu;
}
void utcp_reset_timers(struct utcp *utcp) {