Fixed Windows connect() bug for TcpSocket
The socket is put into non-blocking mode prior to connecting. Previously, errno was being checked after connecting to see if the socket would block. This is the correct behaviour on Linux. On Windows however, errno remains 0, and WSAGetLastError() needs to be compared against WSAEWOULDBLOCK instead.
This commit is contained in:
parent
4dec5318f7
commit
fb28a03c2b
@ -88,7 +88,7 @@ namespace fr
|
|||||||
mbedtls_ssl_init(ssl.get());
|
mbedtls_ssl_init(ssl.get());
|
||||||
mbedtls_net_init(ssl_socket_descriptor.get());
|
mbedtls_net_init(ssl_socket_descriptor.get());
|
||||||
|
|
||||||
//Do to mbedtls not supporting connect timeouts, we have to use an fr::TcpSocket to
|
//Due to mbedtls not supporting connect timeouts, we have to use an fr::TcpSocket to
|
||||||
//Open the descriptor, and then steal it. This is a hack.
|
//Open the descriptor, and then steal it. This is a hack.
|
||||||
{
|
{
|
||||||
fr::TcpSocket socket;
|
fr::TcpSocket socket;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace fr
|
|||||||
{
|
{
|
||||||
|
|
||||||
TcpSocket::TcpSocket() noexcept
|
TcpSocket::TcpSocket() noexcept
|
||||||
: socket_descriptor(-1)
|
: socket_descriptor(-1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ namespace fr
|
|||||||
received = 0;
|
received = 0;
|
||||||
|
|
||||||
//Read RECV_CHUNK_SIZE bytes into the recv buffer
|
//Read RECV_CHUNK_SIZE bytes into the recv buffer
|
||||||
int64_t status = ::recv(socket_descriptor, (char*)data, buffer_size, 0);
|
int64_t status = ::recv(socket_descriptor, (char*)data, buffer_size, 0);
|
||||||
|
|
||||||
if(status > 0)
|
if(status > 0)
|
||||||
{
|
{
|
||||||
@ -125,10 +125,18 @@ namespace fr
|
|||||||
|
|
||||||
//Try and connect
|
//Try and connect
|
||||||
ret = ::connect(socket_descriptor, c->ai_addr, c->ai_addrlen);
|
ret = ::connect(socket_descriptor, c->ai_addr, c->ai_addrlen);
|
||||||
|
#ifdef _WIN32
|
||||||
|
if(ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK)
|
||||||
|
#else
|
||||||
if(ret < 0 && errno != EINPROGRESS)
|
if(ret < 0 && errno != EINPROGRESS)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
else if(ret == 0) //If it connected immediately then break out of the connect loop
|
else if(ret == 0) //If it connected immediately then break out of the connect loop
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//Wait for the socket to do something/expire
|
//Wait for the socket to do something/expire
|
||||||
timeval tv = {};
|
timeval tv = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user