LAPTOP-T815PCOQ\25526
2025-01-09 592c0397bd5bc333b37b0b762b1bfeedae11f770
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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);
    }
}