55#include " Loggere.h"
66
77
8+
9+
10+
11+
12+ template <typename _FUNCTION, typename ... _ARGS>
13+ class CConnetFunction : public CFunctionBase
14+ {
15+ public:
16+
17+ CConnetFunction (_FUNCTION func, _ARGS... args)
18+ :m_binder(std::forward<_FUNCTION>(func), std::forward<_ARGS>(args)...)
19+ {
20+
21+ }
22+ typename std::_Bindres_helper<int , _FUNCTION, _ARGS...>::type m_binder;
23+ virtual ~CConnetFunction () {}
24+
25+ virtual int operator ()(CSocketBase* pClient)
26+ {
27+ return m_binder (pClient);
28+ }
29+
30+ };
31+
32+
33+
34+ template <typename _FUNCTION, typename ... _ARGS>
35+ class CRecvFunction : public CFunctionBase
36+ {
37+ public:
38+
39+ CRecvFunction (_FUNCTION func, _ARGS... args)
40+ :m_binder(std::forward<_FUNCTION>(func), std::forward<_ARGS>(args)...)
41+ {
42+
43+ }
44+
45+ virtual ~CRecvFunction () {}
46+ virtual int operator ()(CSocketBase* pClient, const Buffer& data)
47+ {
48+ return m_binder (pClient, data);
49+ }
50+ typename std::_Bindres_helper<int , _FUNCTION, _ARGS...>::type m_binder;
51+
52+ };
53+
854class CBusiness
955{
1056public:
@@ -18,21 +64,31 @@ class CBusiness
1864 template <typename _FUNCTION_, typename ..._ARGS_>
1965 int SetConnectedcallback (_FUNCTION_ func, _ARGS_... args)
2066 {
21- m_connnectedcallback = new CFunction <_FUNCTION_, _ARGS_...>(func, args...);
67+ m_connnectedcallback = new CConnetFunction <_FUNCTION_, _ARGS_...>(func, args...);
2268 if (m_connnectedcallback == NULL ) return -1 ;
2369 return 0 ;
2470
2571 }
2672
27-
2873 template <typename _FUNCTION_, typename ..._ARGS_>
2974 int SetRecvcallback (_FUNCTION_ func, _ARGS_... args)
3075 {
31- m_recvcallback = new CFunction <_FUNCTION_, _ARGS_...>(func, args...);
76+ m_recvcallback = new CRecvFunction <_FUNCTION_, _ARGS_...>(func, args...);
3277 if (m_recvcallback == NULL ) return -1 ;
3378 return 0 ;
3479
3580 }
81+
82+
83+ // template<typename _FUNCTION_, typename ..._ARGS_>
84+ // int SetRecvcallback(_FUNCTION_ func, _ARGS_... args)
85+ // {
86+ // m_connnectedcallback = new CConnetFunction<_FUNCTION_, _ARGS_...>(func, args...);
87+ // //m_connnectedcallback = new CConnetFunction<_FUNCTION_, _ARGS_...>(func, args...);
88+ // if (m_recvcallback == NULL) return -1;
89+ // return 0;
90+
91+ // }
3692protected:
3793
3894 CFunctionBase* m_connnectedcallback;
0 commit comments