diff options
author | Rob Landley <rob@landley.net> | 2019-02-13 20:00:53 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-13 20:00:53 -0600 |
commit | 7e6a7da60042dbf033cc3136877a2862bf825bd1 (patch) | |
tree | 24f98032c51c97237c51d3af6e36580758a15a50 /lib/net.c | |
parent | fbedc9dd74aeb0331202f9e503316960e32fa879 (diff) | |
download | toybox-7e6a7da60042dbf033cc3136877a2862bf825bd1.tar.gz |
Move nanomove(), nanodiff(), union socksaddr, and xrecvwait() to lib.
Diffstat (limited to 'lib/net.c')
-rw-r--r-- | lib/net.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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; +} |