Libtorrent Session_Status not updating

十年热恋 提交于 2020-01-07 01:22:34

问题


Im trying to get Session_Status updated but for whatever reason the values of the structure never update, session is started like so:

 using namespace libtorrent;
 session* Session;
 session_status* Session_Status;
 session_settings* Session_Settings;

 bool Start_Client_Sess ( )
 {
     using namespace libtorrent;
     Session = new session;
     Session_Status = new session_status;
     Session_Settings = new session_settings;
     Session->settings ( );
     Session->set_settings ( *Session_Settings );

     Session->add_extension ( create_ut_pex_plugin );
     Session->add_extension ( create_ut_metadata_plugin );
     Session->add_extension ( create_lt_trackers_plugin );
     Session->add_extension ( create_smart_ban_plugin );

     Session->start_upnp ( );
     Session->start_natpmp ( );
     Session->start_dht ( );
     Session->start_lsd ( );    

     error_code e;
     Session->listen_on ( std::make_pair ( 6881 , 6889 ) , e );

     if ( e )
     {
         return false;
     }
     return true;
 }

then on a Windows 1 second timer I'm doing this:

 void RunTimer ( )
 {
     using namespace libtorrent;
     Session->status ( );
     if ( Session->is_listening ( ) )
     {
         if ( Session_Status->has_incoming_connections )
         {
             INT x = 2;
             std::cout << x << "\n";
         }
         else
         {
             INT x = 1;
             std::cout << x << "\n";
         }
     }
     else
     {
         INT x = 0;
         std::cout << x << "\n";
     }
 }

but no matter what the session is always listening even if the firewall is blocking Libtorrent and there is always connections even if the internet is off.


回答1:


I believe you meant to assign the session status to your Session_Status object:

*Session_Status = Session->status();

I would suggest you don't heap allocate the session_status nor session_settings objects.



来源:https://stackoverflow.com/questions/32298517/libtorrent-session-status-not-updating

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!