Commit 7132db70 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement wait_for_fd.

parent 88681ffc
...@@ -181,3 +181,23 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned short *plen_r) ...@@ -181,3 +181,23 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned short *plen_r)
*plen_r = plen; *plen_r = plen;
return 0; return 0;
} }
int
wait_for_fd(int direction, int fd, int msecs)
{
fd_set fds;
int rc;
struct timeval tv;
tv.tv_sec = msecs / 1000;
tv.tv_usec = msecs * 1000;
FD_ZERO(&fds);
FD_SET(fd, &fds);
if(direction)
rc = select(fd + 1, NULL, &fds, NULL, &tv);
else
rc = select(fd + 1, &fds, NULL, NULL, &tv);
return rc;
}
...@@ -36,6 +36,7 @@ void do_debugf(const char *format, ...) ATTRIBUTE ((format (printf, 1, 2))); ...@@ -36,6 +36,7 @@ void do_debugf(const char *format, ...) ATTRIBUTE ((format (printf, 1, 2)));
const char *format_address(const unsigned char *address); const char *format_address(const unsigned char *address);
int parse_address(const char *address, unsigned char *addr_r); int parse_address(const char *address, unsigned char *addr_r);
int parse_net(const char *net, unsigned char *prefix_r, unsigned short *plen_r); int parse_net(const char *net, unsigned char *prefix_r, unsigned short *plen_r);
int wait_for_fd(int direction, int fd, int msecs);
/* If debugging is disabled, we want to avoid calling format_address /* If debugging is disabled, we want to avoid calling format_address
for every omitted debugging message. So debug is a macro. But for every omitted debugging message. So debug is a macro. But
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment