mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
catch EINPROGRESS and WSAEWOULDBLOCK
This commit is contained in:
parent
992cfefc8e
commit
85d94017c7
1 changed files with 21 additions and 4 deletions
|
|
@ -19,10 +19,14 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
using SOCKET = int;
|
||||
#endif // _WIN32
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "debug/Logger.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
||||
|
|
@ -361,11 +365,24 @@ public:
|
|||
|
||||
int res = connectsocket(descriptor, addrinfo->ai_addr, addrinfo->ai_addrlen);
|
||||
if (res == -1) {
|
||||
auto error = handle_socket_error("Connect failed");
|
||||
closesocket(descriptor);
|
||||
freeaddrinfo(addrinfo);
|
||||
throw error;
|
||||
# ifdef _WIN32
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK) {
|
||||
auto error = handle_socket_error("Connect failed");
|
||||
closesocket(descriptor);
|
||||
freeaddrinfo(addrinfo);
|
||||
throw error;
|
||||
}
|
||||
# else
|
||||
if (errno != EINPROGRESS) {
|
||||
auto error = handle_socket_error("Connect failed");
|
||||
closesocket(descriptor);
|
||||
freeaddrinfo(addrinfo);
|
||||
throw error;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
|
||||
logger.info() << "connected to " << address << " ["
|
||||
<< to_string(addrinfo) << ":" << port << "]";
|
||||
return std::make_shared<SocketImpl>(descriptor, addrinfo);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue