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

102 lines
2.5 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
/**
* 线
* ping rtt 10ms rtt
*
*/
class tcp_keeper : public thread
{
public:
tcp_keeper(void);
~tcp_keeper(void);
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
/**
* IO
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rw_timeout(int n);
2019-01-15 11:57:19 +08:00
/**
*
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_min(int n);
/**
*
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_max(int n);
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
/**
*
* 便
* @param ttl {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_pool_ttl(int ttl);
2019-01-15 11:57:19 +08:00
/**
* rtt
*
* @param rtt {double}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rtt_min(double rtt);
2019-01-15 11:57:19 +08:00
/**
* tcp_keeper
* @param addr {const char*} ip:port
* @param hit {bool*}
* @return {socket_stream*} NULL
*/
socket_stream* peek(const char* addr, bool* hit = NULL);
2019-01-15 11:57:19 +08:00
/**
* tcp_keeper 线
*/
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