Browse Source

tcp_client: close connections when leaving

So you can join another game latter
fix #251
pull/292/head
Mathieu Maret 7 years ago committed by Anders Jenbo
parent
commit
0ac4c1e419
  1. 8
      SourceX/dvlnet/tcp_client.cpp
  2. 1
      SourceX/dvlnet/tcp_client.h

8
SourceX/dvlnet/tcp_client.cpp

@ -17,6 +17,7 @@ int tcp_client::create(std::string addrstr, std::string passwd)
local_server.reset(new tcp_server(ioc, addrstr, port, passwd));
return join(local_server->localhost_self(), passwd);
} catch (std::system_error &e) {
eprintf("%s\n", e.what());
return -1;
}
}
@ -33,6 +34,7 @@ int tcp_client::join(std::string addrstr, std::string passwd)
asio::ip::tcp::no_delay option(true);
sock.set_option(option);
} catch (std::exception &e) {
eprintf("%s\n", e.what());
return -1;
}
start_recv();
@ -104,5 +106,11 @@ void tcp_client::send(packet &pkt)
});
}
bool tcp_client::SNetLeaveGame(int type){
if(sock.is_open())
sock.close();
return true;
}
} // namespace net
} // namespace dvl

1
SourceX/dvlnet/tcp_client.h

@ -19,6 +19,7 @@ class tcp_client : public base {
public:
int create(std::string addrstr, std::string passwd);
int join(std::string addrstr, std::string passwd);
virtual bool SNetLeaveGame(int type);
constexpr static unsigned short default_port = 6112;

Loading…
Cancel
Save