-
Notifications
You must be signed in to change notification settings - Fork 250
/
tc_epoll_server.h
1868 lines (1559 loc) · 44.6 KB
/
tc_epoll_server.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TARS_TC_EPOLL_SERVER_H_
#define __TARS_TC_EPOLL_SERVER_H_
#include <string>
#include <memory>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include "util/tc_epoller.h"
#include "util/tc_thread.h"
#include "util/tc_clientsocket.h"
#include "util/tc_logger.h"
#include "util/tc_shm.h"
#include "util/tc_common.h"
#include "util/tc_mem_queue.h"
#include "util/tc_squeue.h"
#include "util/tc_mmap.h"
#include "util/tc_fifo.h"
#include "util/tc_buffer.h"
#include "util/tc_buffer_pool.h"
using namespace std;
namespace tars
{
#if TARS_SSL
class TC_OpenSSL;
#endif
/////////////////////////////////////////////////
/**
* @file tc_epoll_server.h
* @brief EpollServer类
*
*/
/////////////////////////////////////////////////
/**
* Server基类
* 注册协议解析器
* 注册逻辑处理器
* 注册管理端口处理器
*/
class PropertyReport;
class TC_EpollServer : public TC_ThreadLock, public TC_HandleBase
{
public:
////////////////////////////////////////////////////////////////////////////
/**
* 定义协议解析的返回值
*/
enum
{
PACKET_LESS = 0,
PACKET_FULL = 1,
PACKET_ERR = -1,
};
enum EM_CLOSE_T
{
EM_CLIENT_CLOSE = 0, //客户端主动关闭
EM_SERVER_CLOSE = 1, //服务端业务主动调用close关闭连接,或者框架因某种异常主动关闭连接
EM_SERVER_TIMEOUT_CLOSE = 2 //连接超时了,服务端主动关闭
};
/**
* 定义协议解析接口的操作对象
* 注意必须是线程安全的或是可以重入的
*/
using protocol_functor = std::function<int (string&, string&)>;
using header_filter_functor = std::function<int (int, string&)>;
using conn_protocol_functor = std::function<int (string&, string&, void*)>;
class NetThread;
class BindAdapter;
typedef TC_AutoPtr<BindAdapter> BindAdapterPtr;
class Handle;
typedef TC_AutoPtr<Handle> HandlePtr;
class HandleGroup;
typedef TC_AutoPtr<HandleGroup> HandleGroupPtr;
////////////////////////////////////////////////////////////////////////////
/**定义数据队列中的结构*/
struct tagRecvData
{
uint32_t uid; /**连接标示*/
string buffer; /**需要发送的内容*/
string ip; /**远程连接的ip*/
uint16_t port; /**远程连接的端口*/
int64_t recvTimeStamp; /**接收到数据的时间*/
bool isOverload; /**是否已过载 */
bool isClosed; /**是否已关闭*/
int fd; /*保存产生该消息的fd,用于回包时选择网络线程*/
BindAdapterPtr adapter; /**标识哪一个adapter的消息*/
int closeType; /*如果是关闭消息包,则标识关闭类型,0:表示客户端主动关闭;1:服务端主动关闭;2:连接超时服务端主动关闭*/
};
struct tagSendData
{
char cmd; /**命令:'c',关闭fd; 's',有数据需要发送*/
uint32_t uid; /**连接标示*/
string buffer; /**需要发送的内容*/
string ip; /**远程连接的ip*/
uint16_t port; /**远程连接的端口*/
};
typedef TC_ThreadQueue<tagRecvData*, deque<tagRecvData*> > recv_queue;
typedef TC_ThreadQueue<tagSendData*, deque<tagSendData*> > send_queue;
typedef recv_queue::queue_type recv_queue_type;
////////////////////////////////////////////////////////////////////////////
/**
* 链接状态
*/
struct ConnStatus
{
string ip;
int32_t uid;
uint16_t port;
int timeout;
int iLastRefreshTime;
};
////////////////////////////////////////////////////////////////////////////
/**
* 按name对handle分组,
* 每组handle处理一个或多个Adapter消息
* 每个handle对象一个线程
*/
struct HandleGroup : public TC_HandleBase
{
string name;
TC_ThreadLock monitor;
vector<HandlePtr> handles;
map<string, BindAdapterPtr> adapters;
};
////////////////////////////////////////////////////////////////////////////
/**
* @brief 定义服务逻辑处理的接口
*
*/
/**
* 服务的逻辑处理代码
*/
class Handle : public TC_Thread, public TC_ThreadLock, public TC_HandleBase
{
public:
/**
* 构造, 默认没有请求, 等待10s
*/
Handle();
/**
* 析构函数
*/
virtual ~Handle();
/**
* 设置服务
* @param pEpollServer
*/
void setEpollServer(TC_EpollServer *pEpollServer);
/**
* 获取服务
* @return TC_EpollServer*
*/
TC_EpollServer* getEpollServer();
/**
* 设置所属的Group
* @param pHandleGroup
*/
void setHandleGroup(HandleGroupPtr& pHandleGroup);
/**
* 获取所属Group
* @return HandleGroup*
*/
HandleGroupPtr& getHandleGroup();
/**
* 线程处理方法
*/
virtual void run();
public:
/**
* 发送数据
* @param stRecvData
* @param sSendBuffer
*/
void sendResponse(unsigned int uid, const string &sSendBuffer, const string &ip, int port, int fd);
/**
* 关闭链接
* @param stRecvData
*/
void close(unsigned int uid, int fd);
/**
* 设置等待时间
* @param iWaitTime
*/
void setWaitTime(uint32_t iWaitTime);
/**
* 对象初始化
*/
virtual void initialize() {};
/**
* 唤醒HandleGroup中的handle线程
*/
virtual void notifyFilter();
protected:
/**
* 具体的处理逻辑
*/
virtual void handleImp();
/**
* 处理函数
* @param stRecvData: 接收到的数据
*/
virtual void handle(const tagRecvData &stRecvData) = 0;
/**
* 处理超时数据, 即数据在队列中的时间已经超过
* 默认直接关闭连接
* @param stRecvData: 接收到的数据
*/
virtual void handleTimeout(const tagRecvData &stRecvData);
/**
* 处理连接关闭通知,包括
* 1.close by peer
* 2.recv/send fail
* 3.close by timeout or overload
* @param stRecvData:
*/
virtual void handleClose(const tagRecvData &stRecvData);
/**
* 处理overload数据 即数据队列中长度已经超过允许值
* 默认直接关闭连接
* @param stRecvData: 接收到的数据
*/
virtual void handleOverload(const tagRecvData &stRecvData);
/**
* 处理Filter的消息
*/
//virtual void handleFilter() {};
/**
* 处理异步回调队列
*/
virtual void handleAsyncResponse() {}
/**
* handleFilter拆分的第二部分,处理用户自有数据
* 非游戏逻辑可忽略bExpectIdle参数
*/
virtual void handleCustomMessage(bool bExpectIdle = false) {}
/**
* 心跳(每处理完一个请求或者等待请求超时都会调用一次)
*/
virtual void heartbeat() {}
/**
* 线程已经启动, 进入具体处理前调用
*/
virtual void startHandle() {}
/**
* 线程马上要退出时调用
*/
virtual void stopHandle() {}
/**
* 是否所有的Adpater队列都为空
* @return bool
*/
virtual bool allAdapterIsEmpty();
/**
* 是否所有的servant都没有resp消息待处理
* @return bool
*/
virtual bool allFilterIsEmpty();
/**
* 友元类
*/
friend class BindAdapter;
protected:
/**
* 服务
*/
TC_EpollServer *_pEpollServer;
/**
* 所属handle组
*/
HandleGroupPtr _handleGroup;
/**
* 等待时间
*/
uint32_t _iWaitTime;
};
using close_functor = std::function<void (void*, EM_CLOSE_T )>;
using auth_process_wrapper_functor = std::function<bool (void*, const std::string& )>;
////////////////////////////////////////////////////////////////////////////
// 服务端口管理,监听socket信息
class BindAdapter : public TC_ThreadLock, public TC_HandleBase
{
public:
/**
* 缺省的一些定义
*/
enum
{
DEFAULT_QUEUE_CAP = 10*1024, /**流量*/
MIN_QUEUE_TIMEOUT = 3*1000, /**队列最小超时时间(ms)*/
DEFAULT_MAX_CONN = 1024, /**缺省最大连接数*/
DEFAULT_QUEUE_TIMEOUT = 60*1000, /**缺省的队列超时时间(ms)*/
};
/**
* 顺序
*/
enum EOrder
{
ALLOW_DENY,
DENY_ALLOW
};
BindAdapter()
{
_pReportQueue = NULL;
_pReportConRate = NULL;
_pReportTimeoutNum = NULL;
}
/**
* 构造函数
*/
BindAdapter(TC_EpollServer *pEpollServer);
/**
* 析够函数
*/
~BindAdapter();
/**
* 设置adapter name
* @param name
*/
void setName(const string &name);
/**
* 获取adapter name
* @return string
*/
string getName() const;
/**
* 获取queue capacity
* @return int
*/
int getQueueCapacity() const;
/**
* 设置queue capacity
* @param n
*/
void setQueueCapacity(int n);
/**
* 设置协议名称
* @param name
*/
void setProtocolName(const string& name);
/**
* 获取协议名称
* @return const string&
*/
const string& getProtocolName();
/**
* 是否tars协议
* @return bool
*/
bool isTarsProtocol();
/**
* 判断是否需要过载保护
* @return bool
*/
int isOverloadorDiscard();
/**
* 设置消息在队列中的超时时间, t为毫秒
* (超时时间精度只能是s)
* @param t
*/
void setQueueTimeout(int t);
/**
* 获取消息在队列中的超时时间, 毫秒
* @return int
*/
int getQueueTimeout() const;
/**
* 设置endpoint
* @param str
*/
void setEndpoint(const string &str);
/**
* 获取ip
* @return const string&
*/
TC_Endpoint getEndpoint() const;
/**
* 监听socket
* @return TC_Socket
*/
TC_Socket &getSocket();
/**
* 设置最大连接数
* @param iMaxConns
*/
void setMaxConns(int iMaxConns);
/**
* 获取最大连接数
* @return size_t
*/
size_t getMaxConns() const;
/**
* 设置HeartBeat时间
* @param n
*/
void setHeartBeatTime(time_t t);
/**
* 获取HeartBeat时间
* @return size_t
*/
time_t getHeartBeatTime() const;
/**
* 设置allow deny次序
* @param eOrder
*/
void setOrder(EOrder eOrder);
/**
* 设置允许ip
* @param vtAllow
*/
void setAllow(const vector<string> &vtAllow);
/**
* 设置禁止ip
* @param vtDeny
*/
void setDeny(const vector<string> &vtDeny);
/**
* 获取允许ip
* @return vector<string>: ip列表
*/
vector<string> getAllow() const;
/**
* 获取禁止ip
* @return vector<string>: ip列表
*/
vector<string> getDeny() const;
/**
* 获取allow deny次序
* @return EOrder
*/
EOrder getOrder() const;
/**
* 是否Ip被允许
* @param ip
* @return bool
*/
bool isIpAllow(const string& ip) const;
/**
* 是否超过了最大连接数
* @return bool
*/
bool isLimitMaxConnection() const;
/**
* 减少当前连接数
*/
void decreaseNowConnection();
/**
* 减少当前连接数
*/
void increaseNowConnection();
/**
* 获取所有链接状态
* @return ConnStatus
*/
vector<ConnStatus> getConnStatus();
/**
* 获取当前连接数
* @return size_t
*/
size_t getNowConnection() const;
/**
* 获取EpollServer
* @return TC_EpollServer*
*/
TC_EpollServer* getEpollServer();
/**
* 注册协议解析器
* @param pp
*/
void setProtocol(const protocol_functor& pf, int iHeaderLen = 0, const header_filter_functor& hf = echo_header_filter);
/**
* 获取协议解析器
* @return protocol_functor&
*/
protocol_functor &getProtocol();
/**
* 解析包头处理对象
* @return protocol_functor&
*/
header_filter_functor &getHeaderFilterFunctor();
/**
* 增加数据到队列中
* @param vtRecvData
* @param bPushBack 后端插入
* @param sBuffer
*/
void insertRecvQueue(const recv_queue::queue_type &vtRecvData,bool bPushBack = true);
/**
* 通知等待在接收队列上面的线程醒过来
*/
void notifyRecvQueue();
/**
* 等待数据
* @return bool
*/
bool waitForRecvQueue(tagRecvData* &recv, uint32_t iWaitTime);
/**
* 接收队列的大小
* @return size_t
*/
size_t getRecvBufferSize() const;
/**
* 默认的协议解析类, 直接echo
* @param r
* @param o
* @return int
*/
static int echo_protocol(string &r, string &o);
/**
* 默认的包头处理
* @param i
* @param o
* @return int
*/
static int echo_header_filter(int i, string &o);
/**
* 获取需要过滤的包头长度
*/
int getHeaderFilterLen();
/**
* 设置所属的handle组名
* @param handleGroupName
*/
void setHandleGroupName(const string& handleGroupName);
/**
* 获得所属的handle组名
* @return string
*/
string getHandleGroupName() const;
/**
* 获得所属的handle
* @return HandleGroupPtr
*/
HandleGroupPtr getHandleGroup() const
{
return _handleGroup;
}
/**
* 设置ServantHandle数目
* @param n
*/
void setHandleNum(int n);
/**
* 所属handle组的handle数(每个handle一个对象)
* @return int
*/
int getHandleNum();
/**
* 绑定两个Adapter到同一个Group
* @param otherAdapter
*/
void setHandle(BindAdapterPtr& otherAdapter)
{
_pEpollServer->setHandleGroup(otherAdapter->getHandleGroupName(), this);
}
/**
* 初始化处理线程,线程将会启动
*/
template<typename T> void setHandle()
{
_pEpollServer->setHandleGroup<T>(_handleGroupName, _iHandleNum, this);
}
/**
* 设置服务端回包缓存的大小限制
*/
void setBackPacketBuffLimit(size_t iLimitSize);
/**
* 获取服务端回包缓存的大小限制
*/
size_t getBackPacketBuffLimit();
/**
* 设置close回调函数
*/
void setOnClose(const close_functor& f) { _closeFunc = f; }
/**
* 注册协议解析器
*/
void setConnProtocol(const conn_protocol_functor& cpf, int iHeaderLen = 0, const header_filter_functor& hf = echo_header_filter);
/**
* 获取协议解析器
* @return conn_protocol_functor&
*/
conn_protocol_functor& getConnProtocol() { return _cpf; }
/**
* 注册鉴权包裹函数
* @param apwf
*/
void setAuthProcessWrapper(const auth_process_wrapper_functor& apwf) { _authWrapper = apwf; }
void setAkSk(const std::string& ak, const std::string& sk) { _accessKey = ak; _secretKey = sk; }
bool checkAkSk(const std::string& ak, const std::string& sk) { return ak == _accessKey && sk == _secretKey; }
std::string getSk(const std::string& ak) const { return (_accessKey == ak) ? _secretKey : ""; }
public:
//统计上报的对象
PropertyReport * _pReportQueue;
PropertyReport * _pReportConRate;
PropertyReport * _pReportTimeoutNum;
protected:
friend class TC_EpollServer;
friend class NetThread;
/**
* 服务
*/
TC_EpollServer *_pEpollServer;
/**
* Adapter所用的HandleGroup
*/
HandleGroupPtr _handleGroup;
/**
* 协议解析
*/
protocol_functor _pf;
/**
* 首个数据包包头过滤
*/
header_filter_functor _hf;
/**
* adapter的名字
*/
string _name;
/**
* handle分组名称
*/
string _handleGroupName;
/**
* 监听fd
*/
TC_Socket _s;
/**
* 绑定的IP
*/
TC_Endpoint _ep;
/**
* 最大连接数
*/
int _iMaxConns;
/**
* 当前连接数
*/
TC_Atomic _iCurConns;
/**
* Handle个数
*/
size_t _iHandleNum;
/**
* 允许的Order
*/
volatile EOrder _eOrder;
/**
* 允许的ip
*/
vector<string> _vtAllow;
/**
* 禁止的ip
*/
vector<string> _vtDeny;
/**
* 接收的数据队列
*/
recv_queue _rbuffer;
/**
* 队列最大容量
*/
int _iQueueCapacity;
/**
* 消息超时时间(从入队列到出队列间隔)(毫秒)
*/
int _iQueueTimeout;
/**
* 首个数据包包头长度
*/
int _iHeaderLen;
/**
* 上次心跳发送时间
*/
volatile time_t _iHeartBeatTime;
/**
* 协议名称,缺省为"tars"
*/
string _protocolName;
//回包缓存限制大小
size_t _iBackPacketBuffLimit;
/**
* 包裹认证函数,不能为空
*/
auth_process_wrapper_functor _authWrapper;
/**
* 该obj的AK SK
*/
std::string _accessKey;
std::string _secretKey;
//连接关闭的回调函数
close_functor _closeFunc;
// 协议解析
conn_protocol_functor _cpf;
};
////////////////////////////////////////////////////////////////////////////
class NetThread : public TC_Thread, public TC_ThreadLock, public TC_HandleBase
{
public:
////////////////////////////////////////////////////////////////////////////
// 服务连接管理
/**
* 建立连接的socket信息
*/
class Connection
{
public:
enum EnumConnectionType
{
EM_TCP = 0,
EM_UDP = 1,
};
/**
* 构造函数
* @param lfd
* @param s
* @param ip
* @param port
*/
Connection(BindAdapter *pBindAdapter, int lfd, int timeout, int fd, const string& ip, uint16_t port);
/**
* udp连接
* @param fd
*/
Connection(BindAdapter *pBindAdapter, int fd);
/**
* 通讯组件初始化
*/
Connection(BindAdapter *pBindAdapter);
/**
* 析构函数
*/
virtual ~Connection();
/**
* 链接所属的adapter
*/
BindAdapter* getBindAdapter() { return _pBindAdapter; }
/**
* 初始化
* @param id, 连接的唯一id
*/
void init(unsigned int uid) { _uid = uid; }
/**
* 获取连接超时时间
*
* @return int
*/
int getTimeout() const { return _timeout; }
/**
* 获取线程的惟一id
*
* @return unsigned int
*/
uint32_t getId() const { return _uid; }
/**
* 获取监听fd
*
* @return int
*/
int getListenfd() const { return _lfd; }
/**
* 当前连接fd
*
* @return int
*/
virtual int getfd() const { return _sock.getfd(); }
/**
* 是否有效
*
* @return bool
*/
bool isValid() const { return _sock.isValid();}
/**
* 远程IP
*
* @return string
*/
string getIp() const { return _ip; }
/**
* 远程端口
*
* @return uint16_t
*/
uint16_t getPort() const { return _port; }
/**
* 设置首个数据包包头需要过滤的字节数
*/
void setHeaderFilterLen(int iHeaderLen) { _iHeaderLen = iHeaderLen; }
/**
* 设置关闭,发送完当前数据就关闭连接
*/
bool setClose();// { _bClose = true; return _sendbuffer.empty(); }
/**
* 获取连接类型
*/
EnumConnectionType getType() const { return _enType; }
bool IsEmptyConn() const {return _bEmptyConn;}
/**
* Init Auth State;
*/
void tryInitAuthState(int initState);
protected:
/**
* 关闭连接
* @param fd
*/
void close();
/**
* 添加发送buffer
* @param buffer
* @return int, -1:发送出错, 0:无数据, 1:发送完毕, 2:还有数据
*/
virtual int send(const string& buffer, const string &ip, uint16_t port, bool byEpollout = false);
/**
* 发送数据
*
* @return int
*/
virtual int send();
/**
* 发送buffer-slices
* @param slices
* @return int, -1:发送出错, >= 0:发送的字节数
*/
int send(const std::vector<TC_Slice>& slices);
/**
* 读取数据