2019-07-27 22:44:32 +08:00
|
|
|
|
#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>
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 异步连接回调函数处理类
|
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);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 获得输入的非阻塞 IO 句柄
|
2015-04-04 15:25:29 +08:00
|
|
|
|
* @return {aio_socket_stream&}
|
|
|
|
|
*/
|
|
|
|
|
aio_socket_stream& get_conn() const
|
|
|
|
|
{
|
|
|
|
|
return conn_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 获得传入的服务端地址
|
2015-04-04 15:25:29 +08:00
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
|
|
|
|
const char* get_addr() const
|
|
|
|
|
{
|
|
|
|
|
return addr_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 设置连接是否是存活的
|
2015-04-04 15:25:29 +08:00
|
|
|
|
* @param yesno {bool}
|
|
|
|
|
*/
|
|
|
|
|
void set_alive(bool yesno);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 关闭非阻塞 IO 句柄
|
2015-04-04 15:25:29 +08:00
|
|
|
|
*/
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
|
|
public:
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 以下的函数仅供内部使用
|
2015-04-04 15:25:29 +08:00
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 当前检测对象是否处于阻塞模式下
|
2015-04-04 15:25:29 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool blocked() const
|
|
|
|
|
{
|
|
|
|
|
return blocked_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 在阻塞检测方式下,调用此函数用来设置检测对象是否处于阻塞状态,
|
|
|
|
|
* 处于阻塞状态时该检测对象是禁止通过调用方法 close 来关闭的
|
|
|
|
|
* @param on {bool} 设置检测对象是否处于阻塞状态,缺省为处于阻塞状态
|
2015-04-04 15:25:29 +08:00
|
|
|
|
*/
|
|
|
|
|
void set_blocked(bool on);
|
|
|
|
|
|
|
|
|
|
private:
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数
|
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_;
|
2018-06-05 14:42:35 +08:00
|
|
|
|
bool timedout_;
|
2015-04-04 15:25:29 +08:00
|
|
|
|
struct timeval begin_;
|
|
|
|
|
check_timer& timer_;
|
|
|
|
|
aio_socket_stream& conn_;
|
|
|
|
|
string addr_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|