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

105 lines
2.7 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;
/**
* 线
* ping rtt 10ms rtt
*
*/
class tcp_keeper : public thread
{
public:
tcp_keeper(void);
~tcp_keeper(void);
/**
*
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_timeout(int n);
/**
* IO
* @param n {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rw_timeout(int n);
/**
*
* @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);
/**
*
* @param ttl {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_conn_ttl(int ttl);
/**
*
* 便
* @param ttl {int}
* @return {tcp_keeper&}
*/
tcp_keeper& set_pool_ttl(int ttl);
/**
* rtt
*
* @param rtt {double}
* @return {tcp_keeper&}
*/
tcp_keeper& set_rtt_min(double rtt);
/**
* tcp_keeper
* @param addr {const char*} ip:port
* @param hit {bool*}
* @param sync {bool}
*
* @return {socket_stream*} NULL
*/
socket_stream* peek(const char* addr, bool* hit = NULL,
bool sync = false);
/**
* 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