TcpPullClient.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Author : Bruce Liang
  5. * Website : https://github.com/ldcsaa
  6. * Project : https://github.com/ldcsaa/HP-Socket
  7. * Blog : http://www.cnblogs.com/ldcsaa
  8. * Wiki : http://www.oschina.net/p/hp-socket
  9. * QQ Group : 44636872, 75375912
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. #pragma once
  24. #include "TcpClient.h"
  25. #include "MiscHelper.h"
  26. template<class T> class CTcpPullClientT : public IPullClient, public T
  27. {
  28. using __super = T;
  29. using __super::m_itPool;
  30. public:
  31. using __super::Stop;
  32. using __super::Wait;
  33. using __super::GetState;
  34. public:
  35. virtual EnFetchResult Fetch(BYTE* pData, int iLength)
  36. {
  37. return ::FetchBuffer(&m_lsBuffer, pData, iLength);
  38. }
  39. virtual EnFetchResult Peek(BYTE* pData, int iLength)
  40. {
  41. return ::PeekBuffer(&m_lsBuffer, pData, iLength);
  42. }
  43. protected:
  44. virtual EnHandleResult DoFireReceive(ITcpClient* pSender, const BYTE* pData, int iLength)
  45. {
  46. m_lsBuffer.Cat(pData, iLength);
  47. return __super::DoFireReceive(pSender, m_lsBuffer.Length());
  48. }
  49. virtual void Reset()
  50. {
  51. m_lsBuffer.Clear();
  52. __super::Reset();
  53. }
  54. public:
  55. CTcpPullClientT(ITcpClientListener* pListener)
  56. : T (pListener)
  57. , m_lsBuffer(m_itPool)
  58. {
  59. }
  60. virtual ~CTcpPullClientT()
  61. {
  62. ENSURE_STOP();
  63. }
  64. private:
  65. TItemListEx m_lsBuffer;
  66. };
  67. typedef CTcpPullClientT<CTcpClient> CTcpPullClient;
  68. #ifdef _SSL_SUPPORT
  69. #include "SSLClient.h"
  70. typedef CTcpPullClientT<CSSLClient> CSSLPullClient;
  71. #endif