Browse Source

Use asio to resolve host name (or IP)

Fixes #735
pull/742/head
Marcin Konicki 6 years ago committed by GitHub
parent
commit
2a5d3b6c52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      SourceX/DiabloUI/selgame.cpp
  2. 8
      SourceX/dvlnet/tcp_client.cpp
  3. 1
      SourceX/dvlnet/tcp_client.h

5
SourceX/DiabloUI/selgame.cpp

@ -53,7 +53,7 @@ constexpr UiArtText SELUDPGAME_DESCRIPTION_LABEL = UiArtText("Description:", { P
UiListItem SELUDPGAME_DIALOG_ITEMS[] = {
{ "Create Game", 0 },
{ "Enter IP", 1 },
{ "Join Game", 1 },
};
UiItem SELUDPGAME_DIALOG[] = {
MAINMENU_BACKGROUND,
@ -73,7 +73,8 @@ UiItem ENTERIP_DIALOG[] = {
SELUDPGAME_TITLE,
SELUDPGAME_DESCRIPTION_LABEL,
SELGAME_DESCRIPTION,
UiArtText("Enter IP", { PANEL_LEFT + 305, 211, 285, 33 }, UIS_CENTER | UIS_BIG),
UiArtText("Enter address", { PANEL_LEFT + 305, 211, 285, 33 }, UIS_CENTER | UIS_BIG),
UiEdit(selgame_Ip, 128, { PANEL_LEFT + 305, 314, 285, 33 }, UIS_MED | UIS_GOLD),
SELGAME_OK,
SELGAME_CANCEL,

8
SourceX/dvlnet/tcp_client.cpp

@ -2,11 +2,14 @@
#include <functional>
#include <exception>
#include <sstream>
#include <system_error>
#include <stdexcept>
#include <sodium.h>
#include <SDL.h>
#include <asio/connect.hpp>
namespace dvl {
namespace net {
@ -29,8 +32,9 @@ int tcp_client::join(std::string addrstr, std::string passwd)
setup_password(passwd);
try {
auto ipaddr = asio::ip::make_address(addrstr);
sock.connect(asio::ip::tcp::endpoint(ipaddr, default_port));
std::stringstream port;
port << default_port;
asio::connect(sock, resolver.resolve(addrstr, port.str()));
asio::ip::tcp::no_delay option(true);
sock.set_option(option);
} catch (std::exception &e) {

1
SourceX/dvlnet/tcp_client.h

@ -34,6 +34,7 @@ private:
buffer_t recv_buffer = buffer_t(frame_queue::max_frame_size);
asio::io_context ioc;
asio::ip::tcp::resolver resolver = asio::ip::tcp::resolver(ioc);
asio::ip::tcp::socket sock = asio::ip::tcp::socket(ioc);
std::unique_ptr<tcp_server> local_server; // must be declared *after* ioc

Loading…
Cancel
Save