if(newsize > buf->maxsize)
newsize = buf->maxsize;
char *newdata = realloc(buf->data, newsize);
- fprintf(stderr, "%p = realloc(%p, %zu)\n", newdata, buf->data, newsize);
if(!newdata)
return -1;
buf->data = newdata;
buf->size = newsize;
}
- fprintf(stderr, "memcpy(%p, %p, %zu)\n", buf->data + buf->used, data, len);
memcpy(buf->data + buf->used, data, len);
buf->used += len;
return len;
#endif
if(!acceptable) {
- debug("Packet not acceptable, %u <= %u + %zu < %u\n", c->rcv.nxt, hdr.seq, len, c->rcv.nxt + c->rcv.wnd);
+ debug("Packet not acceptable, %u <= %u + %zu < %u\n", c->rcv.nxt, hdr.seq, len, c->rcv.nxt + c->rcv.wnd);
// Ignore unacceptable RST packets.
if(hdr.ctl & RST)
return 0;
// Otherwise, send an ACK back in the hope things improve.
- goto ack;
+ ack(c, true);
+ return 0;
}
c->snd.wnd = hdr.wnd; // TODO: move below
rxd = c->recv(c, data, len);
if(rxd != len) {
// TODO: once we have a receive buffer, handle the application not accepting all data.
- fprintf(stderr, "c->recv(%p, %p, %zu) returned %zd\n", c, data, len, rxd);
abort();
}
if(rxd < 0)
int utcp_close(struct utcp_connection *c) {
if(utcp_shutdown(c, SHUT_RDWR))
return -1;
+ c->recv = NULL;
+ c->poll = NULL;
c->reapable = true;
return 0;
}
return -1;
}
+ c->recv = NULL;
+ c->poll = NULL;
c->reapable = true;
switch(c->state) {
* The return value is the time to the next timeout in milliseconds,
* or maybe a negative value if the timeout is infinite.
*/
-int utcp_timeout(struct utcp *utcp) {
+struct timeval utcp_timeout(struct utcp *utcp) {
struct timeval now;
gettimeofday(&now, NULL);
struct timeval next = {now.tv_sec + 3600, now.tv_usec};
struct timeval diff;
timersub(&next, &now, &diff);
- if(diff.tv_sec < 0)
- return 0;
- return diff.tv_sec * 1000 + diff.tv_usec / 1000;
+ return diff;
}
struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv) {