From bedf2f703cb3dc97467e662e6750fcd369309e6b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 9 Aug 2016 21:45:06 +0100 Subject: [PATCH] Small code cleanups --- src/file.cc | 2 +- src/remote.cc | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/file.cc b/src/file.cc index fdca896f..f8928243 100644 --- a/src/file.cc +++ b/src/file.cc @@ -216,7 +216,7 @@ void write(int fd, StringView data) count -= written; if (written == -1) - throw file_access_error("fd: " + to_string(fd), strerror(errno)); + throw file_access_error(format("fd: {}", fd), strerror(errno)); } } diff --git a/src/remote.cc b/src/remote.cc index 798b14ee..ca079427 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -548,9 +548,8 @@ void RemoteClient::write_next_key() void send_command(StringView session, StringView command) { int sock = connect_to(session); - if (::write(sock, command.data(), (int)command.length()) < 0) - throw runtime_error(format("unable to write data to socket (fd: {}; errno: {})", sock, ::strerror(errno))); - close(sock); + auto close_sock = on_scope_end([sock]{ close(sock); }); + write(sock, command); }