TcpPullClient.h 1.8 KB

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