diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2011-04-04 18:17:12 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2011-04-07 02:53:55 +0200 |
commit | ebba2b3e2a551ce638d17332761431ba748f178f (patch) | |
tree | 5fded7a9455e3a83c513d594cf17337ad22c0096 /libavformat/network.h | |
parent | 1f6265e011f6e56562b2f58c182bc0261062b3c4 (diff) | |
download | ffmpeg-ebba2b3e2a551ce638d17332761431ba748f178f.tar.gz |
proto: factor ff_network_wait_fd and use it on udp
Support the URL_FLAG_NONBLOCK semantic and uniform the protocol.
The quick retry loop is already part of retry_transfer_wrapper.
The polling routine is common to the network protocols:
udp, tcp and, once merged, sctp.
Diffstat (limited to 'libavformat/network.h')
-rw-r--r-- | libavformat/network.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libavformat/network.h b/libavformat/network.h index 27bebb3505..6943bc6765 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -55,6 +55,10 @@ static inline int ff_neterrno() { #include <arpa/inet.h> #endif +#if HAVE_POLL_H +#include <poll.h> +#endif + int ff_socket_nonblock(int socket, int enable); static inline int ff_network_init(void) @@ -67,6 +71,15 @@ static inline int ff_network_init(void) return 1; } +static inline int ff_network_wait_fd(int fd, int write) +{ + int ev = write ? POLLOUT : POLLIN; + struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; + int ret; + ret = poll(&p, 1, 100); + return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN); +} + static inline void ff_network_close(void) { #if HAVE_WINSOCK2_H |