Esempio n. 1
0
void 
playdar_request_handler::handle_request(const moost::http::request& req, moost::http::reply& rep)
{
    //TODO: Handle % encodings
    
    log::info() << "HTTP " << req.method << " " << req.uri << " " << req.origin << endl;
    if( req.origin != "127.0.0.1" &&
        req.origin != "::1" && // not tested the ipv6 check
        req.origin != "0:0:0:0:0:0:0:1" && 
        req.uri.substr(0,5) != "/sid/" )
    {
        log::info() << "BLOCKED. Only localhost may access non /sid/ urls." << endl;
        rep.stock_reply(moost::http::reply::unauthorized);
        return;
    }
    
    boost::tokenizer<boost::char_separator<char> > tokenizer(req.uri, boost::char_separator<char>("/?"));
    string base;
    if( tokenizer.begin() != tokenizer.end())
        base = *tokenizer.begin();

    boost::to_lower(base);
    HandlerMap::iterator handler = m_urlHandlers.find( base );
    if( handler != m_urlHandlers.end())
    {
        handler->second( req, rep );
    }
    else
    {
        rep.stock_reply(moost::http::reply::not_found);
    } 
}
bool HostReflectionHost::BootUp::_handleMessage()
{
    if(!_deviceToHostQueue->peek())
    {
        return false;
    }

    report("  found message in gpu->cpu queue, pulling it...");

    Header header;

    _deviceToHostQueue->pull(&header, sizeof(Header));

    report("   type     " << header.type);
    report("   threadId " << header.threadId);
    report("   size     " << header.size);
    report("   handler  " << header.handler);

    HandlerMap::iterator handler = _handlers.find(header.handler);
    assert(handler != _handlers.end());

    if(header.type == Synchronous)
    {
        void* address = 0;
        _deviceToHostQueue->pull(&address, sizeof(void*));

        report("   synchronous ack to address: " << address);
        bool value = true;

        cudaMemcpyAsync(address, &value, sizeof(bool),
                        cudaMemcpyHostToDevice, 0);
        header.size -= sizeof(void*);
    }

    unsigned int size = header.size + sizeof(Header);

    Header* message = reinterpret_cast<Header*>(new char[size]);

    std::memcpy(message, &header, sizeof(Header));

    _deviceToHostQueue->pull(message + 1, header.size - sizeof(Header));

    report("   invoking message handler...");
    handler->second(*_hostToDeviceQueue, message);

    delete[] reinterpret_cast<char*>(message);

    return true;
}