fix:修正当没有找到local IP时的崩溃问题。
This commit is contained in:
parent
8307a50f16
commit
f19b1e3f4d
@ -25,18 +25,23 @@ bool CTcpServer::start(unsigned short port)
|
|||||||
{
|
{
|
||||||
asio::ip::tcp::resolver resolver(io_context_);
|
asio::ip::tcp::resolver resolver(io_context_);
|
||||||
asio::ip::tcp::resolver::query query(asio::ip::host_name(), "");
|
asio::ip::tcp::resolver::query query(asio::ip::host_name(), "");
|
||||||
asio::ip::tcp::resolver::iterator it = resolver.resolve(query);
|
|
||||||
|
|
||||||
mpdebug("Here are the local IP addresses you may use.");
|
try {
|
||||||
mpdebug("===========================================");
|
auto it = resolver.resolve(query);
|
||||||
int i = 1;
|
mpdebug("Here are the local IP addresses you may use.");
|
||||||
while (it != asio::ip::tcp::resolver::iterator()) {
|
mpdebug("===========================================");
|
||||||
asio::ip::address addr = it->endpoint().address();
|
int i = 1;
|
||||||
mpinfo("({}){}", i, addr.to_string());
|
while (it != asio::ip::tcp::resolver::iterator()) {
|
||||||
++it;
|
asio::ip::address addr = it->endpoint().address();
|
||||||
++i;
|
mpinfo("({}){}", i, addr.to_string());
|
||||||
|
++it;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
mpdebug("===========================================");
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
mpwarn("{}", e.what());
|
||||||
|
mpinfo("will not show local IP.");
|
||||||
}
|
}
|
||||||
mpdebug("===========================================");
|
|
||||||
|
|
||||||
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port);
|
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port);
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user