UniSet  2.2.1
TCPCheck.h
00001 #ifndef _TCPCheck_H_
00002 #define _TCPCheck_H_
00003 // -----------------------------------------------------------------------------
00004 #include <atomic>
00005 #include <cc++/socket.h>
00006 #include "ThreadCreator.h"
00007 // -----------------------------------------------------------------------------
00013 class TCPCheck
00014 {
00015     public:
00016         TCPCheck();
00017         ~TCPCheck();
00018 
00028         bool check( const std::string& _ip, int _port, timeout_t tout, timeout_t sleep_msec = 50 );
00029 
00031         bool check( const std::string& iaddr, timeout_t tout, timeout_t sleep_msec = 50);
00032 
00033 
00038         bool ping( const std::string& _ip, timeout_t tout = 1000, timeout_t sleep_msec = 200, const std::string& ping_argc = "-c 1 -w 0.1 -q -n" );
00039 
00040     protected:
00041 
00042         void check_thread();
00043         void ping_thread();
00044 
00045         void setResult( bool s )
00046         {
00047             result = s;
00048         }
00049 
00050         std::atomic_bool result = {false};
00051         std::string ip = {""};
00052         int port = {0};
00053         int tout_msec;
00054 
00055         std::string ping_args = {"-c 1 -w 0.1 -q -n"};
00056 };
00057 // -----------------------------------------------------------------------------
00058 #endif // _TCPCheck_H_
00059 // -----------------------------------------------------------------------------