diff --git a/src/cpp/ripple/AutoSocket.h b/src/cpp/ripple/AutoSocket.h index d96582525..95f513872 100644 --- a/src/cpp/ripple/AutoSocket.h +++ b/src/cpp/ripple/AutoSocket.h @@ -2,6 +2,7 @@ #define __AUTOSOCKET_H_ #include +#include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include "Log.h" extern LogPartition AutoSocketPartition; @@ -103,6 +105,24 @@ public: PlainSocket().async_read_some(buffers, handler); } + template + void async_read_until(const Seq& buffers, Condition condition, Handler handler) + { + if (isSecure()) + basio::async_read_until(*mSocket, buffers, condition, handler); + else + basio::async_read_until(PlainSocket(), buffers, condition, handler); + } + + template + void async_read_until(basio::basic_streambuf& buffers, const std::string& delim, Handler handler) + { + if (isSecure()) + basio::async_read_until(*mSocket, buffers, delim, handler); + else + basio::async_read_until(PlainSocket(), buffers, delim, handler); + } + template void async_write(const Buf& buffers, Handler handler) { if (isSecure()) @@ -121,6 +141,15 @@ public: boost::asio::async_read(PlainSocket(), buffers, cond, handler); } + template + void async_read(basio::basic_streambuf& buffers, Condition cond, Handler handler) + { + if (isSecure()) + boost::asio::async_read(*mSocket, buffers, cond, handler); + else + boost::asio::async_read(PlainSocket(), buffers, cond, handler); + } + template void async_read(const Buf& buffers, Handler handler) { if (isSecure()) diff --git a/src/cpp/websocketpp/src/connection.hpp b/src/cpp/websocketpp/src/connection.hpp index 9883148ac..50a71b58c 100644 --- a/src/cpp/websocketpp/src/connection.hpp +++ b/src/cpp/websocketpp/src/connection.hpp @@ -899,38 +899,18 @@ public: { // TODO: read timeout timer? - if (socket_type::get_socket().isSecure()) - { - boost::asio::async_read( - socket_type::get_socket().SSLSocket(), - m_buf, - boost::asio::transfer_at_least(std::min( - m_read_threshold, - static_cast(m_processor->get_bytes_needed()) - )), - m_strand.wrap(boost::bind( - &type::handle_read_frame, - type::shared_from_this(), - boost::asio::placeholders::error - )) - ); - } - else - { - boost::asio::async_read( - socket_type::get_socket().PlainSocket(), - m_buf, - boost::asio::transfer_at_least(std::min( - m_read_threshold, - static_cast(m_processor->get_bytes_needed()) - )), - m_strand.wrap(boost::bind( - &type::handle_read_frame, - type::shared_from_this(), - boost::asio::placeholders::error - )) - ); - } + socket_type::get_socket().async_read( + m_buf, + boost::asio::transfer_at_least(std::min( + m_read_threshold, + static_cast(m_processor->get_bytes_needed()) + )), + m_strand.wrap(boost::bind( + &type::handle_read_frame, + type::shared_from_this(), + boost::asio::placeholders::error + )) + ); } } public: @@ -1228,31 +1208,14 @@ public: //m_endpoint.alog().at(log::alevel::DEVEL) << "write header: " << zsutil::to_hex(m_write_queue.front()->get_header()) << log::endl; - if (socket_type::get_socket().isSecure()) - { - boost::asio::async_write( - socket_type::get_socket().SSLSocket(), - m_write_buf, - m_strand.wrap(boost::bind( - &type::handle_write, - type::shared_from_this(), - boost::asio::placeholders::error - )) - ); - } - else - { - boost::asio::async_write( - socket_type::get_socket().PlainSocket(), - m_write_buf, - m_strand.wrap(boost::bind( - &type::handle_write, - type::shared_from_this(), - boost::asio::placeholders::error - )) - ); - } - + socket_type::get_socket().async_write( + m_write_buf, + m_strand.wrap(boost::bind( + &type::handle_write, + type::shared_from_this(), + boost::asio::placeholders::error + )) + ); } else { // if we are in an inturrupted state and had nothing else to write // it is safe to terminate the connection. diff --git a/src/cpp/websocketpp/src/roles/server.hpp b/src/cpp/websocketpp/src/roles/server.hpp index 0e3de9db8..abffa3f3b 100644 --- a/src/cpp/websocketpp/src/roles/server.hpp +++ b/src/cpp/websocketpp/src/roles/server.hpp @@ -544,36 +544,17 @@ void server::connection::async_init() { m_connection.register_timeout(5000,fail::status::TIMEOUT_WS, "Timeout on WebSocket handshake"); - if (m_connection.get_socket().isSecure()) - { - boost::asio::async_read_until( - m_connection.get_socket().SSLSocket(), - m_connection.buffer(), -// match_header, - "\r\n\r\n", - m_connection.get_strand().wrap(boost::bind( - &type::handle_read_request, - m_connection.shared_from_this(), - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred - )) - ); - } - else - { - boost::asio::async_read_until( - m_connection.get_socket().PlainSocket(), - m_connection.buffer(), -// match_header, - "\r\n\r\n", - m_connection.get_strand().wrap(boost::bind( - &type::handle_read_request, - m_connection.shared_from_this(), - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred - )) - ); - } + m_connection.get_socket().async_read_until( + m_connection.buffer(), +// match_header, + std::string("\r\n\r\n"), + m_connection.get_strand().wrap(boost::bind( + &type::handle_read_request, + m_connection.shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred + )) + ); } /// processes the response from an async read for an HTTP header