Ejemplo n.º 1
0
void Gosu::MessageSocket::update()
{
    std::vector<char> buffer(maxMessageSize());

    sockaddr_in addr;
    socklen_t size = sizeof addr;

    for (;;)
    {
        int received = ::recvfrom(pimpl->socket.handle(), &buffer.front(),
            buffer.size(), 0, reinterpret_cast<sockaddr*>(&addr),
            &size);

        if (received != SOCKET_ERROR && onReceive)
        {
            onReceive(ntohl(addr.sin_addr.s_addr),
                ntohs(addr.sin_port), &buffer.front(), received);
        }
        else switch (lastSocketError())
        {
            // Ignore some of the errors.
            case GOSU_SOCK_ERR(EWOULDBLOCK):
            case GOSU_SOCK_ERR(ENETDOWN):
            case GOSU_SOCK_ERR(ENETRESET):
            case GOSU_SOCK_ERR(ETIMEDOUT):
            case GOSU_SOCK_ERR(ECONNRESET):
                return;

            // Everything else is unexpected.
            default:
                throwLastSocketError();
        }
    }
}
Ejemplo n.º 2
0
HostReflectionHost::BootUp::BootUp(const std::string& module)
    : _module(module)
{
    report("Booting up host reflection...");

    // add message handlers
    _addMessageHandlers();

    // allocate memory for the queue
    size_t queueDataSize = maxMessageSize() * 2;
    size_t size = 2 * (queueDataSize + sizeof(QueueMetaData));

    _deviceHostSharedMemory = new char[size];

    // setup the queue meta data
    QueueMetaData* hostToDeviceMetaData =
        (QueueMetaData*)_deviceHostSharedMemory;
    QueueMetaData* deviceToHostMetaData =
        (QueueMetaData*)_deviceHostSharedMemory + 1;

    char* hostToDeviceData = _deviceHostSharedMemory +
                             2 * sizeof(QueueMetaData);
    char* deviceToHostData = _deviceHostSharedMemory +
                             2 * sizeof(QueueMetaData) + queueDataSize;

    hostToDeviceMetaData->hostBegin = hostToDeviceData;
    hostToDeviceMetaData->size      = queueDataSize;
    hostToDeviceMetaData->head      = 0;
    hostToDeviceMetaData->tail      = 0;
    hostToDeviceMetaData->mutex     = (size_t)-1;

    deviceToHostMetaData->hostBegin = deviceToHostData;
    deviceToHostMetaData->size      = queueDataSize;
    deviceToHostMetaData->head      = 0;
    deviceToHostMetaData->tail      = 0;
    deviceToHostMetaData->mutex     = (size_t)-1;

    // Allocate the queues
    _hostToDeviceQueue = new HostQueue(hostToDeviceMetaData);
    _deviceToHostQueue = new HostQueue(deviceToHostMetaData);

    // Map the memory onto the device
    cudaHostRegister(_deviceHostSharedMemory, size, 0);

    char* devicePointer = 0;

    cudaHostGetDevicePointer((void**)&devicePointer,
                             _deviceHostSharedMemory, 0);

    // Send the metadata to the device
    QueueMetaData* hostToDeviceMetaDataPointer =
        (QueueMetaData*)devicePointer;
    QueueMetaData* deviceToHostMetaDataPointer =
        (QueueMetaData*)devicePointer + 1;

    hostToDeviceMetaData->deviceBegin = devicePointer +
                                        2 * sizeof(QueueMetaData);
    deviceToHostMetaData->deviceBegin = devicePointer +
                                        2 * sizeof(QueueMetaData) + queueDataSize;

    cudaConfigureCall(dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);

    cudaSetupArgument(&hostToDeviceMetaDataPointer, 8, 0 );
    cudaSetupArgument(&deviceToHostMetaDataPointer, 8, 8 );
    ocelot::launch(_module, "_bootupHostReflection");

    // start up the host worker thread
    _kill   = false;
    _thread = new boost::thread(_runThread, this);
}