2018-12-28 21:46:01 +08:00
|
|
|
#pragma once
|
|
|
|
#include "fiber_cpp_define.hpp"
|
2019-01-14 14:34:14 +08:00
|
|
|
#include <string>
|
2018-12-28 21:46:01 +08:00
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
2019-01-14 14:34:14 +08:00
|
|
|
class keeper_waiter;
|
2018-12-28 21:46:01 +08:00
|
|
|
class socket_stream;
|
2019-01-14 14:34:14 +08:00
|
|
|
class thread_mutex;
|
2018-12-28 21:46:01 +08:00
|
|
|
|
|
|
|
class tcp_keeper : public thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tcp_keeper(void);
|
|
|
|
~tcp_keeper(void);
|
|
|
|
|
2018-12-29 15:42:03 +08:00
|
|
|
tcp_keeper& set_conn_timeout(int n);
|
|
|
|
tcp_keeper& set_rw_timeout(int n);
|
|
|
|
tcp_keeper& set_conn_max(int n);
|
|
|
|
tcp_keeper& set_conn_ttl(int ttl);
|
|
|
|
tcp_keeper& set_pool_ttl(int ttl);
|
|
|
|
|
2019-01-14 14:34:14 +08:00
|
|
|
tcp_keeper& set_rtt_min(double rtt);
|
|
|
|
|
|
|
|
socket_stream* peek(const char* addr, bool* hit = NULL);
|
2018-12-28 21:46:01 +08:00
|
|
|
|
|
|
|
void stop(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// @override
|
|
|
|
void* run(void);
|
|
|
|
|
|
|
|
private:
|
2019-01-14 14:34:14 +08:00
|
|
|
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);
|
2018-12-28 21:46:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|