fixes to http/tcp server
This commit is contained in:
parent
8e1b99f40c
commit
c885981c65
3 changed files with 4 additions and 11 deletions
|
|
@ -93,19 +93,16 @@ 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
FC_START_SHARED_IMPL(fc::http::connection)
|
FC_START_SHARED_IMPL(fc::http::connection)
|
||||||
fc::tcp_socket sock;
|
fc::tcp_socket sock;
|
||||||
fc::ip::endpoint ep;
|
fc::ip::endpoint ep;
|
||||||
|
impl() {
|
||||||
|
}
|
||||||
|
|
||||||
int read_until( char* buffer, char* end, char c = '\n' ) {
|
int read_until( char* buffer, char* end, char c = '\n' ) {
|
||||||
char* p = buffer;
|
char* p = buffer;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace fc {
|
||||||
|
|
||||||
class tcp_socket::impl {
|
class tcp_socket::impl {
|
||||||
public:
|
public:
|
||||||
impl():_sock( fc::asio::default_io_service() ){ slog( "creating socket %p", &_sock); }
|
impl():_sock( fc::asio::default_io_service() ){ }
|
||||||
~impl(){
|
~impl(){
|
||||||
if( _sock.is_open() ) _sock.close();
|
if( _sock.is_open() ) _sock.close();
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,6 @@ namespace fc {
|
||||||
public:
|
public:
|
||||||
impl(uint16_t port):
|
impl(uint16_t port):
|
||||||
_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 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();
|
||||||
|
|
@ -108,23 +107,18 @@ namespace fc {
|
||||||
|
|
||||||
|
|
||||||
bool tcp_server::accept( tcp_socket& s ) {
|
bool tcp_server::accept( tcp_socket& s ) {
|
||||||
|
if( !my ) return false;
|
||||||
fc::promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("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