summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2015-01-30 10:51:52 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-02-11 17:03:37 +0100
commit0e8e4b2728a2a90a3f781e4b8f69e305b9e19b61 (patch)
tree3e7954ce0c98ef344161343da049be61709eb049 /src
parentfbb82367004db0fb095901ab450f029a7af6dede (diff)
ecore_con: use ioctlsocket() when building for windows.
fcntl() doesnt work under windows. References : - http://msdn.microsoft.com/en-us/library/windows/desktop/ms738573%28v=vs.85%29.aspx - http://msdn.microsoft.com/en-us/library/windows/desktop/ms740096%28v=vs.85%29.aspx imported from Guillaume Friloux ecore fork : https://github.com/gfriloux/ecore/commit/66da77d491d4f304767bac88d9ace4a5ff5f41e0
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore_con/ecore_con.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c
index a21e6df8b4..13e953664f 100644
--- a/src/lib/ecore_con/ecore_con.c
+++ b/src/lib/ecore_con/ecore_con.c
@@ -1523,6 +1523,9 @@ _ecore_con_cb_tcp_listen(void *data,
1523 Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS); 1523 Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
1524 struct linger lin; 1524 struct linger lin;
1525 const char *memerr = NULL; 1525 const char *memerr = NULL;
1526#ifdef _WIN32
1527 u_long mode = 1;
1528#endif
1526 1529
1527 errno = 0; 1530 errno = 0;
1528 if (!net_info) /* error message has already been handled */ 1531 if (!net_info) /* error message has already been handled */
@@ -1573,8 +1576,13 @@ _ecore_con_cb_tcp_listen(void *data,
1573 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,
1574 net_info->info.ai_protocol); 1577 net_info->info.ai_protocol);
1575 if (svr->fd < 0) goto error; 1578 if (svr->fd < 0) goto error;
1579
1580#ifdef _WIN32
1581 if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
1582#else
1576 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; 1583 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1577 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; 1584 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1585#endif
1578 1586
1579 lin.l_onoff = 1; 1587 lin.l_onoff = 1;
1580 lin.l_linger = 0; 1588 lin.l_linger = 0;
@@ -1630,6 +1638,9 @@ _ecore_con_cb_udp_listen(void *data,
1630#endif 1638#endif
1631 const int on = 1; 1639 const int on = 1;
1632 const char *memerr = NULL; 1640 const char *memerr = NULL;
1641#ifdef _WIN32
1642 u_long mode = 1;
1643#endif
1633 1644
1634 type = svr->type; 1645 type = svr->type;
1635 type &= ECORE_CON_TYPE; 1646 type &= ECORE_CON_TYPE;
@@ -1694,8 +1705,13 @@ _ecore_con_cb_udp_listen(void *data,
1694 1705
1695 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0) 1706 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1696 goto error; 1707 goto error;
1708
1709#ifdef _WIN32
1710 if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
1711#else
1697 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; 1712 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1698 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; 1713 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1714#endif
1699 1715
1700 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) 1716 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1701 goto error; 1717 goto error;
@@ -1731,6 +1747,9 @@ _ecore_con_cb_tcp_connect(void *data,
1731 int res; 1747 int res;
1732 int curstate = 0; 1748 int curstate = 0;
1733 const char *memerr = NULL; 1749 const char *memerr = NULL;
1750#ifdef _WIN32
1751 u_long mode = 1;
1752#endif
1734 1753
1735 errno = 0; 1754 errno = 0;
1736 if (!net_info) /* error message has already been handled */ 1755 if (!net_info) /* error message has already been handled */
@@ -1743,8 +1762,12 @@ _ecore_con_cb_tcp_connect(void *data,
1743 net_info->info.ai_protocol); 1762 net_info->info.ai_protocol);
1744 if (svr->fd < 0) goto error; 1763 if (svr->fd < 0) goto error;
1745 1764
1765#ifdef _WIN32
1766 if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
1767#else
1746 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; 1768 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1747 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; 1769 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1770#endif
1748 1771
1749 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0) 1772 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1750 goto error; 1773 goto error;
@@ -1763,7 +1786,7 @@ _ecore_con_cb_tcp_connect(void *data,
1763#ifdef _WIN32 1786#ifdef _WIN32
1764 if (res == SOCKET_ERROR) 1787 if (res == SOCKET_ERROR)
1765 { 1788 {
1766 if (WSAGetLastError() != WSAEINPROGRESS) 1789 if (WSAGetLastError() != WSAEWOULDBLOCK)
1767 { 1790 {
1768 char *err; 1791 char *err;
1769 err = evil_format_message(WSAGetLastError()); 1792 err = evil_format_message(WSAGetLastError());
@@ -1826,6 +1849,9 @@ _ecore_con_cb_udp_connect(void *data,
1826 int broadcast = 1; 1849 int broadcast = 1;
1827 const char *memerr = NULL; 1850 const char *memerr = NULL;
1828 Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS); 1851 Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
1852#ifdef _WIN32
1853 u_long mode = 1;
1854#endif
1829 1855
1830 errno = 0; 1856 errno = 0;
1831 if (!net_info) /* error message has already been handled */ 1857 if (!net_info) /* error message has already been handled */
@@ -1837,8 +1863,13 @@ _ecore_con_cb_udp_connect(void *data,
1837 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, 1863 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1838 net_info->info.ai_protocol); 1864 net_info->info.ai_protocol);
1839 if (svr->fd < 0) goto error; 1865 if (svr->fd < 0) goto error;
1866
1867#ifdef _WIN32
1868 if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
1869#else
1840 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error; 1870 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1841 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; 1871 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1872#endif
1842 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST) 1873 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1843 { 1874 {
1844 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST, 1875 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
@@ -1984,6 +2015,9 @@ _ecore_con_svr_tcp_handler(void *data,
1984 unsigned int client_addr_len; 2015 unsigned int client_addr_len;
1985 const char *clerr = NULL; 2016 const char *clerr = NULL;
1986 Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS); 2017 Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS);
2018#ifdef _WIN32
2019 u_long mode = 1;
2020#endif
1987 2021
1988 if (svr->delete_me) 2022 if (svr->delete_me)
1989 return ECORE_CALLBACK_RENEW; 2023 return ECORE_CALLBACK_RENEW;
@@ -2014,8 +2048,12 @@ _ecore_con_svr_tcp_handler(void *data,
2014 goto error; 2048 goto error;
2015 } 2049 }
2016 2050
2051#ifdef _WIN32
2052 if (ioctlsocket(cl->fd, FIONBIO, &mode)) goto error;
2053#else
2017 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error; 2054 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
2018 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error; 2055 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
2056#endif
2019 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ, 2057 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
2020 _ecore_con_svr_cl_handler, obj, NULL, NULL); 2058 _ecore_con_svr_cl_handler, obj, NULL, NULL);
2021 if (!cl->fd_handler) goto error; 2059 if (!cl->fd_handler) goto error;
@@ -2220,6 +2258,9 @@ _ecore_con_svr_udp_handler(void *data,
2220 int num; 2258 int num;
2221 Ecore_Con_Server *svr_obj = data; 2259 Ecore_Con_Server *svr_obj = data;
2222 Ecore_Con_Client *obj = NULL; 2260 Ecore_Con_Client *obj = NULL;
2261+#ifdef _WIN32
2262+ u_long mode = 1;
2263+#endif
2223 2264
2224 Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS); 2265 Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS);
2225 if (svr->delete_me) 2266 if (svr->delete_me)
@@ -2232,8 +2273,7 @@ _ecore_con_svr_udp_handler(void *data,
2232 return ECORE_CALLBACK_RENEW; 2273 return ECORE_CALLBACK_RENEW;
2233 2274
2234#ifdef _WIN32 2275#ifdef _WIN32
2235 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK); 2276 if (!ioctlsocket(svr->fd, FIONBIO, &mode))
2236 if (num >= 0)
2237 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0, 2277 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2238 (struct sockaddr *)&client_addr, 2278 (struct sockaddr *)&client_addr,
2239 &client_addr_len); 2279 &client_addr_len);