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 : 66da77d491
This commit is contained in:
parent
fbb8236700
commit
0e8e4b2728
|
@ -1523,6 +1523,9 @@ _ecore_con_cb_tcp_listen(void *data,
|
|||
Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
|
||||
struct linger lin;
|
||||
const char *memerr = NULL;
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
if (!net_info) /* error message has already been handled */
|
||||
|
@ -1573,8 +1576,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 (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
|
||||
|
||||
lin.l_onoff = 1;
|
||||
lin.l_linger = 0;
|
||||
|
@ -1630,6 +1638,9 @@ _ecore_con_cb_udp_listen(void *data,
|
|||
#endif
|
||||
const int on = 1;
|
||||
const char *memerr = NULL;
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
#endif
|
||||
|
||||
type = svr->type;
|
||||
type &= ECORE_CON_TYPE;
|
||||
|
@ -1694,8 +1705,13 @@ _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;
|
||||
|
@ -1731,6 +1747,9 @@ _ecore_con_cb_tcp_connect(void *data,
|
|||
int res;
|
||||
int curstate = 0;
|
||||
const char *memerr = NULL;
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
if (!net_info) /* error message has already been handled */
|
||||
|
@ -1743,8 +1762,12 @@ _ecore_con_cb_tcp_connect(void *data,
|
|||
net_info->info.ai_protocol);
|
||||
if (svr->fd < 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 (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
|
||||
goto error;
|
||||
|
@ -1763,7 +1786,7 @@ _ecore_con_cb_tcp_connect(void *data,
|
|||
#ifdef _WIN32
|
||||
if (res == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAEINPROGRESS)
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
{
|
||||
char *err;
|
||||
err = evil_format_message(WSAGetLastError());
|
||||
|
@ -1826,6 +1849,9 @@ _ecore_con_cb_udp_connect(void *data,
|
|||
int broadcast = 1;
|
||||
const char *memerr = NULL;
|
||||
Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
if (!net_info) /* error message has already been handled */
|
||||
|
@ -1837,8 +1863,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 (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 ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
|
||||
{
|
||||
if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
|
||||
|
@ -1984,6 +2015,9 @@ _ecore_con_svr_tcp_handler(void *data,
|
|||
unsigned int client_addr_len;
|
||||
const char *clerr = NULL;
|
||||
Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS);
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
#endif
|
||||
|
||||
if (svr->delete_me)
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
|
@ -2014,8 +2048,12 @@ _ecore_con_svr_tcp_handler(void *data,
|
|||
goto error;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ioctlsocket(cl->fd, FIONBIO, &mode)) goto error;
|
||||
#else
|
||||
if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
||||
if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
||||
#endif
|
||||
cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
|
||||
_ecore_con_svr_cl_handler, obj, NULL, NULL);
|
||||
if (!cl->fd_handler) goto error;
|
||||
|
@ -2220,6 +2258,9 @@ _ecore_con_svr_udp_handler(void *data,
|
|||
int num;
|
||||
Ecore_Con_Server *svr_obj = data;
|
||||
Ecore_Con_Client *obj = NULL;
|
||||
+#ifdef _WIN32
|
||||
+ u_long mode = 1;
|
||||
+#endif
|
||||
|
||||
Ecore_Con_Server_Data *svr = eo_data_scope_get(svr_obj, ECORE_CON_SERVER_CLASS);
|
||||
if (svr->delete_me)
|
||||
|
@ -2232,8 +2273,7 @@ _ecore_con_svr_udp_handler(void *data,
|
|||
return ECORE_CALLBACK_RENEW;
|
||||
|
||||
#ifdef _WIN32
|
||||
num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
|
||||
if (num >= 0)
|
||||
if (!ioctlsocket(svr->fd, FIONBIO, &mode))
|
||||
num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&client_addr,
|
||||
&client_addr_len);
|
||||
|
|
Loading…
Reference in New Issue