完成端口最最最基本的理解

完成端口最最最基本的理解
// IOCP_Learn.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <WinSock2.h>
// 根据某结构体中一个成员的地址,计算出外层结构体的地址
//CONTAINING_RECORD
class CTest_CONTAINING_RECORD
{
public:
    void Test()
    {
        CTest_CONTAINING_RECORD* pTest = CONTAINING_RECORD(&m_i, CTest_CONTAINING_RECORD, m_i);
        std::cout << reinterpret_cast<unsigned int>(this) << std::endl;
        std::cout << reinterpret_cast<unsigned int>(pTest) << std::endl;
    }
private:
    int m_i;
};
//OVERLAPPED
namespace iocp
{
enum EM_IOCP_OP_TYPE
{
    emIOCP_POST_SEND = 0, 
    emIOCP_POST_ASYNC_RECV,
    emIOCP_POST_ACCEPT,
    emIOCP_DISSCONNECT
};
};//~ end of namespace iocp
// 直接继承OVERLAPPED,根据C++对象的内存布局可以确定stIOCP_OVERLAPPED和static_cast<OVERLAPPED>(obj_stIOCP_OVERLAPPED)
// 是一样的
struct stIOCP_OVERLAPPED : public OVERLAPPED
{
    WSABUF wsabuf;
    EM_IOCP_OP_TYPE optype;
};

// 还有一个是关联的key,没有提到,以及关联socket句柄和完成提示
int _tmain(int argc, _TCHAR* argv[])
{
    CTest_CONTAINING_RECORD test;
    test.Test();
return 0;
}

你可能感兴趣的:(完成端口最最最基本的理解)