예제 #1
0
void HttpServer::destroy(ConnectionPtr connection, bool release)
{
    connection->markToBeDeleted();

    {
        std::lock_guard<std::mutex> lock(connections_mutex_);
        auto it = std::find_if(std::begin(connections_),
                               std::end(connections_),
                               [&](ConnectionPtr conn)
                               { return connection == conn; });
        if (it == std::end(connections_))
        {
            return;
        }
        else
        {
            --connection_count_;
            connections_.erase(it);
        }
    }

    if (release)
    {
        connection->disown();
        HTTP::Connection::release(connection);
    }
}
예제 #2
0
void HttpServer::connection_notify_request(ConnectionPtr connection,
                                           HTTP::Request&& request)
{
    if (sink_)
    {
        connection->disown();
        sink_(connection, std::forward<HTTP::Request>(request));
    }
    else
    {
        connection->response().setCode(HTTP::HttpCode::NoContent).setBody("");
        HTTP::setShouldConnectionBeClosed(request, connection->response());
        connection->sendResponse();
    }
}