Repository navigation
Expand file tree
/
Copy pathcross.cpp
More file actions
168 lines (149 loc) · 3.64 KB
/
Copy pathcross.cpp
File metadata and controls
168 lines (149 loc) · 3.64 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
*============================================================
* @file cross.cpp
* @brief
*
* compiler gcc4.1.2
* platform Linux
*
* copyright: TaoMee, Inc. ShangHai CN. All rights reserved.
*
*============================================================
*/
extern "C" {
#include <libtaomee/list.h>
#include <libtaomee/log.h>
#include <libtaomee/timer.h>
#include <async_serv/dll.h>
#include <async_serv/net_if.h>
#include <libtaomee/conf_parser/config.h>
}
#include "dbproxy.hpp"
#include "dispatcher.hpp"
#include "proto.hpp"
#include "utils.hpp"
#include "cross_inc.hpp"
static IJobDispatcher* g_static_dispatcher = NULL;
static int online_timeout_process(void* owner, void* data)
{
if (g_static_dispatcher){
return g_static_dispatcher->Dispatch(CROSS_COMMID_ONLINE_TIMEOUT, owner, data);
}
return -1;
}
static int online_pk_tryagain(void* owner, void* data)
{
if (g_static_dispatcher){
return g_static_dispatcher->Dispatch(CROSS_COMMID_ONLINE_PK_TRYAGAIN, owner, data);
}
return -1;
}
int init_all_timer_type(int rstart)
{
REGISTER_TIMER_TYPE(n_make_online_dead, online_timeout_process, rstart);
REGISTER_TIMER_TYPE(n_try_match_again, online_pk_tryagain, rstart);
return 0;
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" int init_service(int isparent)
{
if (!isparent) {
DEBUG_LOG("CROSS SERVER START");
setup_timer();
init_all_timer_type(0);
g_static_dispatcher = CreateJobDispatcher();
if (g_static_dispatcher == NULL){
ERROR_LOG("CROSS SERVER START FAILED, CREATE DISPATCHER FAILED, MEMORY NOT ENOUTH");
return -1;
}
}
return 0;
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" int fini_service(int isparent)
{
if (!isparent) {
DEBUG_LOG("fini service");
if (g_static_dispatcher){
g_static_dispatcher->Release();
delete g_static_dispatcher;
g_static_dispatcher = NULL;
}
destroy_timer();
}
return 0;
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" void proc_events()
{
handle_timer();
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" int get_pkg_len(int fd, const void* avail_data, int avail_len, int isparent)
{
if (avail_len < 4) {
return 0;
}
const mole2cross_proto_t* pkg = reinterpret_cast<const mole2cross_proto_t*>(avail_data);
if ((pkg->len > pkg_size) || (pkg->len < sizeof(mole2cross_proto_t))) {
ERROR_LOG("invalid len=%u from fd=%d", pkg->len, fd);
return -1;
}
return pkg->len;
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" int proc_pkg_from_client(void* data, int len, fdsession_t* fdsess)
{
if (g_static_dispatcher){
return dispatch(g_static_dispatcher, data, fdsess);
}else{
ERROR_LOG("DISPATCHER IS NULL");
return -1;
}
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" void proc_pkg_from_serv(int fd, void* data, int len)
{
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" void on_client_conn_closed(int fd)
{
if (g_static_dispatcher){
DEBUG_LOG("client conn closed");
void* param = NULL;
CONVERT_PTR_TO_PTR(fd, param);
g_static_dispatcher->Dispatch(CROSS_COMMID_CLEAN_ONLINE_INFO, param, NULL);
}
}
/**
* @brief AsyncServer框架要求实现的接口之一。
*
*/
extern "C" void on_fd_closed(int fd)
{
if (fd == proxysvr_fd) {
DEBUG_LOG("DB PROXY CONNECTION CLOSED\t[fd=%d]", proxysvr_fd);
proxysvr_fd = -1;
}
}