From b05034bc176b38b3b3f31c7a2e1e53b4c16f61e2 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Sat, 2 Nov 2013 11:38:40 +0100 Subject: replace __gnu_cxx::stdio_filebuf with boost::iostreams --- ssh-agent-filter.C | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ssh-agent-filter.C') diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C index dd1b508..b4234c3 100644 --- a/ssh-agent-filter.C +++ b/ssh-agent-filter.C @@ -25,6 +25,10 @@ namespace po = boost::program_options; #include namespace fs = boost::filesystem; +#include +#include +namespace io = boost::iostreams; + #include #include #include @@ -32,7 +36,6 @@ namespace fs = boost::filesystem; #include #include #include -#include #include #include @@ -201,7 +204,7 @@ void parse_cmdline (int const argc, char const * const * const argv) { } void setup_filters () { - __gnu_cxx::stdio_filebuf agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out}; + io::stream_buffer agent_filebuf{make_upstream_agent_conn(), io::close_handle}; std::iostream agent{&agent_filebuf}; agent.exceptions(std::ios::badbit | std::ios::failbit); @@ -325,7 +328,7 @@ rfc4251string handle_request (rfc4251string const & r) { switch (request_code) { case SSH2_AGENTC_REQUEST_IDENTITIES: { - __gnu_cxx::stdio_filebuf agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out}; + io::stream_buffer agent_filebuf{make_upstream_agent_conn(), io::close_handle}; std::iostream agent{&agent_filebuf}; agent.exceptions(std::ios::badbit | std::ios::failbit); rfc4251string agent_answer; @@ -383,7 +386,7 @@ rfc4251string handle_request (rfc4251string const & r) { } if (allow) { - __gnu_cxx::stdio_filebuf agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out}; + io::stream_buffer agent_filebuf{make_upstream_agent_conn(), io::close_handle}; std::iostream agent{&agent_filebuf}; agent.exceptions(std::ios::badbit | std::ios::failbit); rfc4251string agent_answer; @@ -428,8 +431,8 @@ 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 - __gnu_cxx::stdio_filebuf client_filebuf_in{sock, std::ios::in}; - __gnu_cxx::stdio_filebuf client_filebuf_out{sock, std::ios::out}; + 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); -- cgit v1.2.3 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(-) (limited to 'ssh-agent-filter.C') 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