CCF
Loading...
Searching...
No Matches
responder_lookup.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/odata_error.h"
6#include "ccf/pal/locking.h"
7#include "http2_types.h"
8
9#include <unordered_map>
10
11namespace http
12{
14 {
15 protected:
16 using ByStream = std::
17 unordered_map<http2::StreamId, std::shared_ptr<ccf::http::HTTPResponder>>;
18
19 std::unordered_map<::tcp::ConnID, ByStream> all_responders;
20
21 // Responder lookup is shared by all HTTP sessions
23
24 public:
25 std::shared_ptr<ccf::http::HTTPResponder> lookup_responder(
26 ::tcp::ConnID session_id, http2::StreamId stream_id)
27 {
28 std::unique_lock<ccf::pal::Mutex> guard(lock);
29 auto conn_it = all_responders.find(session_id);
30 if (conn_it != all_responders.end())
31 {
32 auto& by_stream = conn_it->second;
33 auto stream_it = by_stream.find(stream_id);
34 if (stream_it != by_stream.end())
35 {
36 return stream_it->second;
37 }
38 }
39
40 return nullptr;
41 }
42
44 ::tcp::ConnID session_id,
45 http2::StreamId stream_id,
46 std::shared_ptr<ccf::http::HTTPResponder> responder)
47 {
48 std::unique_lock<ccf::pal::Mutex> guard(lock);
49 all_responders[session_id][stream_id] = responder;
50 }
51
53 {
54 std::unique_lock<ccf::pal::Mutex> guard(lock);
55 all_responders.erase(session_id);
56 }
57 };
58}
Definition responder_lookup.h:14
ccf::pal::Mutex lock
Definition responder_lookup.h:22
void cleanup_responders(::tcp::ConnID session_id)
Definition responder_lookup.h:52
std::unordered_map<::tcp::ConnID, ByStream > all_responders
Definition responder_lookup.h:19
std::shared_ptr< ccf::http::HTTPResponder > lookup_responder(::tcp::ConnID session_id, http2::StreamId stream_id)
Definition responder_lookup.h:25
void add_responder(::tcp::ConnID session_id, http2::StreamId stream_id, std::shared_ptr< ccf::http::HTTPResponder > responder)
Definition responder_lookup.h:43
std::unordered_map< http2::StreamId, std::shared_ptr< ccf::http::HTTPResponder > > ByStream
Definition responder_lookup.h:17
std::mutex Mutex
Definition locking.h:12
int32_t StreamId
Definition http2_types.h:21
Definition error_reporter.h:6
int64_t ConnID
Definition msg_types.h:9