mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +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 <arpa/inet.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
using SOCKET = int;
|
using SOCKET = int;
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
||||||
|
|
@ -361,11 +365,24 @@ public:
|
||||||
|
|
||||||
int res = connectsocket(descriptor, addrinfo->ai_addr, addrinfo->ai_addrlen);
|
int res = connectsocket(descriptor, addrinfo->ai_addr, addrinfo->ai_addrlen);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
auto error = handle_socket_error("Connect failed");
|
# ifdef _WIN32
|
||||||
closesocket(descriptor);
|
if (WSAGetLastError() != WSAEWOULDBLOCK) {
|
||||||
freeaddrinfo(addrinfo);
|
auto error = handle_socket_error("Connect failed");
|
||||||
throw error;
|
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 << " ["
|
logger.info() << "connected to " << address << " ["
|
||||||
<< to_string(addrinfo) << ":" << port << "]";
|
<< to_string(addrinfo) << ":" << port << "]";
|
||||||
return std::make_shared<SocketImpl>(descriptor, addrinfo);
|
return std::make_shared<SocketImpl>(descriptor, addrinfo);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue