Commit 146ce0f8 authored by Livio Madaro's avatar Livio Madaro Committed by Youness Alaoui

set nonblocking mode for socket on Windows

parent 7973ba49
...@@ -93,6 +93,9 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -93,6 +93,9 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
socklen_t name_len = sizeof (name); socklen_t name_len = sizeof (name);
NiceSocket *sock; NiceSocket *sock;
TcpPriv *priv; TcpPriv *priv;
#ifdef G_OS_WIN32
unsigned long set_nonblock=1;
#endif
if (addr == NULL) { if (addr == NULL) {
/* We can't connect a tcp socket with no destination address */ /* We can't connect a tcp socket with no destination address */
...@@ -129,6 +132,8 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -129,6 +132,8 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
#endif #endif
#ifdef O_NONBLOCK #ifdef O_NONBLOCK
fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK); fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK);
#elif defined G_OS_WIN32
ioctlsocket(sockfd, FIONBIO, &set_nonblock);
#endif #endif
name_len = name.ss_family == AF_INET? sizeof (struct sockaddr_in) : name_len = name.ss_family == AF_INET? sizeof (struct sockaddr_in) :
...@@ -136,7 +141,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -136,7 +141,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
ret = connect (sockfd, (const struct sockaddr *)&name, name_len); ret = connect (sockfd, (const struct sockaddr *)&name, name_len);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (ret < 0 && WSAGetLastError () != WSAEINPROGRESS) { if (ret < 0 && WSAGetLastError () != WSAEWOULDBLOCK) {
closesocket (sockfd); closesocket (sockfd);
#else #else
if (ret < 0 && errno != EINPROGRESS) { if (ret < 0 && errno != EINPROGRESS) {
...@@ -258,7 +263,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -258,7 +263,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) { if (WSAGetLastError () == WSAEWOULDBLOCK ||
WSAGetLastError () == WSAENOTCONN) {
#else #else
if (errno == EAGAIN) { if (errno == EAGAIN) {
#endif #endif
......
...@@ -70,6 +70,9 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -70,6 +70,9 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
struct sockaddr_storage name; struct sockaddr_storage name;
socklen_t name_len = sizeof (name); socklen_t name_len = sizeof (name);
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock = g_slice_new0 (NiceSocket);
#ifdef G_OS_WIN32
unsigned long set_nonblock=1;
#endif
if (addr != NULL) { if (addr != NULL) {
nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name); nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name);
...@@ -102,6 +105,8 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -102,6 +105,8 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
#endif #endif
#ifdef O_NONBLOCK #ifdef O_NONBLOCK
fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK); fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK);
#elif defined G_OS_WIN32
ioctlsocket(sockfd, FIONBIO, &set_nonblock);
#endif #endif
if(bind (sockfd, (struct sockaddr *) &name, if(bind (sockfd, (struct sockaddr *) &name,
......
...@@ -227,6 +227,10 @@ stun_trans_init (StunTransport *tr, int fd, ...@@ -227,6 +227,10 @@ stun_trans_init (StunTransport *tr, int fd,
*/ */
static int stun_socket (int family, int type, int proto) static int stun_socket (int family, int type, int proto)
{ {
#ifdef _WIN32
unsigned long set_nonblock=1;
#endif
int fd = socket (family, type, proto); int fd = socket (family, type, proto);
if (fd == -1) if (fd == -1)
return -1; return -1;
...@@ -236,6 +240,8 @@ static int stun_socket (int family, int type, int proto) ...@@ -236,6 +240,8 @@ static int stun_socket (int family, int type, int proto)
#endif #endif
#ifdef O_NONBLOCK #ifdef O_NONBLOCK
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) | O_NONBLOCK); fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) | O_NONBLOCK);
#elif defined _WIN32
ioctlsocket(fd, FIONBIO, &set_nonblock);
#endif #endif
#ifdef MSG_ERRQUEUE #ifdef MSG_ERRQUEUE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment