1 #include "quiche/http2/adapter/nghttp2_session.h"
2
3 #include "quiche/common/platform/api/quiche_logging.h"
4
5 namespace http2 {
6 namespace adapter {
7
NgHttp2Session(Perspective perspective,nghttp2_session_callbacks_unique_ptr callbacks,const nghttp2_option * options,void * userdata)8 NgHttp2Session::NgHttp2Session(Perspective perspective,
9 nghttp2_session_callbacks_unique_ptr callbacks,
10 const nghttp2_option* options, void* userdata)
11 : session_(MakeSessionPtr(nullptr)), perspective_(perspective) {
12 nghttp2_session* session;
13 switch (perspective_) {
14 case Perspective::kClient:
15 nghttp2_session_client_new2(&session, callbacks.get(), userdata, options);
16 break;
17 case Perspective::kServer:
18 nghttp2_session_server_new2(&session, callbacks.get(), userdata, options);
19 break;
20 }
21 session_ = MakeSessionPtr(session);
22 }
23
~NgHttp2Session()24 NgHttp2Session::~NgHttp2Session() {
25 // Can't invoke want_read() or want_write(), as they are virtual methods.
26 const bool pending_reads = nghttp2_session_want_read(session_.get()) != 0;
27 const bool pending_writes = nghttp2_session_want_write(session_.get()) != 0;
28 if (pending_reads || pending_writes) {
29 QUICHE_VLOG(1) << "Shutting down connection with pending reads: "
30 << pending_reads << " or pending writes: " << pending_writes;
31 }
32 }
33
ProcessBytes(absl::string_view bytes)34 int64_t NgHttp2Session::ProcessBytes(absl::string_view bytes) {
35 return nghttp2_session_mem_recv(
36 session_.get(), reinterpret_cast<const uint8_t*>(bytes.data()),
37 bytes.size());
38 }
39
Consume(Http2StreamId stream_id,size_t num_bytes)40 int NgHttp2Session::Consume(Http2StreamId stream_id, size_t num_bytes) {
41 return nghttp2_session_consume(session_.get(), stream_id, num_bytes);
42 }
43
want_read() const44 bool NgHttp2Session::want_read() const {
45 return nghttp2_session_want_read(session_.get()) != 0;
46 }
47
want_write() const48 bool NgHttp2Session::want_write() const {
49 return nghttp2_session_want_write(session_.get()) != 0;
50 }
51
GetRemoteWindowSize() const52 int NgHttp2Session::GetRemoteWindowSize() const {
53 return nghttp2_session_get_remote_window_size(session_.get());
54 }
55
56 } // namespace adapter
57 } // namespace http2
58