(r)->tv_sec = (a)->tv_sec - (b)->tv_sec;\
(r)->tv_usec = (a)->tv_usec - (b)->tv_usec;\
if((r)->tv_usec < 0)\
- (r)->tv_sec--, (r)->tv_usec += 1000000;\
+ (r)->tv_sec--, (r)->tv_usec += USEC_PER_SEC;\
} while (0)
#endif
-#ifndef max
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#endif
+static inline size_t max(size_t a, size_t b) {
+ return a > b ? a : b;
+}
#ifdef UTCP_DEBUG
#include <stdarg.h>
* that are shifted to before the start of the receive buffer.
*
* There are three cases:
- * - the SACK entry is ahead of ^, in that case just change the offset.
+ * - the SACK entry is after ^, in that case just change the offset.
* - the SACK entry starts before and ends after ^, so we have to
* change both its offset and size.
* - the SACK entry is completely before ^, in that case delete it.
memmove(&c->sacks[i + 1], &c->sacks[i], (NSACKS - i - 1) * sizeof c->sacks[i]);
c->sacks[i].offset = offset;
c->sacks[i].len = rxd;
+ } else {
+ debug("SACK entries full, dropping packet\n");
}
break;
} else { // merge
// In case this is for a CLOSED connection, ignore the packet.
// TODO: make it so incoming packets can never match a CLOSED connection.
- if(c->state == CLOSED)
+ if(c->state == CLOSED) {
+ debug("Got packet for closed connection\n");
return 0;
+ }
// It is for an existing connection.
}
int utcp_close(struct utcp_connection *c) {
- if(utcp_shutdown(c, SHUT_RDWR))
+ if(utcp_shutdown(c, SHUT_RDWR) && errno != ENOTCONN)
return -1;
c->recv = NULL;
c->poll = NULL;
utcp->send = send;
utcp->priv = priv;
utcp->mtu = DEFAULT_MTU;
- utcp->timeout = DEFAULT_USER_TIMEOUT; // s
- utcp->rto = START_RTO; // us
+ utcp->timeout = DEFAULT_USER_TIMEOUT; // sec
+ utcp->rto = START_RTO; // usec
return utcp;
}