Revision 1642cb6b

View differences:

libavformat/network.h
44 44

  
45 45
int ff_socket_nonblock(int socket, int enable);
46 46

  
47
static inline int ff_network_init(void)
48
{
49
#ifdef HAVE_WINSOCK2_H
50
    WSADATA wsaData;
51
    if (WSAStartup(MAKEWORD(1,1), &wsaData))
52
        return 0;
53
#endif
54
    return 1;
55
}
56

  
57
static inline void ff_network_close(void)
58
{
59
#ifdef HAVE_WINSOCK2_H
60
    WSACleanup();
61
#endif
62
}
63

  
47 64
#if !defined(HAVE_INET_ATON)
48 65
/* in os_support.c */
49 66
int inet_aton (const char * str, struct in_addr * add);
libavformat/tcp.c
53 53
    if (port <= 0 || port >= 65536)
54 54
        goto fail;
55 55

  
56
    if(!ff_network_init())
57
        return AVERROR(EIO);
58

  
56 59
    dest_addr.sin_family = AF_INET;
57 60
    dest_addr.sin_port = htons(port);
58 61
    if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
......
174 177
{
175 178
    TCPContext *s = h->priv_data;
176 179
    closesocket(s->fd);
180
    ff_network_close();
177 181
    av_free(s);
178 182
    return 0;
179 183
}
libavformat/udp.c
321 321
        udp_set_remote_url(h, uri);
322 322
    }
323 323

  
324
    if(!ff_network_init())
325
        return AVERROR(EIO);
326

  
324 327
#ifndef CONFIG_IPV6
325 328
    udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
326 329
    if (udp_fd < 0)
......
472 475
        udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
473 476
#endif
474 477
    closesocket(s->udp_fd);
478
    ff_network_close();
475 479
    av_free(s);
476 480
    return 0;
477 481
}

Also available in: Unified diff