From 6bd62edb43e60a4103dda857a930b79221f87acd Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Tue, 7 May 2013 09:37:37 -0500 Subject: [PATCH] removes unused code & updates naming conventions --- websocketpp/connection.hpp | 10 ++-- websocketpp/impl/connection_impl.hpp | 78 +++------------------------- 2 files changed, 12 insertions(+), 76 deletions(-) diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index e54209de40..62b0e8ce53 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -773,14 +773,12 @@ public: void start(); - void read(size_t num_bytes); - void handle_read(const lib::error_code& ec, size_t bytes_transferred); - + void read_handshake(size_t num_bytes); - void write(std::string msg); - void handle_write(const lib::error_code& ec); + //void write(std::string msg); + //void handle_write(const lib::error_code& ec); - void handle_handshake_read(const lib::error_code& ec, + void handle_read_handshake(const lib::error_code& ec, size_t bytes_transferred); void handle_read_http_response(const lib::error_code& ec, size_t bytes_transferred); diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 314097d199..21d56c68da 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -557,25 +557,18 @@ void connection::handle_transport_init(const lib::error_code& ec) { } // At this point the transport is ready to read and write bytes. - if (m_is_server) { - this->read(1); + this->read_handshake(1); } else { // We are a client. Set the processor to the version specified in the // config file and send a handshake request. m_processor = get_processor(config::client_version); this->send_http_request(); } - - // TODO: Begin websocket handshake - // server: read/process/write/go - // client: process/write/read/process/go - - //this->read(); } template -void connection::read(size_t num_bytes) { +void connection::read_handshake(size_t num_bytes) { m_alog.write(log::alevel::devel,"connection read"); transport_con_type::async_read_at_least( @@ -583,7 +576,7 @@ void connection::read(size_t num_bytes) { m_buf, config::connection_read_buffer_size, lib::bind( - &type::handle_handshake_read, + &type::handle_read_handshake, type::shared_from_this(), lib::placeholders::_1, lib::placeholders::_2 @@ -594,14 +587,14 @@ void connection::read(size_t num_bytes) { // All exit paths for this function need to call send_http_response() or submit // a new read request with this function as the handler. template -void connection::handle_handshake_read(const lib::error_code& ec, +void connection::handle_read_handshake(const lib::error_code& ec, size_t bytes_transferred) { - m_alog.write(log::alevel::devel,"connection handle_handshake_read"); + m_alog.write(log::alevel::devel,"connection handle_read_handshake"); this->atomic_state_check( istate::READ_HTTP_REQUEST, - "handle_handshake_read must be called from READ_HTTP_REQUEST state" + "handle_read_handshake must be called from READ_HTTP_REQUEST state" ); if (ec) { @@ -699,7 +692,7 @@ void connection::handle_handshake_read(const lib::error_code& ec, m_buf, config::connection_read_buffer_size, lib::bind( - &type::handle_handshake_read, + &type::handle_read_handshake, type::shared_from_this(), lib::placeholders::_1, lib::placeholders::_2 @@ -993,62 +986,7 @@ bool connection::process_handshake_request() { } return true; -} - -// TODO: does this function still need to be here? -template -void connection::handle_read(const lib::error_code& ec, - size_t bytes_transferred) -{ - if (ec) { - m_elog.write(log::elevel::rerror,"error in handle_read"+ec.message()); - return; - } - - // TODO: assert bytes_transferred < m_buf size. - - m_alog.write(log::alevel::devel,"connection handle_read"); - - std::string foo(m_buf,bytes_transferred); - - // process bytes - - if (foo == "close") { - this->terminate(); - return; - } - - //m_handler->on_message(type::shared_from_this(),foo); - - this->read(); -} - - -template -void connection::write(std::string msg) { - m_alog.write(log::alevel::devel,"connection write"); - - transport_con_type::async_write( - msg.data(), - msg.size(), - lib::bind( - &type::handle_write, - type::shared_from_this(), - lib::placeholders::_1 - ) - ); -} - -template -void connection::handle_write(const lib::error_code& ec) { - if (ec) { - m_elog.write(log::elevel::rerror, - "error in handle_write: "+ec.message()); - return; - } - - m_alog.write(log::alevel::devel,"connection handle_write"); -} +} template void connection::send_http_response() {