acl/lib_fiber/cpp/include/fiber/tcp_keeper.hpp

105 lines
3.2 KiB
C++
Raw Normal View History

#pragma once
#include "fiber_cpp_define.hpp"
#include <string>
namespace acl {
class keeper_waiter;
class socket_stream;
class thread_mutex;
2019-01-15 11:57:19 +08:00
/**
*
* <EFBFBD> ping rtt <EFBFBD>10ms rtt
* <EFBFBD>
2019-01-15 11:57:19 +08:00
*/
class tcp_keeper : public thread
{
public:
tcp_keeper(void);
~tcp_keeper(void);
2019-01-15 11:57:19 +08:00
/**
*
2019-01-15 11:57:19 +08:00
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_timeout(int n);
2019-01-15 11:57:19 +08:00
/**
* <EFBFBD> IO <EFBFBD>
2019-01-15 11:57:19 +08:00
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rw_timeout(int n);
2019-01-15 11:57:19 +08:00
/**
*
2019-01-15 11:57:19 +08:00
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_min(int n);
/**
* ц
2019-01-15 11:57:19 +08:00
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_max(int n);
2019-01-15 11:57:19 +08:00
/**
*
2019-01-15 11:57:19 +08:00
* @param ttl {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_ttl(int ttl);
2019-01-15 11:57:19 +08:00
/**
*
* 樿<EFBFBD>
2019-01-15 11:57:19 +08:00
* @param ttl {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_pool_ttl(int ttl);
2019-01-15 11:57:19 +08:00
/**
* rtt
* 洿
2019-01-15 11:57:19 +08:00
* @param rtt {double}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rtt_min(double rtt);
2019-01-15 11:57:19 +08:00
/**
* <EFBFBD> tcp_keeper <EFBFBD>
* @param addr {const char*} ip:port
* @param hit {bool*}
* @param sync {bool} 洿ā<EFBFBD>
* <EFBFBD>
* @return {socket_stream*} NULL
2019-01-15 11:57:19 +08:00
*/
socket_stream* peek(const char* addr, bool* hit = NULL,
bool sync = false);
2019-01-15 11:57:19 +08:00
/**
* tcp_keeper
2019-01-15 11:57:19 +08:00
*/
void stop(void);
protected:
// @override
void* run(void);
private:
double rtt_min_;
keeper_waiter* waiter_;
std::map<std::string, double> addrs_;
thread_mutex* lock_;
bool direct(const char* addr, bool& found);
void remove(const char* addr);
void update(const char* addr, double cost);
};
} // namespace acl