• client实现TCP高并发


    碎片函数实现

    bool Socket::ConnectEx(const char * Address, uint32 Port)
    {
    struct hostent * ci = gethostbyname(Address);
    if(ci == 0)
    return false;

    SOCKADDR_IN addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = htons((short)0);
    ::bind(m_fd, (const sockaddr*)&addr, sizeof(addr));
    BindIoCompletionCallback((HANDLE)m_fd, SocketMgr::NetIOCompletionRoutine, 0);

    m_client.sin_family = ci->h_addrtype;
    m_client.sin_port = ntohs((u_short)Port);
    memcpy(&m_client.sin_addr.s_addr, ci->h_addr_list[0], ci->h_length);
    LPFN_CONNECTEX pfnConnectEx;
    GUID GuidConnectEx = WSAID_CONNECTEX;
    DWORD dwBytes;
    WSAIoctl(m_fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof(GuidConnectEx),
    &pfnConnectEx, sizeof(pfnConnectEx), &dwBytes, NULL, NULL);
    if (!pfnConnectEx)
    {
    return false;
    }
    m_writeEvent.Reset(this);
    m_writeEvent.m_event = SOCKET_IO_EVENT_CONNECTING;
    if (pfnConnectEx(m_fd, (const sockaddr*)&m_client, sizeof(SOCKADDR_IN), NULL, 0, NULL, &m_writeEvent.m_overlap))
    {

    }
    return true;
    }

  • 相关阅读:
    MongoDB小结07
    MongoDB小结07
    MongoDB小结06
    MongoDB小结05
    MongoDB小结04
    MongoDB小结03
    MongoDB小结02
    MongoDB小结01
    this与super
    UVa 11174
  • 原文地址:https://www.cnblogs.com/yifen/p/2825334.html
Copyright © 2020-2023  润新知