aboutsummaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-02-13 20:00:53 -0600
committerRob Landley <rob@landley.net>2019-02-13 20:00:53 -0600
commit7e6a7da60042dbf033cc3136877a2862bf825bd1 (patch)
tree24f98032c51c97237c51d3af6e36580758a15a50 /lib/net.c
parentfbedc9dd74aeb0331202f9e503316960e32fa879 (diff)
downloadtoybox-7e6a7da60042dbf033cc3136877a2862bf825bd1.tar.gz
Move nanomove(), nanodiff(), union socksaddr, and xrecvwait() to lib.
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;
+}