ecore_con: Fix checks from socket() and accept() under windows.
authorNicolas Aguirre <aguirre.nicolas@gmail.com>
Fri, 30 Jan 2015 10:04:19 +0000 (11:04 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 11 Feb 2015 16:03:37 +0000 (17:03 +0100)
import from Guillaume Friloux ecore's fork : https://github.com/gfriloux/ecore/commit/ab2d406a37c0ae205b6a934b7ea747f4b2baee81

src/lib/ecore_con/ecore_con.c

index 13e9536..b56535c 100644 (file)
@@ -1575,11 +1575,13 @@ _ecore_con_cb_tcp_listen(void *data,
 
    svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
                     net_info->info.ai_protocol);
-   if (svr->fd < 0) goto error;
-
 #ifdef _WIN32
+   if (svr->fd == INVALID_SOCKET) goto error;
+
    if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
 #else
+   if (svr->fd < 0) goto error;
+
    if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
    if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
 #endif
@@ -1674,8 +1676,17 @@ _ecore_con_cb_udp_listen(void *data,
 #endif
    svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
                     net_info->info.ai_protocol);
+#ifdef _WIN32
+   if (svr->fd == INVALID_SOCKET) goto error;
+
+   if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
+#else
    if (svr->fd < 0) goto error;
 
+   if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
+   if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
+#endif
+
    if (type == ECORE_CON_REMOTE_MCAST)
      {
         if (net_info->info.ai_family == AF_INET)
@@ -1706,13 +1717,6 @@ _ecore_con_cb_udp_listen(void *data,
    if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
      goto error;
 
-#ifdef _WIN32
-   if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
-#else
-   if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
-   if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
-#endif
-
    if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
      goto error;
 
@@ -1760,11 +1764,13 @@ _ecore_con_cb_tcp_connect(void *data,
 
    svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
                     net_info->info.ai_protocol);
-   if (svr->fd < 0) goto error;
-
 #ifdef _WIN32
+   if (svr->fd == INVALID_SOCKET) goto error;
+
    if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
 #else
+   if (svr->fd < 0) goto error;
+
    if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
    if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
 #endif
@@ -1862,11 +1868,13 @@ _ecore_con_cb_udp_connect(void *data,
 
    svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
                     net_info->info.ai_protocol);
-   if (svr->fd < 0) goto error;
-
 #ifdef _WIN32
+   if (svr->fd == INVALID_SOCKET) goto error;
+
    if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
 #else
+   if (svr->fd < 0) goto error;
+
    if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
    if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
 #endif
@@ -2040,7 +2048,11 @@ _ecore_con_svr_tcp_handler(void *data,
    client_addr_len = sizeof(client_addr);
    memset(&client_addr, 0, client_addr_len);
    cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
+#ifdef _WIN32
+   if (cl->fd == INVALID_SOCKET) goto error;
+#else
    if (cl->fd < 0) goto error;
+#endif
    if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
        (svr->client_count >= (unsigned int)svr->client_limit))
      {