updates...
This commit is contained in:
parent
44ea53407b
commit
949095ab00
8 changed files with 30 additions and 11 deletions
|
|
@ -50,6 +50,7 @@ set( sources
|
||||||
src/ssh.cpp
|
src/ssh.cpp
|
||||||
src/process.cpp
|
src/process.cpp
|
||||||
src/http_connection.cpp
|
src/http_connection.cpp
|
||||||
|
src/http_server.cpp
|
||||||
src/json_rpc_connection.cpp
|
src/json_rpc_connection.cpp
|
||||||
src/json_rpc_stream_connection.cpp
|
src/json_rpc_stream_connection.cpp
|
||||||
src/json_rpc_tcp_connection.cpp
|
src/json_rpc_tcp_connection.cpp
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,9 @@ namespace fc {
|
||||||
http::reply request( const fc::string& method, const fc::string& url, const fc::string& body );
|
http::reply request( const fc::string& method, const fc::string& url, const fc::string& body );
|
||||||
|
|
||||||
// used for servers
|
// used for servers
|
||||||
fc::tcp_socket& get_socket();
|
fc::tcp_socket& get_socket()const;
|
||||||
|
|
||||||
http::request read_request();
|
http::request read_request()const;
|
||||||
void send_reply( const http::reply& );
|
|
||||||
|
|
||||||
FC_REFERENCE_TYPE(connection)
|
FC_REFERENCE_TYPE(connection)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ shared_impl<T>::shared_impl( U&& u ):_impl(fc::forward<U>(u)){}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
shared_impl<T>::shared_impl( const shared_impl<T>& u ):_impl(u._impl){}
|
shared_impl<T>::shared_impl( const shared_impl<T>& u ):_impl(u._impl){}
|
||||||
|
template<typename T>
|
||||||
|
shared_impl<T>::shared_impl( shared_impl<T>& u ):_impl(u._impl){}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
shared_impl<T>::shared_impl( shared_impl<T>&& u ):_impl(fc::move(u._impl)){}
|
shared_impl<T>::shared_impl( shared_impl<T>&& u ):_impl(fc::move(u._impl)){}
|
||||||
|
|
@ -55,6 +57,8 @@ TYPE::TYPE( TYPE&& c )\
|
||||||
:my(fc::move(c.my)){}\
|
:my(fc::move(c.my)){}\
|
||||||
TYPE::TYPE( const TYPE& c )\
|
TYPE::TYPE( const TYPE& c )\
|
||||||
:my(c.my){}\
|
:my(c.my){}\
|
||||||
|
TYPE::TYPE( TYPE& c )\
|
||||||
|
:my(c.my){}\
|
||||||
TYPE::TYPE() \
|
TYPE::TYPE() \
|
||||||
:my( new fc::shared_impl<TYPE>::impl( ) ){}\
|
:my( new fc::shared_impl<TYPE>::impl( ) ){}\
|
||||||
TYPE::~TYPE(){}\
|
TYPE::~TYPE(){}\
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ namespace fc {
|
||||||
shared_impl( U&& u );
|
shared_impl( U&& u );
|
||||||
|
|
||||||
shared_impl( const shared_impl& u );
|
shared_impl( const shared_impl& u );
|
||||||
|
shared_impl( shared_impl& u );
|
||||||
shared_impl( shared_impl&& u );
|
shared_impl( shared_impl&& u );
|
||||||
shared_impl& operator=( shared_impl&& u );
|
shared_impl& operator=( shared_impl&& u );
|
||||||
shared_impl& operator=( const shared_impl& u );
|
shared_impl& operator=( const shared_impl& u );
|
||||||
|
|
@ -131,6 +132,7 @@ namespace fc {
|
||||||
TYPE( TYPE* ); \
|
TYPE( TYPE* ); \
|
||||||
TYPE( TYPE&& ); \
|
TYPE( TYPE&& ); \
|
||||||
TYPE( const TYPE& ); \
|
TYPE( const TYPE& ); \
|
||||||
|
TYPE( TYPE& ); \
|
||||||
template<typename A1> \
|
template<typename A1> \
|
||||||
TYPE( A1&& ); \
|
TYPE( A1&& ); \
|
||||||
template<typename A1,typename A2> \
|
template<typename A1,typename A2> \
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ namespace fc {
|
||||||
_ptr = p._ptr;
|
_ptr = p._ptr;
|
||||||
if( _ptr ) _ptr->retain();
|
if( _ptr ) _ptr->retain();
|
||||||
}
|
}
|
||||||
|
shared_ptr( shared_ptr& p ) {
|
||||||
|
_ptr = p._ptr;
|
||||||
|
if( _ptr ) _ptr->retain();
|
||||||
|
}
|
||||||
shared_ptr( shared_ptr&& p ) {
|
shared_ptr( shared_ptr&& p ) {
|
||||||
_ptr = p._ptr;
|
_ptr = p._ptr;
|
||||||
p._ptr = nullptr;
|
p._ptr = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -93,16 +93,19 @@ namespace fc {
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void pack_helper( const T& v, const char* name )const {
|
inline void pack_helper( const T& v, const char* name )const {
|
||||||
|
slog( "%s", name );
|
||||||
fc::pack( obj[name], v );
|
fc::pack( obj[name], v );
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void pack_helper( const fc::optional<T>& v, const char* name )const {
|
inline void pack_helper( const fc::optional<T>& v, const char* name )const {
|
||||||
|
slog( "%s", name );
|
||||||
if( !!v ) {
|
if( !!v ) {
|
||||||
fc::pack( obj[name], *v );
|
fc::pack( obj[name], *v );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<typename T, typename C, T (C::*p)>
|
template<typename T, typename C, T (C::*p)>
|
||||||
inline void operator()( const char* name )const {
|
inline void operator()( const char* name )const {
|
||||||
|
slog( "%s", name );
|
||||||
pack_helper( c.*p, name );
|
pack_helper( c.*p, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,16 +114,13 @@ http::reply connection::request( const fc::string& method,
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for servers
|
// used for servers
|
||||||
fc::tcp_socket& connection::get_socket() {
|
fc::tcp_socket& connection::get_socket()const {
|
||||||
return my->sock;
|
return my->sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
http::request connection::read_request() {
|
http::request connection::read_request()const {
|
||||||
http::request r;
|
http::request r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
void connection::send_reply( const http::reply& ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} } // fc::http
|
} } // fc::http
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace fc {
|
||||||
|
|
||||||
class tcp_socket::impl {
|
class tcp_socket::impl {
|
||||||
public:
|
public:
|
||||||
impl():_sock( fc::asio::default_io_service() ){ }
|
impl():_sock( fc::asio::default_io_service() ){ slog( "creating socket %p", &_sock); }
|
||||||
~impl(){
|
~impl(){
|
||||||
if( _sock.is_open() ) _sock.close();
|
if( _sock.is_open() ) _sock.close();
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,10 @@ namespace fc {
|
||||||
|
|
||||||
class tcp_server::impl {
|
class tcp_server::impl {
|
||||||
public:
|
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(){
|
~impl(){
|
||||||
_accept.close();
|
_accept.close();
|
||||||
}
|
}
|
||||||
|
|
@ -105,17 +108,23 @@ namespace fc {
|
||||||
|
|
||||||
|
|
||||||
bool tcp_server::accept( tcp_socket& s ) {
|
bool tcp_server::accept( tcp_socket& s ) {
|
||||||
fc::promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("mace::cmt::asio::tcp::accept") );
|
fc::promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("tcp::accept") );
|
||||||
|
slog( "accept socket %p", &s.my->_sock );
|
||||||
my->_accept.async_accept( s.my->_sock, [=]( const boost::system::error_code& e ) {
|
my->_accept.async_accept( s.my->_sock, [=]( const boost::system::error_code& e ) {
|
||||||
p->set_value(e);
|
p->set_value(e);
|
||||||
} );
|
} );
|
||||||
|
slog( ".");
|
||||||
auto ec = p->wait();
|
auto ec = p->wait();
|
||||||
|
slog( ".");
|
||||||
if( !ec ) s.my->_sock.non_blocking(true);
|
if( !ec ) s.my->_sock.non_blocking(true);
|
||||||
|
slog( ".");
|
||||||
if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
|
if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
|
||||||
|
slog( ".");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void tcp_server::listen( uint16_t port ) {
|
void tcp_server::listen( uint16_t port ) {
|
||||||
if( my ) delete my;
|
if( my ) delete my;
|
||||||
|
slog( "Listen %d", port );
|
||||||
my = new impl(port);
|
my = new impl(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue