From 949095ab0050ad3fcaeec1326c204557bdeb5788 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 12 Dec 2012 15:56:48 -0500 Subject: [PATCH] updates... --- CMakeLists.txt | 1 + include/fc/http/connection.hpp | 5 ++--- include/fc/shared_impl.cpp | 4 ++++ include/fc/shared_impl.hpp | 2 ++ include/fc/shared_ptr.hpp | 4 ++++ include/fc/value_io.hpp | 3 +++ src/http_connection.cpp | 7 ++----- src/tcp_socket.cpp | 15 ++++++++++++--- 8 files changed, 30 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad7a161..c55e2bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set( sources src/ssh.cpp src/process.cpp src/http_connection.cpp + src/http_server.cpp src/json_rpc_connection.cpp src/json_rpc_stream_connection.cpp src/json_rpc_tcp_connection.cpp diff --git a/include/fc/http/connection.hpp b/include/fc/http/connection.hpp index e975eda..557f57a 100644 --- a/include/fc/http/connection.hpp +++ b/include/fc/http/connection.hpp @@ -47,10 +47,9 @@ namespace fc { http::reply request( const fc::string& method, const fc::string& url, const fc::string& body ); // used for servers - fc::tcp_socket& get_socket(); + fc::tcp_socket& get_socket()const; - http::request read_request(); - void send_reply( const http::reply& ); + http::request read_request()const; FC_REFERENCE_TYPE(connection) }; diff --git a/include/fc/shared_impl.cpp b/include/fc/shared_impl.cpp index da73f9a..51948d6 100644 --- a/include/fc/shared_impl.cpp +++ b/include/fc/shared_impl.cpp @@ -14,6 +14,8 @@ shared_impl::shared_impl( U&& u ):_impl(fc::forward(u)){} template shared_impl::shared_impl( const shared_impl& u ):_impl(u._impl){} +template +shared_impl::shared_impl( shared_impl& u ):_impl(u._impl){} template shared_impl::shared_impl( shared_impl&& u ):_impl(fc::move(u._impl)){} @@ -55,6 +57,8 @@ TYPE::TYPE( TYPE&& c )\ :my(fc::move(c.my)){}\ TYPE::TYPE( const TYPE& c )\ :my(c.my){}\ +TYPE::TYPE( TYPE& c )\ +:my(c.my){}\ TYPE::TYPE() \ :my( new fc::shared_impl::impl( ) ){}\ TYPE::~TYPE(){}\ diff --git a/include/fc/shared_impl.hpp b/include/fc/shared_impl.hpp index bb6e7c8..3e3a73b 100644 --- a/include/fc/shared_impl.hpp +++ b/include/fc/shared_impl.hpp @@ -113,6 +113,7 @@ namespace fc { shared_impl( U&& u ); shared_impl( const shared_impl& u ); + shared_impl( shared_impl& u ); shared_impl( shared_impl&& u ); shared_impl& operator=( shared_impl&& u ); shared_impl& operator=( const shared_impl& u ); @@ -131,6 +132,7 @@ namespace fc { TYPE( TYPE* ); \ TYPE( TYPE&& ); \ TYPE( const TYPE& ); \ + TYPE( TYPE& ); \ template \ TYPE( A1&& ); \ template \ diff --git a/include/fc/shared_ptr.hpp b/include/fc/shared_ptr.hpp index 859467a..856aa7c 100644 --- a/include/fc/shared_ptr.hpp +++ b/include/fc/shared_ptr.hpp @@ -40,6 +40,10 @@ namespace fc { _ptr = p._ptr; if( _ptr ) _ptr->retain(); } + shared_ptr( shared_ptr& p ) { + _ptr = p._ptr; + if( _ptr ) _ptr->retain(); + } shared_ptr( shared_ptr&& p ) { _ptr = p._ptr; p._ptr = nullptr; diff --git a/include/fc/value_io.hpp b/include/fc/value_io.hpp index de9c678..fa23dba 100644 --- a/include/fc/value_io.hpp +++ b/include/fc/value_io.hpp @@ -93,16 +93,19 @@ namespace fc { */ template inline void pack_helper( const T& v, const char* name )const { + slog( "%s", name ); fc::pack( obj[name], v ); } template inline void pack_helper( const fc::optional& v, const char* name )const { + slog( "%s", name ); if( !!v ) { fc::pack( obj[name], *v ); } } template inline void operator()( const char* name )const { + slog( "%s", name ); pack_helper( c.*p, name ); } diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 621b1ad..0a28c5d 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -114,16 +114,13 @@ http::reply connection::request( const fc::string& method, } // used for servers -fc::tcp_socket& connection::get_socket() { +fc::tcp_socket& connection::get_socket()const { return my->sock; } -http::request connection::read_request() { +http::request connection::read_request()const { http::request r; return r; } -void connection::send_reply( const http::reply& ) { - -} } } // fc::http diff --git a/src/tcp_socket.cpp b/src/tcp_socket.cpp index 4df563c..ddfa3d2 100644 --- a/src/tcp_socket.cpp +++ b/src/tcp_socket.cpp @@ -9,7 +9,7 @@ namespace fc { class tcp_socket::impl { public: - impl():_sock( fc::asio::default_io_service() ){ } + impl():_sock( fc::asio::default_io_service() ){ slog( "creating socket %p", &_sock); } ~impl(){ if( _sock.is_open() ) _sock.close(); } @@ -85,7 +85,10 @@ namespace fc { class tcp_server::impl { public: - impl(uint16_t port):_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){} + impl(uint16_t port): + _accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){ + slog( "... tcp server port %d", port ); + } ~impl(){ _accept.close(); } @@ -105,17 +108,23 @@ namespace fc { bool tcp_server::accept( tcp_socket& s ) { - fc::promise::ptr p( new promise("mace::cmt::asio::tcp::accept") ); + fc::promise::ptr p( new promise("tcp::accept") ); + slog( "accept socket %p", &s.my->_sock ); my->_accept.async_accept( s.my->_sock, [=]( const boost::system::error_code& e ) { p->set_value(e); } ); + slog( "."); auto ec = p->wait(); + slog( "."); if( !ec ) s.my->_sock.non_blocking(true); + slog( "."); if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) ); + slog( "."); return true; } void tcp_server::listen( uint16_t port ) { if( my ) delete my; + slog( "Listen %d", port ); my = new impl(port); }