开源的socket服务端客户端,支持C# C++

TcpPullClient.h 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Version : 4.1.3
  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(ITcpClient* pSender, const BYTE* pData, int iLength)
  41. {
  42. m_lsBuffer.Cat(pData, iLength);
  43. return __super::DoFireReceive(pSender, 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