From: Guus Sliepen Date: Fri, 5 Dec 2014 21:08:21 +0000 (+0100) Subject: Change utcp_timeout() to return a struct timeval. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=5e2471e7e38b68745668aa9c3b1d55297895bba2;p=utcp Change utcp_timeout() to return a struct timeval. This is what MeshLink uses internally as well, and prevents confusion over which units the old int return value had. --- diff --git a/test.c b/test.c index 757364f..922099a 100644 --- a/test.c +++ b/test.c @@ -100,10 +100,10 @@ int main(int argc, char *argv[]) { }; char buf[102400]; - int timeout = utcp_timeout(u); + struct timeval timeout = utcp_timeout(u); while(dir) { - poll(fds, 2, timeout); + poll(fds, 2, timeout.tv_sec * 1000 + timeout.tv_usec / 1000); if(fds[0].revents) { int len = read(0, buf, sizeof buf); diff --git a/utcp.c b/utcp.c index 391706f..2ef56ea 100644 --- a/utcp.c +++ b/utcp.c @@ -1061,7 +1061,7 @@ static void retransmit(struct utcp_connection *c) { * 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}; @@ -1111,9 +1111,7 @@ int utcp_timeout(struct utcp *utcp) { 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) { diff --git a/utcp.h b/utcp.h index 53a107f..7ebca73 100644 --- a/utcp.h +++ b/utcp.h @@ -23,6 +23,8 @@ #include #include #include +// TODO: Windows +#include #ifndef UTCP_INTERNAL struct utcp { @@ -56,7 +58,7 @@ extern ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len); extern int utcp_close(struct utcp_connection *connection); extern int utcp_abort(struct utcp_connection *connection); extern int utcp_shutdown(struct utcp_connection *connection, int how); -extern int utcp_timeout(struct utcp *utcp); +extern struct timeval utcp_timeout(struct utcp *utcp); extern void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv); extern void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll);