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)
socklen_t name_len = sizeof (name);
NiceSocket *sock;
TcpPriv *priv;
#ifdef G_OS_WIN32
unsigned long set_nonblock=1;
#endif
if (addr == NULL) {
/* We can't connect a tcp socket with no destination address */
......@@ -129,6 +132,8 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
#endif
#ifdef O_NONBLOCK
fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK);
#elif defined G_OS_WIN32
ioctlsocket(sockfd, FIONBIO, &set_nonblock);
#endif
name_len = name.ss_family == AF_INET? sizeof (struct sockaddr_in) :
......@@ -136,7 +141,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
ret = connect (sockfd, (const struct sockaddr *)&name, name_len);
#ifdef G_OS_WIN32
if (ret < 0 && WSAGetLastError () != WSAEINPROGRESS) {
if (ret < 0 && WSAGetLastError () != WSAEWOULDBLOCK) {
closesocket (sockfd);
#else
if (ret < 0 && errno != EINPROGRESS) {
......@@ -258,7 +263,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) {
if (WSAGetLastError () == WSAEWOULDBLOCK ||
WSAGetLastError () == WSAENOTCONN) {
#else
if (errno == EAGAIN) {
#endif
......
......@@ -70,6 +70,9 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
struct sockaddr_storage name;
socklen_t name_len = sizeof (name);
NiceSocket *sock = g_slice_new0 (NiceSocket);
#ifdef G_OS_WIN32
unsigned long set_nonblock=1;
#endif
if (addr != NULL) {
nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name);
......@@ -102,6 +105,8 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
#endif
#ifdef O_NONBLOCK
fcntl (sockfd, F_SETFL, fcntl (sockfd, F_GETFL) | O_NONBLOCK);
#elif defined G_OS_WIN32
ioctlsocket(sockfd, FIONBIO, &set_nonblock);
#endif
if(bind (sockfd, (struct sockaddr *) &name,
......
......@@ -227,6 +227,10 @@ stun_trans_init (StunTransport *tr, int fd,
*/
static int stun_socket (int family, int type, int proto)
{
#ifdef _WIN32
unsigned long set_nonblock=1;
#endif
int fd = socket (family, type, proto);
if (fd == -1)
return -1;
......@@ -236,6 +240,8 @@ static int stun_socket (int family, int type, int proto)
#endif
#ifdef O_NONBLOCK
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) | O_NONBLOCK);
#elif defined _WIN32
ioctlsocket(fd, FIONBIO, &set_nonblock);
#endif
#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