From a42c87e6a761a56ebc63cd7728fa2126b2e8805f Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Sat, 2 Nov 2013 12:27:10 +0100 Subject: (re)unify client iostreams boost::iostreams does not do lseek()s without being asked extend try-block around entire function --- ssh-agent-filter.C | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C index b4234c3..8ee6aaf 100644 --- a/ssh-agent-filter.C +++ b/ssh-agent-filter.C @@ -427,22 +427,17 @@ rfc4251string handle_request (rfc4251string const & r) { return rfc4251string{answer.str()}; } -void handle_client (int const sock) { - // we could use only one streambuf and iostream but when - // switching from read to write an lseek call is made that - // fails with ESPIPE and causes an exception - io::stream_buffer client_filebuf_in{sock, io::close_handle}; - io::stream_buffer client_filebuf_out{sock, io::never_close_handle}; - std::istream client_in{&client_filebuf_in}; - std::ostream client_out{&client_filebuf_out}; - client_out.exceptions(std::ios::badbit | std::ios::failbit); +void handle_client (int const sock) try { + io::stream_buffer client_filebuf{sock, io::close_handle}; + std::iostream client{&client_filebuf}; + client.exceptions(std::ios::badbit | std::ios::failbit); - rfc4251string request; - while (client_in >> request) try { - client_out << handle_request(request) << std::flush; - } catch (...) { - break; + for (;;) { + rfc4251string request; + client >> request; + client << handle_request(request) << std::flush; } +} catch (...) { } void sighandler (int sig) { -- cgit v1.2.3