forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_repl_client_thread.h
64 lines (56 loc) · 2.09 KB
/
pika_repl_client_thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_REPL_CLIENT_THREAD_H_
#define PIKA_REPL_CLIENT_THREAD_H_
#include <string>
#include <memory>
#include "include/pika_repl_client_conn.h"
#include "pink/include/pink_conn.h"
#include "pink/include/client_thread.h"
class PikaReplClientThread : public pink::ClientThread {
public:
PikaReplClientThread(int cron_interval, int keepalive_timeout);
virtual ~PikaReplClientThread() = default;
int Start();
private:
class ReplClientConnFactory : public pink::ConnFactory {
public:
virtual std::shared_ptr<pink::PinkConn> NewPinkConn(
int connfd,
const std::string &ip_port,
pink::Thread *thread,
void* worker_specific_data,
pink::PinkEpoll* pink_epoll) const override {
return std::static_pointer_cast<pink::PinkConn>
(std::make_shared<PikaReplClientConn>(connfd, ip_port, thread, worker_specific_data, pink_epoll));
}
};
class ReplClientHandle : public pink::ClientHandle {
public:
void CronHandle() const override {
}
void FdTimeoutHandle(int fd, const std::string& ip_port) const override;
void FdClosedHandle(int fd, const std::string& ip_port) const override;
bool AccessHandle(std::string& ip) const override {
// ban 127.0.0.1 if you want to test this routine
// if (ip.find("127.0.0.2") != std::string::npos) {
// std::cout << "AccessHandle " << ip << std::endl;
// return false;
// }
return true;
}
int CreateWorkerSpecificData(void** data) const override {
return 0;
}
int DeleteWorkerSpecificData(void* data) const override {
return 0;
}
void DestConnectFailedHandle(std::string ip_port, std::string reason) const override {
}
};
ReplClientConnFactory conn_factory_;
ReplClientHandle handle_;
};
#endif // PIKA_REPL_CLIENT_THREAD_H_