aboutsummaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/net.c b/lib/net.c
index 346d17e9..d4373fbe 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -138,3 +138,22 @@ void xsendto(int sockfd, void *buf, size_t len, struct sockaddr *dest)
if (rc != len) perror_exit("sendto");
}
+
+// xrecvfrom with timeout in milliseconds
+int xrecvwait(int fd, char *buf, int len, union socksaddr *sa, int timeout)
+{
+ socklen_t sl = sizeof(*sa);
+
+ if (timeout >= 0) {
+ struct pollfd pfd;
+
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ if (!xpoll(&pfd, 1, timeout)) return 0;
+ }
+
+ len = recvfrom(fd, buf, len, 0, (void *)sa, &sl);
+ if (len<0) perror_exit("recvfrom");
+
+ return len;
+}