diff options
author | Nicolas Aguirre <aguirre.nicolas@gmail.com> | 2015-01-30 11:04:19 +0100 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2015-02-11 17:03:37 +0100 |
commit | 7d4f95171c9546273e6e7788e21613a70128ac34 (patch) | |
tree | 0d8d936ba690da7da6843688e792b24844fa38fe /src/lib/ecore_con/ecore_con.c | |
parent | f26977a1758dff88371206882daa2b63594c4368 (diff) |
ecore_con: Fix checks from socket() and accept() under windows.
import from Guillaume Friloux ecore's fork : https://github.com/gfriloux/ecore/commit/ab2d406a37c0ae205b6a934b7ea747f4b2baee81
Diffstat (limited to '')
-rw-r--r-- | src/lib/ecore_con/ecore_con.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c index 13e953664f..b56535cd13 100644 --- a/src/lib/ecore_con/ecore_con.c +++ b/src/lib/ecore_con/ecore_con.c | |||
@@ -1575,11 +1575,13 @@ _ecore_con_cb_tcp_listen(void *data, | |||
1575 | 1575 | ||
1576 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, | 1576 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, |
1577 | net_info->info.ai_protocol); | 1577 | net_info->info.ai_protocol); |
1578 | if (svr->fd < 0) goto error; | ||
1579 | |||
1580 | #ifdef _WIN32 | 1578 | #ifdef _WIN32 |
1579 | if (svr->fd == INVALID_SOCKET) goto error; | ||
1580 | |||
1581 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; | 1581 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; |
1582 | #else | 1582 | #else |
1583 | if (svr->fd < 0) goto error; | ||
1584 | |||
1583 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; | 1585 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; |
1584 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; | 1586 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; |
1585 | #endif | 1587 | #endif |
@@ -1674,8 +1676,17 @@ _ecore_con_cb_udp_listen(void *data, | |||
1674 | #endif | 1676 | #endif |
1675 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, | 1677 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, |
1676 | net_info->info.ai_protocol); | 1678 | net_info->info.ai_protocol); |
1679 | #ifdef _WIN32 | ||
1680 | if (svr->fd == INVALID_SOCKET) goto error; | ||
1681 | |||
1682 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; | ||
1683 | #else | ||
1677 | if (svr->fd < 0) goto error; | 1684 | if (svr->fd < 0) goto error; |
1678 | 1685 | ||
1686 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; | ||
1687 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; | ||
1688 | #endif | ||
1689 | |||
1679 | if (type == ECORE_CON_REMOTE_MCAST) | 1690 | if (type == ECORE_CON_REMOTE_MCAST) |
1680 | { | 1691 | { |
1681 | if (net_info->info.ai_family == AF_INET) | 1692 | if (net_info->info.ai_family == AF_INET) |
@@ -1706,13 +1717,6 @@ _ecore_con_cb_udp_listen(void *data, | |||
1706 | if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0) | 1717 | if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0) |
1707 | goto error; | 1718 | goto error; |
1708 | 1719 | ||
1709 | #ifdef _WIN32 | ||
1710 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; | ||
1711 | #else | ||
1712 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; | ||
1713 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; | ||
1714 | #endif | ||
1715 | |||
1716 | if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) | 1720 | if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) |
1717 | goto error; | 1721 | goto error; |
1718 | 1722 | ||
@@ -1760,11 +1764,13 @@ _ecore_con_cb_tcp_connect(void *data, | |||
1760 | 1764 | ||
1761 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, | 1765 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, |
1762 | net_info->info.ai_protocol); | 1766 | net_info->info.ai_protocol); |
1763 | if (svr->fd < 0) goto error; | ||
1764 | |||
1765 | #ifdef _WIN32 | 1767 | #ifdef _WIN32 |
1768 | if (svr->fd == INVALID_SOCKET) goto error; | ||
1769 | |||
1766 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; | 1770 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; |
1767 | #else | 1771 | #else |
1772 | if (svr->fd < 0) goto error; | ||
1773 | |||
1768 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; | 1774 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; |
1769 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; | 1775 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; |
1770 | #endif | 1776 | #endif |
@@ -1862,11 +1868,13 @@ _ecore_con_cb_udp_connect(void *data, | |||
1862 | 1868 | ||
1863 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, | 1869 | svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, |
1864 | net_info->info.ai_protocol); | 1870 | net_info->info.ai_protocol); |
1865 | if (svr->fd < 0) goto error; | ||
1866 | |||
1867 | #ifdef _WIN32 | 1871 | #ifdef _WIN32 |
1872 | if (svr->fd == INVALID_SOCKET) goto error; | ||
1873 | |||
1868 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; | 1874 | if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error; |
1869 | #else | 1875 | #else |
1876 | if (svr->fd < 0) goto error; | ||
1877 | |||
1870 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; | 1878 | if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; |
1871 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; | 1879 | if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; |
1872 | #endif | 1880 | #endif |
@@ -2040,7 +2048,11 @@ _ecore_con_svr_tcp_handler(void *data, | |||
2040 | client_addr_len = sizeof(client_addr); | 2048 | client_addr_len = sizeof(client_addr); |
2041 | memset(&client_addr, 0, client_addr_len); | 2049 | memset(&client_addr, 0, client_addr_len); |
2042 | cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len); | 2050 | cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len); |
2051 | #ifdef _WIN32 | ||
2052 | if (cl->fd == INVALID_SOCKET) goto error; | ||
2053 | #else | ||
2043 | if (cl->fd < 0) goto error; | 2054 | if (cl->fd < 0) goto error; |
2055 | #endif | ||
2044 | if ((svr->client_limit >= 0) && (svr->reject_excess_clients) && | 2056 | if ((svr->client_limit >= 0) && (svr->reject_excess_clients) && |
2045 | (svr->client_count >= (unsigned int)svr->client_limit)) | 2057 | (svr->client_count >= (unsigned int)svr->client_limit)) |
2046 | { | 2058 | { |