123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /*
- * Copyright: JessMA Open Source (ldcsaa@gmail.com)
- *
- * Version : 3.6.1
- * Author : Bruce Liang
- * Website : http://www.jessma.org
- * Project : https://github.com/ldcsaa
- * Blog : http://www.cnblogs.com/ldcsaa
- * Wiki : http://www.oschina.net/p/hp-socket
- * QQ Group : 75375912
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- #include "stdafx.h"
- #include "SSLServer.h"
- #include "SSLHelper.h"
- BOOL CSSLServer::CheckParams()
- {
- if(!g_SSL.IsValid())
- {
- SetLastError(SE_SSL_ENV_NOT_READY, __FUNCTION__, ERROR_NOT_READY);
- return FALSE;
- }
- return __super::CheckParams();
- }
- void CSSLServer::PrepareStart()
- {
- __super::PrepareStart();
- m_sslPool.SetItemCapacity (GetSocketBufferSize());
- m_sslPool.SetItemPoolSize (GetFreeBufferObjPool());
- m_sslPool.SetItemPoolHold (GetFreeBufferObjHold());
- m_sslPool.SetSessionLockTime(GetFreeSocketObjLockTime());
- m_sslPool.SetSessionPoolSize(GetFreeSocketObjPool());
- m_sslPool.SetSessionPoolHold(GetFreeSocketObjHold());
- m_sslPool.Prepare();
- }
- void CSSLServer::Reset()
- {
- g_SSL.RemoveThreadLocalState();
- __super::Reset();
- }
- void CSSLServer::OnWorkerThreadEnd(DWORD dwThreadID)
- {
- g_SSL.RemoveThreadLocalState();
- __super::OnWorkerThreadEnd(dwThreadID);
- }
- BOOL CSSLServer::SendPackets(CONNID dwConnID, const WSABUF pBuffers[], int iCount)
- {
- ASSERT(pBuffers && iCount > 0);
- TSocketObj* pSocketObj = FindSocketObj(dwConnID);
- if(!TSocketObj::IsValid(pSocketObj))
- {
- ::SetLastError(ERROR_OBJECT_NOT_FOUND);
- return FALSE;
- }
- CSSLSession* pSession = nullptr;
- GetConnectionReserved2(pSocketObj, (PVOID*)&pSession);
- return ::ProcessSend(this, pSocketObj, pSession, pBuffers, iCount);
- }
- EnHandleResult CSSLServer::FireAccept(TSocketObj* pSocketObj)
- {
- EnHandleResult result = DoFireAccept(pSocketObj);
- if(result != HR_ERROR)
- {
- CSSLSession* pSession = m_sslPool.PickFreeSession();
- VERIFY(SetConnectionReserved2(pSocketObj, pSession));
- VERIFY(::ProcessHandShake(this, pSocketObj, pSession) == HR_OK);
- }
- return result;
- }
- EnHandleResult CSSLServer::FireReceive(TSocketObj* pSocketObj, const BYTE* pData, int iLength)
- {
- CSSLSession* pSession = nullptr;
- GetConnectionReserved2(pSocketObj, (PVOID*)&pSession);
- ASSERT(pSession);
- return ::ProcessReceive(this, pSocketObj, pSession, pData, iLength);
- }
- EnHandleResult CSSLServer::FireClose(TSocketObj* pSocketObj, EnSocketOperation enOperation, int iErrorCode)
- {
- EnHandleResult result = DoFireClose(pSocketObj, enOperation, iErrorCode);
- CSSLSession* pSession = nullptr;
- GetConnectionReserved2(pSocketObj, (PVOID*)&pSession);
- ASSERT(pSession);
- if(pSession != nullptr)
- m_sslPool.PutFreeSession(pSession);
- return result;
- }
- EnHandleResult CSSLServer::FireShutdown()
- {
- EnHandleResult result = DoFireShutdown();
- m_sslPool.Clear();
- return result;
- }
|