diff options
author | Ramiro Polla <ramiro.polla@gmail.com> | 2007-08-09 23:39:05 +0000 |
---|---|---|
committer | Ramiro Polla <ramiro.polla@gmail.com> | 2007-08-09 23:39:05 +0000 |
commit | 1642cb6b2e27437abd2bd9ee9a570446382cb26e (patch) | |
tree | 85e43ce900545f91dae4fd52a527aade260f8df1 | |
parent | 7c04134fa166e86f5c6cbe980e00f11e6871f0d1 (diff) | |
download | ffmpeg-1642cb6b2e27437abd2bd9ee9a570446382cb26e.tar.gz |
Add initialization and cleanup functions for Winsock
Originally committed as revision 10040 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/network.h | 17 | ||||
-rw-r--r-- | libavformat/tcp.c | 4 | ||||
-rw-r--r-- | libavformat/udp.c | 4 |
3 files changed, 25 insertions, 0 deletions
diff --git a/libavformat/network.h b/libavformat/network.h index 37606ee98d..4c9a3a07c0 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -44,6 +44,23 @@ int ff_socket_nonblock(int socket, int enable); +static inline int ff_network_init(void) +{ +#ifdef HAVE_WINSOCK2_H + WSADATA wsaData; + if (WSAStartup(MAKEWORD(1,1), &wsaData)) + return 0; +#endif + return 1; +} + +static inline void ff_network_close(void) +{ +#ifdef HAVE_WINSOCK2_H + WSACleanup(); +#endif +} + #if !defined(HAVE_INET_ATON) /* in os_support.c */ int inet_aton (const char * str, struct in_addr * add); diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 2d417ecc47..1b9b4f8458 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -53,6 +53,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (port <= 0 || port >= 65536) goto fail; + if(!ff_network_init()) + return AVERROR(EIO); + dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(port); if (resolve_host(&dest_addr.sin_addr, hostname) < 0) @@ -174,6 +177,7 @@ static int tcp_close(URLContext *h) { TCPContext *s = h->priv_data; closesocket(s->fd); + ff_network_close(); av_free(s); return 0; } diff --git a/libavformat/udp.c b/libavformat/udp.c index 0c42945eb1..edbf543ba9 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -321,6 +321,9 @@ static int udp_open(URLContext *h, const char *uri, int flags) udp_set_remote_url(h, uri); } + if(!ff_network_init()) + return AVERROR(EIO); + #ifndef CONFIG_IPV6 udp_fd = socket(AF_INET, SOCK_DGRAM, 0); if (udp_fd < 0) @@ -472,6 +475,7 @@ static int udp_close(URLContext *h) udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); #endif closesocket(s->udp_fd); + ff_network_close(); av_free(s); return 0; } |