SSLClient.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include "stdafx.h"
  25. #include "SSLClient.h"
  26. #include "SSLHelper.h"
  27. BOOL CSSLClient::CheckParams()
  28. {
  29. if(!g_SSL.IsValid())
  30. {
  31. SetLastError(SE_SSL_ENV_NOT_READY, __FUNCTION__, ERROR_NOT_READY);
  32. return FALSE;
  33. }
  34. return __super::CheckParams();
  35. }
  36. void CSSLClient::PrepareStart()
  37. {
  38. m_dwMainThreadID = ::GetCurrentThreadId();
  39. __super::PrepareStart();
  40. }
  41. void CSSLClient::Reset()
  42. {
  43. m_sslSession.Reset();
  44. if(m_dwMainThreadID != 0)
  45. {
  46. g_SSL.RemoveThreadLocalState(m_dwMainThreadID);
  47. m_dwMainThreadID = 0;
  48. }
  49. __super::Reset();
  50. }
  51. void CSSLClient::OnWorkerThreadEnd(DWORD dwThreadID)
  52. {
  53. g_SSL.RemoveThreadLocalState();
  54. __super::OnWorkerThreadEnd(dwThreadID);
  55. }
  56. BOOL CSSLClient::SendPackets(const WSABUF pBuffers[], int iCount)
  57. {
  58. ASSERT(pBuffers && iCount > 0);
  59. return ::ProcessSend(this, this, &m_sslSession, pBuffers, iCount);
  60. }
  61. EnHandleResult CSSLClient::FireConnect()
  62. {
  63. EnHandleResult result = DoFireConnect(this);
  64. if(result != HR_ERROR)
  65. {
  66. m_sslSession.Renew();
  67. VERIFY(::ProcessHandShake(this, this, &m_sslSession) == HR_OK);
  68. }
  69. return result;
  70. }
  71. EnHandleResult CSSLClient::FireReceive(const BYTE* pData, int iLength)
  72. {
  73. return ::ProcessReceive(this, this, &m_sslSession, pData, iLength);
  74. }