当前位置: 首页>>代码示例>>C++>>正文


C++ Condition::GetHandle方法代码示例

本文整理汇总了C++中Condition::GetHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ Condition::GetHandle方法的具体用法?C++ Condition::GetHandle怎么用?C++ Condition::GetHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Condition的用法示例。


在下文中一共展示了Condition::GetHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteSocket

bool Helium::WriteSocket(Socket& socket, void* buffer, uint32_t bytes, uint32_t& wrote, Condition& terminate, sockaddr_in *peer)
{
    CheckPeerParamCompatibleWithProtocol(static_cast<Helium::SocketProtocol>(socket.m_Protocol), peer);

    if (bytes == 0)
    {
        return true;
    }

    WSABUF buf;
    buf.buf = (CHAR*)buffer;
    buf.len = bytes;

    DWORD flags = 0;
    DWORD wrote_local = 0;

    int wsa_result = peer ? ::WSASendTo(socket.m_Handle, &buf, 1, &wrote_local, 0, (SOCKADDR *)peer, sizeof(sockaddr_in), (OVERLAPPED*)&socket.m_Overlapped, NULL) :
                            ::WSASend  (socket.m_Handle, &buf, 1, &wrote_local, 0, (OVERLAPPED*)&socket.m_Overlapped, NULL);

    if ( wsa_result != 0 )
    {
        int last_error = WSAGetLastError();
        if ( WSAGetLastError() != WSA_IO_PENDING )
        {
#ifdef IPC_DEBUG_SOCKETS
            Helium::Print("Socket Support: Failed to initiate overlapped write (%s)\n", Helium::GetErrorString().c_str());
#endif
            return false;
        }
        else
        {
            HANDLE events[] = { terminate.GetHandle(), socket.m_Overlapped.hEvent };
            DWORD result = ::WSAWaitForMultipleEvents(2, events, FALSE, INFINITE, FALSE);

            HELIUM_ASSERT( result != WAIT_FAILED );

            if ( (result - WAIT_OBJECT_0) == 0 )
            {
#ifdef IPC_DEBUG_SOCKETS
                Helium::Print("Socket Support: Terminating write\n");
#endif
                return false;
            }

            if ( !::WSAGetOverlappedResult(socket.m_Handle, (OVERLAPPED*)&socket.m_Overlapped, &wrote_local, false, &flags) )
            {
#ifdef IPC_DEBUG_SOCKETS
                Helium::Print("Socket Support: Failed write (%s)\n", Helium::GetErrorString().c_str());
#endif
                return false;
            }
        }
    }

    if (wrote_local == 0)
    {
        return false;
    }

    wrote = (uint32_t)wrote_local;

    return true;
}
开发者ID:,项目名称:,代码行数:63,代码来源:


注:本文中的Condition::GetHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。