Correctly handle failing to connect to the given session in client mode
This commit is contained in:
parent
2cdf578834
commit
459cb212e5
15
src/main.cc
15
src/main.cc
|
@ -228,6 +228,11 @@ int run_client(const String& session, const String& init_command)
|
|||
fputs("disconnected from server\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
catch (connection_failed& e)
|
||||
{
|
||||
fputs(e.what(), stderr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -254,7 +259,15 @@ int kakoune(const ParametersParser& parser)
|
|||
}
|
||||
command += String{buf, buf + count};
|
||||
}
|
||||
send_command(parser.option_value("p"), command);
|
||||
try
|
||||
{
|
||||
send_command(parser.option_value("p"), command);
|
||||
}
|
||||
catch (connection_failed& e)
|
||||
{
|
||||
fputs(e.what(), stderr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -448,7 +448,7 @@ std::unique_ptr<RemoteClient> connect_to(const String& session, std::unique_ptr<
|
|||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, filename.c_str(), sizeof(addr.sun_path) - 1);
|
||||
if (connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) == -1)
|
||||
throw runtime_error("connect to " + filename + " failed");
|
||||
throw connection_failed(filename);
|
||||
|
||||
return std::unique_ptr<RemoteClient>{new RemoteClient{sock, std::move(ui), init_command}};
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ void send_command(const String& session, const String& command)
|
|||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, filename.c_str(), sizeof(addr.sun_path) - 1);
|
||||
if (connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) == -1)
|
||||
throw runtime_error("connect to " + filename + " failed");
|
||||
throw connection_failed(filename);
|
||||
|
||||
{
|
||||
Message msg(sock);
|
||||
|
|
|
@ -10,6 +10,13 @@ namespace Kakoune
|
|||
|
||||
struct peer_disconnected {};
|
||||
|
||||
struct connection_failed : runtime_error
|
||||
{
|
||||
connection_failed(const String& filename)
|
||||
: runtime_error{"connect to " + filename + " failed"}
|
||||
{}
|
||||
};
|
||||
|
||||
// A remote client handle communication between a client running on the server
|
||||
// and a user interface running on the local process.
|
||||
class RemoteClient
|
||||
|
|
Loading…
Reference in New Issue
Block a user