connected = true;
}
+ freeaddrinfo(ai);
+
struct utcp *u = utcp_init(server ? do_accept : NULL, NULL, do_send, &s);
if(!u)
return 1;
if(fds[1].revents) {
struct sockaddr_storage ss;
- socklen_t sl;
+ socklen_t sl = sizeof ss;
int len = recvfrom(s, buf, sizeof buf, MSG_DONTWAIT, (struct sockaddr *)&ss, &sl);
if(len <= 0)
break;
memmove(cp + i, cp + i + 1, (utcp->nconnections - i - 1) * sizeof *cp);
utcp->nconnections--;
+ free(c->sndbuf);
free(c);
}
hdr.dst = c->dst;
hdr.seq = c->snd.iss;
hdr.ack = 0;
- hdr.ctl = SYN;
hdr.wnd = c->rcv.wnd;
+ hdr.ctl = SYN;
+ hdr.aux = 0;
set_state(c, SYN_SENT);
pkt.hdr.ack = c->rcv.nxt;
pkt.hdr.wnd = c->snd.wnd;
pkt.hdr.ctl = ACK;
+ pkt.hdr.aux = 0;
do {
uint32_t seglen = left > c->utcp->mtu ? c->utcp->mtu : left;
// FIN counts as one sequence number
c->rcv.nxt++;
+ len++;
// Inform the application that the peer closed the connection.
if(c->recv) {
void utcp_exit(struct utcp *utcp) {
if(!utcp)
return;
- for(int i = 0; i < utcp->nconnections; i++)
- free_connection(utcp->connections[i]);
+ for(int i = 0; i < utcp->nconnections; i++) {
+ if(!utcp->connections[i]->reapable)
+ debug("Warning, freeing unclosed connection %p\n", utcp->connections[i]);
+ free(utcp->connections[i]->sndbuf);
+ free(utcp->connections[i]);
+ }
+ free(utcp->connections);
free(utcp);
}