acl/lib_acl_cpp/include/acl_cpp/connpool/check_client.hpp

93 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2015-04-04 15:25:29 +08:00
#include <map>
#include <vector>
#if !defined(_WIN32) && !defined(_WIN64)
2015-05-21 21:49:35 +08:00
#include <sys/time.h>
#endif
2017-06-02 14:47:24 +08:00
#include "../stream/aio_socket_stream.hpp"
#include "../stdlib/string.hpp"
2015-04-04 15:25:29 +08:00
namespace acl
{
class check_timer;
class aio_socket_stream;
/**
*
2015-04-04 15:25:29 +08:00
*/
class ACL_CPP_API check_client : public aio_open_callback
{
public:
check_client(check_timer& timer, const char* addr,
aio_socket_stream& conn, struct timeval& begin);
/**
* IO
2015-04-04 15:25:29 +08:00
* @return {aio_socket_stream&}
*/
aio_socket_stream& get_conn() const
{
return conn_;
}
/**
*
2015-04-04 15:25:29 +08:00
* @return {const char*}
*/
const char* get_addr() const
{
return addr_.c_str();
}
/**
*
2015-04-04 15:25:29 +08:00
* @param yesno {bool}
*/
void set_alive(bool yesno);
/**
* IO
2015-04-04 15:25:29 +08:00
*/
void close();
public:
// 以下的函数仅供内部使用
2015-04-04 15:25:29 +08:00
/**
*
2015-04-04 15:25:29 +08:00
* @return {bool}
*/
bool blocked() const
{
return blocked_;
}
/**
*
* close
* @param on {bool}
2015-04-04 15:25:29 +08:00
*/
void set_blocked(bool on);
private:
// 基类虚函数
2015-04-04 15:25:29 +08:00
bool open_callback();
void close_callback();
bool timeout_callback();
private:
~check_client() {}
private:
bool blocked_;
bool aliving_;
bool timedout_;
2015-04-04 15:25:29 +08:00
struct timeval begin_;
check_timer& timer_;
aio_socket_stream& conn_;
string addr_;
};
} // namespace acl