|
|
|
|
@ -17,14 +17,9 @@ namespace devilution::net {
|
|
|
|
|
|
|
|
|
|
int tcp_client::create(std::string addrstr) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
auto port = *sgOptions.Network.port; |
|
|
|
|
local_server = std::make_unique<tcp_server>(ioc, addrstr, port, *pktfty); |
|
|
|
|
return join(local_server->LocalhostSelf()); |
|
|
|
|
} catch (std::system_error &e) { |
|
|
|
|
SDL_SetError("%s", e.what()); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
auto port = *sgOptions.Network.port; |
|
|
|
|
local_server = std::make_unique<tcp_server>(ioc, addrstr, port, *pktfty); |
|
|
|
|
return join(local_server->LocalhostSelf()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int tcp_client::join(std::string addrstr) |
|
|
|
|
@ -32,16 +27,26 @@ int tcp_client::join(std::string addrstr)
|
|
|
|
|
constexpr int MsSleep = 10; |
|
|
|
|
constexpr int NoSleep = 250; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
std::stringstream port; |
|
|
|
|
port << *sgOptions.Network.port; |
|
|
|
|
asio::connect(sock, resolver.resolve(addrstr, port.str())); |
|
|
|
|
asio::ip::tcp::no_delay option(true); |
|
|
|
|
sock.set_option(option); |
|
|
|
|
} catch (std::exception &e) { |
|
|
|
|
SDL_SetError("%s", e.what()); |
|
|
|
|
std::string port = StrCat(*sgOptions.Network.port); |
|
|
|
|
|
|
|
|
|
asio::error_code errorCode; |
|
|
|
|
asio::ip::basic_resolver_results<asio::ip::tcp> range = resolver.resolve(addrstr, port, errorCode); |
|
|
|
|
if (errorCode) { |
|
|
|
|
SDL_SetError("%s", errorCode.message().c_str()); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
asio::connect(sock, range, errorCode); |
|
|
|
|
if (errorCode) { |
|
|
|
|
SDL_SetError("%s", errorCode.message().c_str()); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
asio::ip::tcp::no_delay option(true); |
|
|
|
|
sock.set_option(option, errorCode); |
|
|
|
|
if (errorCode) |
|
|
|
|
LogError("Client error setting socket option: {}", errorCode.message()); |
|
|
|
|
|
|
|
|
|
StartReceive(); |
|
|
|
|
{ |
|
|
|
|
cookie_self = packet_out::GenerateCookie(); |
|
|
|
|
|