Skip to content

Commit 41cac84

Browse files
committed
fix indent problem with clang-format
1 parent 43dfb12 commit 41cac84

24 files changed

+4923
-5757
lines changed

common.cpp

Lines changed: 725 additions & 839 deletions
Large diffs are not rendered by default.

common.h

Lines changed: 325 additions & 360 deletions
Large diffs are not rendered by default.

connection.cpp

Lines changed: 99 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,147 +7,124 @@
77

88
#include "connection.h"
99

10-
//const int disable_conv_clear=0;//a udp connection in the multiplexer is called conversation in this program,conv for short.
10+
// const int disable_conv_clear=0;//a udp connection in the multiplexer is called conversation in this program,conv for short.
1111

12-
const int disable_conn_clear=0;//a raw connection is called conn.
12+
const int disable_conn_clear = 0; // a raw connection is called conn.
1313

14-
int report_interval=0;
14+
int report_interval = 0;
1515

16-
void server_clear_function(u64_t u64)//used in conv_manager in server mode.for server we have to use one udp fd for one conv(udp connection),
17-
//so we have to close the fd when conv expires
16+
void server_clear_function(u64_t u64) // used in conv_manager in server mode.for server we have to use one udp fd for one conv(udp connection),
17+
// so we have to close the fd when conv expires
1818
{
19-
fd64_t fd64=u64;
20-
assert(fd_manager.exist(fd64));
21-
ev_io &watcher= fd_manager.get_info(fd64).io_watcher;
19+
fd64_t fd64 = u64;
20+
assert(fd_manager.exist(fd64));
21+
ev_io &watcher = fd_manager.get_info(fd64).io_watcher;
2222

23-
address_t &addr=fd_manager.get_info(fd64).addr;//
24-
assert(conn_manager.exist(addr));//
25-
struct ev_loop *loop =conn_manager.find_insert(addr).loop; // overkill ? should we just use ev_default_loop(0)?
23+
address_t &addr = fd_manager.get_info(fd64).addr; //
24+
assert(conn_manager.exist(addr)); //
25+
struct ev_loop *loop = conn_manager.find_insert(addr).loop; // overkill ? should we just use ev_default_loop(0)?
2626

27-
ev_io_stop(loop,&watcher);
28-
29-
fd_manager.fd64_close(fd64);
27+
ev_io_stop(loop, &watcher);
3028

29+
fd_manager.fd64_close(fd64);
3130
}
3231

33-
3432
////////////////////////////////////////////////////////////////////
3533

36-
conn_manager_t::conn_manager_t()
37-
{
38-
mp.reserve(10007);
39-
last_clear_time=0;
34+
conn_manager_t::conn_manager_t() {
35+
mp.reserve(10007);
36+
last_clear_time = 0;
4037
}
41-
int conn_manager_t::exist(address_t addr)
42-
{
43-
44-
if(mp.find(addr)!=mp.end())
45-
{
46-
return 1;
47-
}
48-
return 0;
38+
int conn_manager_t::exist(address_t addr) {
39+
if (mp.find(addr) != mp.end()) {
40+
return 1;
41+
}
42+
return 0;
4943
}
5044

51-
conn_info_t *& conn_manager_t::find_insert_p(address_t addr) //be aware,the adress may change after rehash
45+
conn_info_t *&conn_manager_t::find_insert_p(address_t addr) // be aware,the adress may change after rehash
5246
{
53-
// u64_t u64=0;
54-
//u64=ip;
55-
//u64<<=32u;
56-
//u64|=port;
57-
unordered_map<address_t,conn_info_t*>::iterator it=mp.find(addr);
58-
if(it==mp.end())
59-
{
60-
mp[addr]=new conn_info_t;
61-
//lru.new_key(addr);
62-
}
63-
else
64-
{
65-
//lru.update(addr);
66-
}
67-
return mp[addr];
47+
// u64_t u64=0;
48+
// u64=ip;
49+
// u64<<=32u;
50+
// u64|=port;
51+
unordered_map<address_t, conn_info_t *>::iterator it = mp.find(addr);
52+
if (it == mp.end()) {
53+
mp[addr] = new conn_info_t;
54+
// lru.new_key(addr);
55+
} else {
56+
// lru.update(addr);
57+
}
58+
return mp[addr];
6859
}
69-
conn_info_t & conn_manager_t::find_insert(address_t addr) //be aware,the adress may change after rehash
60+
conn_info_t &conn_manager_t::find_insert(address_t addr) // be aware,the adress may change after rehash
7061
{
71-
//u64_t u64=0;
72-
//u64=ip;
73-
//u64<<=32u;
74-
//u64|=port;
75-
unordered_map<address_t,conn_info_t*>::iterator it=mp.find(addr);
76-
if(it==mp.end())
77-
{
78-
mp[addr]=new conn_info_t;
79-
//lru.new_key(addr);
80-
}
81-
else
82-
{
83-
//lru.update(addr);
84-
}
85-
return *mp[addr];
62+
// u64_t u64=0;
63+
// u64=ip;
64+
// u64<<=32u;
65+
// u64|=port;
66+
unordered_map<address_t, conn_info_t *>::iterator it = mp.find(addr);
67+
if (it == mp.end()) {
68+
mp[addr] = new conn_info_t;
69+
// lru.new_key(addr);
70+
} else {
71+
// lru.update(addr);
72+
}
73+
return *mp[addr];
8674
}
87-
int conn_manager_t::erase(unordered_map<address_t,conn_info_t*>::iterator erase_it)
88-
{
89-
delete(erase_it->second);
90-
mp.erase(erase_it->first);
91-
return 0;
75+
int conn_manager_t::erase(unordered_map<address_t, conn_info_t *>::iterator erase_it) {
76+
delete (erase_it->second);
77+
mp.erase(erase_it->first);
78+
return 0;
9279
}
93-
int conn_manager_t::clear_inactive()
94-
{
95-
if(get_current_time()-last_clear_time>conn_clear_interval)
96-
{
97-
last_clear_time=get_current_time();
98-
return clear_inactive0();
99-
}
100-
return 0;
80+
int conn_manager_t::clear_inactive() {
81+
if (get_current_time() - last_clear_time > conn_clear_interval) {
82+
last_clear_time = get_current_time();
83+
return clear_inactive0();
84+
}
85+
return 0;
10186
}
10287

103-
int conn_manager_t::clear_inactive0()
104-
{
105-
//mylog(log_info,"called\n");
106-
unordered_map<address_t,conn_info_t*>::iterator it;
107-
unordered_map<address_t,conn_info_t*>::iterator old_it;
108-
109-
if(disable_conn_clear) return 0;
110-
111-
//map<uint32_t,uint64_t>::iterator it;
112-
int cnt=0;
113-
it=clear_it;//TODO,write it back
114-
int size=mp.size();
115-
int num_to_clean=size/conn_clear_ratio+conn_clear_min; //clear 1/10 each time,to avoid latency glitch
116-
117-
//mylog(log_trace,"mp.size() %d\n", size);
118-
119-
num_to_clean=min(num_to_clean,(int)mp.size());
120-
u64_t current_time=get_current_time();
121-
122-
//mylog(log_info,"here size=%d\n",(int)mp.size());
123-
for(;;)
124-
{
125-
if(cnt>=num_to_clean) break;
126-
if(mp.begin()==mp.end()) break;
127-
if(it==mp.end())
128-
{
129-
it=mp.begin();
130-
}
131-
132-
if(it->second->conv_manager.s.get_size() >0)
133-
{
134-
//mylog(log_info,"[%s:%d]size %d \n",my_ntoa(get_u64_h(it->first)),get_u64_l(it->first),(int)it->second->conv_manager.get_size());
135-
it++;
136-
}
137-
else if(current_time<it->second->last_active_time+server_conn_timeout)
138-
{
139-
it++;
140-
}
141-
else
142-
{
143-
address_t tmp_addr=it->first;// avoid making get_str() const;
144-
mylog(log_info,"{%s} inactive conn cleared \n",tmp_addr.get_str());
145-
old_it=it;
146-
it++;
147-
erase(old_it);
148-
}
149-
cnt++;
150-
}
151-
clear_it=it;
152-
return 0;
88+
int conn_manager_t::clear_inactive0() {
89+
// mylog(log_info,"called\n");
90+
unordered_map<address_t, conn_info_t *>::iterator it;
91+
unordered_map<address_t, conn_info_t *>::iterator old_it;
92+
93+
if (disable_conn_clear) return 0;
94+
95+
// map<uint32_t,uint64_t>::iterator it;
96+
int cnt = 0;
97+
it = clear_it; // TODO,write it back
98+
int size = mp.size();
99+
int num_to_clean = size / conn_clear_ratio + conn_clear_min; // clear 1/10 each time,to avoid latency glitch
100+
101+
// mylog(log_trace,"mp.size() %d\n", size);
102+
103+
num_to_clean = min(num_to_clean, (int)mp.size());
104+
u64_t current_time = get_current_time();
105+
106+
// mylog(log_info,"here size=%d\n",(int)mp.size());
107+
for (;;) {
108+
if (cnt >= num_to_clean) break;
109+
if (mp.begin() == mp.end()) break;
110+
if (it == mp.end()) {
111+
it = mp.begin();
112+
}
113+
114+
if (it->second->conv_manager.s.get_size() > 0) {
115+
// mylog(log_info,"[%s:%d]size %d \n",my_ntoa(get_u64_h(it->first)),get_u64_l(it->first),(int)it->second->conv_manager.get_size());
116+
it++;
117+
} else if (current_time < it->second->last_active_time + server_conn_timeout) {
118+
it++;
119+
} else {
120+
address_t tmp_addr = it->first; // avoid making get_str() const;
121+
mylog(log_info, "{%s} inactive conn cleared \n", tmp_addr.get_str());
122+
old_it = it;
123+
it++;
124+
erase(old_it);
125+
}
126+
cnt++;
127+
}
128+
clear_it = it;
129+
return 0;
153130
}

0 commit comments

Comments
 (0)