C++ global class to prevent multiple socket creations -


i have application transfers log files client machine server. time new log file appears, transferred via scp.

currently after transfer complete, socket , libssh2 handle destroyed. creates lot of unnecessary cpu cycles on both ends considering how log files created. i'm leaning towards applying keep-alive logic socket mitigate this.

so question is, best practice make global class maintains sockets connectivity , runs asynchronous timer check recent transfers. it's been awhile since i've written in c++ have in mind:

scpsendfile.h

class sendfile { public:     sendfile();     ~sendfile();     bool scp_authenticate();     bool scp_transferfile(string file);     void scp_closesession();     void asynckeepalive();  private:     unsigned int lasttransfer; #ifdef win32     socket socket; #else     int socket; #endif     int ssh;     libssh2_session *session = null;  };  extern class scpsendfile scpsendfile; 

would there better approach mentioned above? global classes okay , there better logic apply keep-alive creating timer verifies last upload?

thanks