]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Add initialization and cleanup functions for Winsock
authorramiro <ramiro@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Thu, 9 Aug 2007 23:39:05 +0000 (23:39 +0000)
committerramiro <ramiro@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Thu, 9 Aug 2007 23:39:05 +0000 (23:39 +0000)
git-svn-id: file:///var/local/repositories/ffmpeg/trunk@10040 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavformat/network.h
libavformat/tcp.c
libavformat/udp.c

index 37606ee98df2bebf987b9935610505f874a75b39..4c9a3a07c05b16bbf1e348bebb3d10a205483c4c 100644 (file)
 
 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);
index 2d417ecc478ea4e7f0edbaeda81e6390b98b8fef..1b9b4f8458463cbe20e8bd64bae489430584e4f3 100644 (file)
@@ -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;
 }
index 0c42945eb1670b4c98ae972e0309b42d092ce9ee..edbf543ba946b939e1fc24e7aaea713dea82e535 100644 (file)
@@ -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;
 }