UniSet  2.0.0
TCPCheck.h
00001 #ifndef _TCPCheck_H_
00002 #define _TCPCheck_H_
00003 // -----------------------------------------------------------------------------
00004 #include <cc++/socket.h>
00005 #include "Mutex.h"
00006 #include "ThreadCreator.h"
00007 // -----------------------------------------------------------------------------
00014 class TCPCheck
00015 {
00016     public:
00017         TCPCheck();
00018         ~TCPCheck();
00019     
00020         bool check( const std::string& _ip, int _port, timeout_t tout, timeout_t sleep_msec );
00021         
00023         bool check( const std::string& iaddr, timeout_t tout, timeout_t sleep_msec );
00024 
00025     protected:
00026         void check_thread();
00027         inline void setResult( bool res )
00028         {
00029             UniSetTypes::uniset_rwmutex_wrlock l(m);
00030             result = res;
00031         }
00032 
00033         inline bool getResult()
00034         {
00035             bool res = false;
00036             {
00037                 UniSetTypes::uniset_rwmutex_rlock l(m);
00038                 res = result;
00039             }
00040             return res;
00041         }
00042 
00043         bool result;
00044         std::string iaddr;
00045         int tout_msec;
00046         UniSetTypes::uniset_rwmutex m;
00047 };
00048 // -----------------------------------------------------------------------------
00049 #endif // _TCPCheck_H_
00050 // -----------------------------------------------------------------------------