Fix handling of remote errors in the accepter
This commit is contained in:
parent
a6b55074d6
commit
21a76d135c
|
@ -38,8 +38,6 @@ enum class MessageType : char
|
||||||
Key
|
Key
|
||||||
};
|
};
|
||||||
|
|
||||||
struct socket_error{};
|
|
||||||
|
|
||||||
class MsgWriter
|
class MsgWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -231,7 +229,7 @@ private:
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
throw remote_error{"peer disconnected"};
|
throw remote_error{"peer disconnected"};
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
throw socket_error{};
|
throw remote_error{format("socket error, read returned {}", res)};
|
||||||
m_write_pos += res;
|
m_write_pos += res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +357,7 @@ RemoteUI::RemoteUI(int socket, CharCoord dimensions)
|
||||||
disconnect = true;
|
disconnect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (remote_error& err)
|
catch (const remote_error& err)
|
||||||
{
|
{
|
||||||
write_to_debug_buffer(format("Error while reading remote message: {}", err.what()));
|
write_to_debug_buffer(format("Error while reading remote message: {}", err.what()));
|
||||||
disconnect = true;
|
disconnect = true;
|
||||||
|
@ -629,6 +627,8 @@ private:
|
||||||
void handle_available_input()
|
void handle_available_input()
|
||||||
{
|
{
|
||||||
const int sock = m_socket_watcher.fd();
|
const int sock = m_socket_watcher.fd();
|
||||||
|
try
|
||||||
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
m_reader.read_available(sock);
|
m_reader.read_available(sock);
|
||||||
|
@ -652,7 +652,7 @@ private:
|
||||||
ui->set_client(client);
|
ui->set_client(client);
|
||||||
|
|
||||||
Server::instance().remove_accepter(this);
|
Server::instance().remove_accepter(this);
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
case MessageType::Command:
|
case MessageType::Command:
|
||||||
{
|
{
|
||||||
|
@ -662,20 +662,26 @@ private:
|
||||||
Context context{Context::EmptyContextFlag{}};
|
Context context{Context::EmptyContextFlag{}};
|
||||||
CommandManager::instance().execute(command, context);
|
CommandManager::instance().execute(command, context);
|
||||||
}
|
}
|
||||||
catch (runtime_error& e)
|
catch (const runtime_error& e)
|
||||||
{
|
{
|
||||||
write_to_debug_buffer(format("error running command '{}': {}",
|
write_to_debug_buffer(format("error running command '{}': {}",
|
||||||
command, e.what()));
|
command, e.what()));
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
Server::instance().remove_accepter(this);
|
Server::instance().remove_accepter(this);
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
write_to_debug_buffer("Invalid introduction message received");
|
write_to_debug_buffer("Invalid introduction message received");
|
||||||
close(sock);
|
close(sock);
|
||||||
Server::instance().remove_accepter(this);
|
Server::instance().remove_accepter(this);
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
catch (const remote_error& err)
|
||||||
|
{
|
||||||
|
write_to_debug_buffer(format("accepting connection failed: {}", err.what()));
|
||||||
|
close(sock);
|
||||||
|
Server::instance().remove_accepter(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user