|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // ----------------------------------------------------------------------------- 00017 #ifndef _TCPCheck_H_ 00018 #define _TCPCheck_H_ 00019 // ----------------------------------------------------------------------------- 00020 #include <atomic> 00021 #include "ThreadCreator.h" 00022 #include "PassiveTimer.h" // for timeout_t 00023 // ----------------------------------------------------------------------------- 00024 namespace uniset 00025 { 00031 class TCPCheck 00032 { 00033 public: 00034 TCPCheck() noexcept; 00035 ~TCPCheck() noexcept; 00036 00045 bool check( const std::string& _ip, int _port, timeout_t tout ); 00046 00048 bool check( const std::string& iaddr, timeout_t tout ); 00049 00050 00055 bool ping(const std::string& _ip, timeout_t tout = 1000, const std::string& ping_argc = "-c 1 -w 0.1 -q -n" ); 00056 00057 protected: 00058 00059 void check_thread(); 00060 void ping_thread(); 00061 00062 std::condition_variable thr_event; 00063 std::mutex thr_mutex; 00064 std::atomic_bool thr_finished = { false }; 00065 00066 std::atomic_bool result = {false}; 00067 std::string ip = {""}; 00068 int port = {0}; 00069 int tout_msec; 00070 00071 std::string ping_args = {"-c 1 -w 0.1 -q -n"}; 00072 }; 00073 // ------------------------------------------------------------------------- 00074 } // end of uniset namespace 00075 // ----------------------------------------------------------------------------- 00076 #endif // _TCPCheck_H_ 00077 // -----------------------------------------------------------------------------
1.7.6.1