void IksConnection::handle_error( const bs::error_code& ec ) { if ( ec == bae::operation_aborted ) return; sz_log(5, "IksConnection(%p):handle_error, error: %s, state: %d", this, ec.message().c_str(), int(state)); switch (state) { case CONNECTED: break; case CONNECTING: schedule_reconnect(); return; case WAITING: return; } std::string empty; for ( auto& i : commands ) i.second( ec , "" , empty ); commands.clear(); connection_error_sig(ec); bs::error_code _ec; keepalive_timer.cancel(_ec); schedule_reconnect(); }
void IksConnection::handle_error( const boost::system::error_code& ec ) { std::string empty; for ( auto& i : commands ) i.second( ec , "" , empty ); commands.clear(); connection_error_sig(ec); }
void IksConnection::schedule_keepalive() { sz_log(10, "IksConnection(%p): schedule_keepalive", this); auto self = shared_from_this(); keepalive_timer.expires_from_now( boost::posix_time::seconds( 5 ) ); keepalive_timer.async_wait([self] ( const bs::error_code& ec ) { if ( ec == bae::operation_aborted ) return; self->send_command("i_will_not_buy_this_record_it_is_scratched", "" , [self] ( const bs::error_code &ec , const std::string& status , std::string& data ) { if ( !ec && self->state == CONNECTED ) self->schedule_keepalive(); bs::error_code _ec; self->keepalive_timeout_timer.cancel(_ec); return IksCmdStatus::cmd_done; }); self->keepalive_timeout_timer.expires_from_now( boost::posix_time::seconds( 20 ) ); self->keepalive_timeout_timer.async_wait([self] ( const bs::error_code& ec ) { if ( ec == bae::operation_aborted ) return; sz_log(5, "IksConnection(%p): keepalive timeout timer kicked in, state:%d" , self.get(), int(self->state)); switch (self->state) { case CONNECTED: break; default: return; } auto _ec = make_error_code( bs::errc::stream_timeout ); std::string empty; for ( auto& i : self->commands ) i.second( _ec , "" , empty ); self->commands.clear(); self->connection_error_sig( _ec ); self->schedule_reconnect(); }); }); }
void location_connection::connect_to_location() { auto self = shared_from_this(); m_connection->send_command("connect" , m_location, [self] ( const bs::error_code& ec, const std::string& status, std::string& data ) { sz_log( 5 , "location_connection(%p)::connect_to_location error: %s" , self.get() , ec.message().c_str() ); if ( ec ) { self->connection_error_sig( ec ); return IksCmdStatus::cmd_done; } if ( status != "k" ) { sz_log( 5 , "location_connection(%p)::connect_to_location not ok from server" " error: %s , data: %s" , self.get(), status.c_str() , data.c_str() ); self->connection_error_sig( make_iks_error_code( data ) ); return IksCmdStatus::cmd_done; } sz_log( 10 , "location_connection(%p)::connected " , self.get() ); self->m_connected = true; self->add_defined_params(); self->send_cached(); self->connected_sig(); return IksCmdStatus::cmd_done; }); }
void IksConnection::handle_read_line( ba::streambuf& buf ) { std::istream is( &buf ); std::string tag; std::string data; IksCmdId id; std::getline(is, tag, ' '); is >> id; is.ignore(1); std::getline(is, data); if ( !is ) { sz_log(1, "IksConnection(%p):handle_read_line invalid response from server, tag: %s, data: %s" , this, tag.c_str(), data.c_str()); auto ec = make_error_code( iks_client_error::invalid_server_response ); std::string empty; for ( auto& i : commands ) i.second( ec , "" , empty ); commands.clear(); connection_error_sig( ec ); schedule_reconnect(); return; } sz_log(10, "IksConnection(%p): received message: tag: %s, id:%d data: %s" , this, tag.c_str(), int(id), data.c_str() ); auto i = commands.find(id); if ( i != commands.end() ) { if ( i->second( make_error_code( bs::errc::success ), tag , data ) == cmd_done) commands.erase(i); } else cmd_sig( tag, id, data ); }
void location_connection::connect_to_location() { auto self = shared_from_this(); m_connection->send_command("connect" , m_location, [self] ( const bs::error_code& ec, const std::string& status, std::string& data ) { if ( ec ) return IksCmdStatus::cmd_done; if ( status != "k" ) { self->connection_error_sig( make_iks_error_code( data ) ); return IksCmdStatus::cmd_done; } ///XXX: 1. send defined params ///XXX: 2. send cached self->connected_sig(); self->m_connected = true; return IksCmdStatus::cmd_done; }); }
void connection_mgr::on_error(const boost::system::error_code& ec) { if (ec != ba::error::operation_aborted) connection_error_sig(ec); }
void location_connection::on_connection_error(const boost::system::error_code& ec) { connection_error_sig(ec); }