| | |
| | | // pOpen OpenFunc;
|
| | | // pClose CloseFunc;
|
| | |
|
| | | typedef struct tagCallBackFuncs
|
| | | {
|
| | | std::function<int(void)> OpenFunc;
|
| | | std::function<int(void)> CloseFunc;
|
| | | std::function<int(void)> ClearBufFunc;
|
| | | std::function<int (void *,int)> SendPkgFunc;
|
| | | std::function<int(void *, int)> RecvPkgFunc;
|
| | | std::function<int(int)> OpenFunc;
|
| | | std::function<int(int)> CloseFunc;
|
| | | }stCallBackFuncs, *pCallBackFuncs;
|
| | |
|
| | |
|
| | | stCallBackFuncs m_CallBackFuncs;
|
| | |
|
| | | int m_bSendCallBackSet = 0;
|
| | | int m_bRecvCallBackSet = 0;
|
| | | int m_bOpenCallBackSet = 0;
|
| | | int m_bCloseCallBackSet = 0;
|
| | | int m_bClearBufCallBackSet = 0;
|
| | |
|
| | | bool m_bOpened=false;
|
| | |
|
| | | int SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc);
|
| | | int SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc);
|
| | | int SetOpenCallBackFunc(std::function<int(int)> pOpenFunc);
|
| | | int SetCloseCallBackFunc(std::function<int(int)> pCloseFunc);
|
| | | int SetCallBackFuncs(pCallBackFuncs pFuncSt);
|
| | |
|
| | | int m_nErrCount = 0;
|
| | | int m_nContinueErrCount = 0;
|
| | |
| | | {
|
| | | if (m_bOpenCallBackSet)
|
| | | {
|
| | | OpenFunc(OpenParam);
|
| | | m_CallBackFuncs.OpenFunc();
|
| | | }
|
| | | m_bOpened = true;
|
| | | return KL_OK;
|
| | |
| | | {
|
| | | if (m_bCloseCallBackSet)
|
| | | {
|
| | | CloseFunc(CloseParam);
|
| | | m_CallBackFuncs.CloseFunc();
|
| | | }
|
| | | m_bOpened = false;
|
| | | return KL_OK;
|
| | | };
|
| | | int SendPacket(void * pBuf, int Len)
|
| | | {
|
| | | if (m_bOpened && m_bSendCallBackSet) return SendPkgFunc(pBuf, Len);
|
| | | if (m_bOpened && m_bSendCallBackSet)
|
| | | { |
| | | if (m_bClearBufCallBackSet) m_CallBackFuncs.ClearBufFunc();
|
| | | return m_CallBackFuncs.SendPkgFunc(pBuf, Len);
|
| | | }
|
| | | else return KL_ERR;
|
| | | }
|
| | |
|
| | | int RecvPacket(void * pBuf, int LenToRead, int ReTryCount=3)
|
| | | int RecvPacket(void * pBuf, int LenToRead, int ReTryCount=1)
|
| | | {
|
| | |
|
| | | if (m_bOpened && m_bRecvCallBackSet)
|
| | |
| | | char * pBufByte = (char *)pBuf;
|
| | | for (int i = 0; i < ReTryCount; i++)
|
| | | {
|
| | | int len1= RecvPkgFunc(pBufByte + len2, LenToRead - len2);
|
| | | int len1= m_CallBackFuncs.RecvPkgFunc(pBufByte + len2, LenToRead - len2);
|
| | | if (len1 <= 0 || len1 > 256) {
|
| | | continue;
|
| | | }
|