#include "stdafx.h"
|
#include "AcceptClient.h"
|
|
|
namespace BEQ {
|
CAcceptClient::CAcceptClient()
|
{
|
m_listener.onRead = nullptr;
|
m_listener.onClose = nullptr;
|
m_pContext1 = nullptr;
|
m_pContext2 = nullptr;
|
m_pContext3 = nullptr;
|
m_pContext4 = nullptr;
|
}
|
|
CAcceptClient::~CAcceptClient()
|
{
|
|
}
|
|
void CAcceptClient::setListener(AcceptClientListener listener)
|
{
|
m_listener.onRead = listener.onRead;
|
m_listener.onClose = listener.onClose;
|
}
|
|
void CAcceptClient::OnClose(int nErrorCode)
|
{
|
if (m_listener.onClose != nullptr) {
|
m_listener.onClose(this);
|
}
|
|
__super::OnClose(nErrorCode);
|
}
|
|
|
void CAcceptClient::OnReceive(int nErrorCode)
|
{
|
char szBuffer[4096];
|
int nRead = Receive(szBuffer, 4096);
|
switch (nRead) {
|
case 0:
|
Close();
|
break;
|
case SOCKET_ERROR:
|
if (GetLastError() != WSAEWOULDBLOCK) {
|
Close();
|
}
|
break;
|
default:
|
if (m_listener.onRead != nullptr) {
|
m_listener.onRead(this, szBuffer, nRead);
|
}
|
}
|
|
__super::OnReceive(nErrorCode);
|
}
|
}
|