Commit 6039152c authored by Youness Alaoui's avatar Youness Alaoui

use WSAGetLastError instead of errno

parent ddd7c552
...@@ -54,10 +54,6 @@ ...@@ -54,10 +54,6 @@
#include "tcp-turn.h" #include "tcp-turn.h"
#ifdef G_OS_WIN32
#define EINPROGRESS WSAEINPROGRESS
#endif
typedef struct { typedef struct {
NiceUdpTurnSocketCompatibility compatibility; NiceUdpTurnSocketCompatibility compatibility;
GQueue send_queue; GQueue send_queue;
...@@ -101,7 +97,11 @@ socket_recv ( ...@@ -101,7 +97,11 @@ socket_recv (
ret = read (sock->fileno, priv->recv_buf + priv->recv_buf_len, ret = read (sock->fileno, priv->recv_buf + priv->recv_buf_len,
headerlen - priv->recv_buf_len); headerlen - priv->recv_buf_len);
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK)
#else
if (errno == EAGAIN) if (errno == EAGAIN)
#endif
return 0; return 0;
else else
return ret; return ret;
...@@ -139,7 +139,11 @@ socket_recv ( ...@@ -139,7 +139,11 @@ socket_recv (
ret = read (sock->fileno, priv->recv_buf + priv->recv_buf_len, ret = read (sock->fileno, priv->recv_buf + priv->recv_buf_len,
priv->expecting_len + padlen - priv->recv_buf_len); priv->expecting_len + padlen - priv->recv_buf_len);
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK)
#else
if (errno == EAGAIN) if (errno == EAGAIN)
#endif
return 0; return 0;
else else
return ret; return ret;
...@@ -188,7 +192,11 @@ socket_send_more ( ...@@ -188,7 +192,11 @@ socket_send_more (
ret = write (sock->fileno, tbs->buf, tbs->length); ret = write (sock->fileno, tbs->buf, tbs->length);
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) {
#else
if (errno == EAGAIN) { if (errno == EAGAIN) {
#endif
add_to_be_sent (sock, tbs->buf, tbs->length, TRUE); add_to_be_sent (sock, tbs->buf, tbs->length, TRUE);
g_free (tbs->buf); g_free (tbs->buf);
g_slice_free (struct to_be_sent, tbs); g_slice_free (struct to_be_sent, tbs);
...@@ -267,15 +275,19 @@ socket_send ( ...@@ -267,15 +275,19 @@ socket_send (
ret = write (sock->fileno, &tmpbuf, sizeof(guint16)); ret = write (sock->fileno, &tmpbuf, sizeof(guint16));
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) {
#else
if (errno == EAGAIN) { if (errno == EAGAIN) {
add_to_be_sent (sock, (gchar*) &tmpbuf, sizeof(guint16), FALSE); #endif
add_to_be_sent (sock, (gchar *) &tmpbuf, sizeof(guint16), FALSE);
add_to_be_sent (sock, buf, len, FALSE); add_to_be_sent (sock, buf, len, FALSE);
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
} }
} else if ((guint)ret < sizeof(guint16)) { } else if ((guint)ret < sizeof(guint16)) {
add_to_be_sent (sock, ((gchar*) &tmpbuf) + ret, add_to_be_sent (sock, ((gchar *) &tmpbuf) + ret,
sizeof(guint16) - ret, FALSE); sizeof(guint16) - ret, FALSE);
add_to_be_sent (sock, buf, len, FALSE); add_to_be_sent (sock, buf, len, FALSE);
return TRUE; return TRUE;
...@@ -285,7 +297,11 @@ socket_send ( ...@@ -285,7 +297,11 @@ socket_send (
ret = write (sock->fileno, buf, len); ret = write (sock->fileno, buf, len);
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) {
#else
if (errno == EAGAIN) { if (errno == EAGAIN) {
#endif
add_to_be_sent (sock, buf, len, FALSE); add_to_be_sent (sock, buf, len, FALSE);
add_to_be_sent (sock, padbuf, padlen, FALSE); add_to_be_sent (sock, padbuf, padlen, FALSE);
return TRUE; return TRUE;
...@@ -304,7 +320,11 @@ socket_send ( ...@@ -304,7 +320,11 @@ socket_send (
ret = write (sock->fileno, padbuf, padlen); ret = write (sock->fileno, padbuf, padlen);
if (ret < 0) { if (ret < 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () == WSAEWOULDBLOCK) {
#else
if (errno == EAGAIN) { if (errno == EAGAIN) {
#endif
add_to_be_sent (sock, padbuf, padlen, FALSE); add_to_be_sent (sock, padbuf, padlen, FALSE);
return TRUE; return TRUE;
} else { } else {
...@@ -400,7 +420,11 @@ nice_tcp_turn_socket_new ( ...@@ -400,7 +420,11 @@ nice_tcp_turn_socket_new (
ret = connect (sockfd, (const struct sockaddr *)&name, name_len); ret = connect (sockfd, (const struct sockaddr *)&name, name_len);
#ifdef G_OS_WIN32
if (ret < 0 && WSAGetLastError () != WSAEINPROGRESS) {
#else
if (ret < 0 && errno != EINPROGRESS) { if (ret < 0 && errno != EINPROGRESS) {
#endif
close (sockfd); close (sockfd);
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
return NULL; return NULL;
......
...@@ -165,8 +165,11 @@ static void numb (void) ...@@ -165,8 +165,11 @@ static void numb (void)
assert (fd != -1); assert (fd != -1);
val = connect (fd,res->ai_addr, res->ai_addrlen); val = connect (fd,res->ai_addr, res->ai_addrlen);
#ifdef G_OS_WIN32
assert (val == 0 || (WSAGetLastError () == WSAEINPROGRESS));
#else
assert (val == 0 || (errno == EINPROGRESS)); assert (val == 0 || (errno == EINPROGRESS));
#endif
memset (&hints, 0, sizeof (hints)); memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
......
...@@ -135,9 +135,14 @@ int stun_trans_create (stun_trans_t *restrict tr, int type, int proto, ...@@ -135,9 +135,14 @@ int stun_trans_create (stun_trans_t *restrict tr, int type, int proto,
if (fd == -1) if (fd == -1)
return errno; return errno;
if (connect (fd, srv, srvlen) && (errno != EINPROGRESS)) if (connect (fd, srv, srvlen) &&
{ #ifdef _WIN32
(WSAGetLastError () != WSAEINPROGRESS)) {
val = WSAGetLastError ();
#else
(errno != EINPROGRESS)) {
val = errno; val = errno;
#endif
goto error; goto error;
} }
......
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