@@ -1888,28 +1888,6 @@ inline int Http2Stream::SubmitResponse(nghttp2_nv* nva,
1888
1888
}
1889
1889
1890
1890
1891
- // Initiate a response that contains data read from a file descriptor.
1892
- inline int Http2Stream::SubmitFile (int fd,
1893
- nghttp2_nv* nva, size_t len,
1894
- int64_t offset,
1895
- int64_t length,
1896
- int options) {
1897
- CHECK (!this ->IsDestroyed ());
1898
- Http2Scope h2scope (this );
1899
- DEBUG_HTTP2STREAM (this , " submitting file" );
1900
- if (options & STREAM_OPTION_GET_TRAILERS)
1901
- flags_ |= NGHTTP2_STREAM_FLAG_TRAILERS;
1902
-
1903
- if (offset > 0 ) fd_offset_ = offset;
1904
- if (length > -1 ) fd_length_ = length;
1905
-
1906
- Http2Stream::Provider::FD prov (this , options, fd);
1907
- int ret = nghttp2_submit_response (session_->session (), id_, nva, len, *prov);
1908
- CHECK_NE (ret, NGHTTP2_ERR_NOMEM);
1909
- return ret;
1910
- }
1911
-
1912
-
1913
1891
// Submit informational headers for a stream.
1914
1892
inline int Http2Stream::SubmitInfo (nghttp2_nv* nva, size_t len) {
1915
1893
CHECK (!this ->IsDestroyed ());
@@ -2085,87 +2063,6 @@ Http2Stream::Provider::~Provider() {
2085
2063
provider_.source .ptr = nullptr ;
2086
2064
}
2087
2065
2088
- // The FD Provider pulls data from a file descriptor using libuv. All of the
2089
- // data transfer occurs in C++, without any chunks being passed through JS
2090
- // land.
2091
- Http2Stream::Provider::FD::FD (Http2Stream* stream, int options, int fd)
2092
- : Http2Stream::Provider(stream, options) {
2093
- CHECK (!stream->IsDestroyed ());
2094
- provider_.source .fd = fd;
2095
- provider_.read_callback = Http2Stream::Provider::FD::OnRead;
2096
- }
2097
-
2098
- Http2Stream::Provider::FD::FD (int options, int fd)
2099
- : Http2Stream::Provider(options) {
2100
- provider_.source .fd = fd;
2101
- provider_.read_callback = Http2Stream::Provider::FD::OnRead;
2102
- }
2103
-
2104
- ssize_t Http2Stream::Provider::FD::OnRead (nghttp2_session* handle,
2105
- int32_t id,
2106
- uint8_t * buf,
2107
- size_t length,
2108
- uint32_t * flags,
2109
- nghttp2_data_source* source,
2110
- void * user_data) {
2111
- Http2Session* session = static_cast <Http2Session*>(user_data);
2112
- Http2Stream* stream = session->FindStream (id);
2113
- if (stream->statistics_ .first_byte_sent == 0 )
2114
- stream->statistics_ .first_byte_sent = uv_hrtime ();
2115
-
2116
- DEBUG_HTTP2SESSION2 (session, " reading outbound file data for stream %d" , id);
2117
- CHECK_EQ (id, stream->id ());
2118
-
2119
- int fd = source->fd ;
2120
- int64_t offset = stream->fd_offset_ ;
2121
- ssize_t numchars = 0 ;
2122
-
2123
- if (stream->fd_length_ >= 0 &&
2124
- stream->fd_length_ < static_cast <int64_t >(length))
2125
- length = stream->fd_length_ ;
2126
-
2127
- uv_buf_t data;
2128
- data.base = reinterpret_cast <char *>(buf);
2129
- data.len = length;
2130
-
2131
- uv_fs_t read_req;
2132
-
2133
- if (length > 0 ) {
2134
- // TODO(addaleax): Never use synchronous I/O on the main thread.
2135
- numchars = uv_fs_read (session->event_loop (),
2136
- &read_req,
2137
- fd, &data, 1 ,
2138
- offset, nullptr );
2139
- uv_fs_req_cleanup (&read_req);
2140
- }
2141
-
2142
- // Close the stream with an error if reading fails
2143
- if (numchars < 0 )
2144
- return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
2145
-
2146
- // Update the read offset for the next read
2147
- stream->fd_offset_ += numchars;
2148
- stream->fd_length_ -= numchars;
2149
-
2150
- DEBUG_HTTP2SESSION2 (session, " sending %d bytes" , numchars);
2151
-
2152
- // if numchars < length, assume that we are done.
2153
- if (static_cast <size_t >(numchars) < length || length <= 0 ) {
2154
- DEBUG_HTTP2SESSION2 (session, " no more data for stream %d" , id);
2155
- *flags |= NGHTTP2_DATA_FLAG_EOF;
2156
- session->GetTrailers (stream, flags);
2157
- // If the stream or session gets destroyed during the GetTrailers
2158
- // callback, check that here and close down the stream
2159
- if (stream->IsDestroyed ())
2160
- return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
2161
- if (session->IsDestroyed ())
2162
- return NGHTTP2_ERR_CALLBACK_FAILURE;
2163
- }
2164
-
2165
- stream->statistics_ .sent_bytes += numchars;
2166
- return numchars;
2167
- }
2168
-
2169
2066
// The Stream Provider pulls data from a linked list of uv_buf_t structs
2170
2067
// built via the StreamBase API and the Streams js API.
2171
2068
Http2Stream::Provider::Stream::Stream (int options)
@@ -2508,27 +2405,6 @@ void Http2Stream::Respond(const FunctionCallbackInfo<Value>& args) {
2508
2405
DEBUG_HTTP2STREAM (stream, " response submitted" );
2509
2406
}
2510
2407
2511
- // Initiates a response on the Http2Stream using a file descriptor to provide
2512
- // outbound DATA frames.
2513
- void Http2Stream::RespondFD (const FunctionCallbackInfo<Value>& args) {
2514
- Environment* env = Environment::GetCurrent (args);
2515
- Local<Context> context = env->context ();
2516
- Isolate* isolate = env->isolate ();
2517
- Http2Stream* stream;
2518
- ASSIGN_OR_RETURN_UNWRAP (&stream, args.Holder ());
2519
-
2520
- int fd = args[0 ]->Int32Value (context).ToChecked ();
2521
- Local<Array> headers = args[1 ].As <Array>();
2522
-
2523
- int64_t offset = args[2 ]->IntegerValue (context).ToChecked ();
2524
- int64_t length = args[3 ]->IntegerValue (context).ToChecked ();
2525
- int options = args[4 ]->IntegerValue (context).ToChecked ();
2526
-
2527
- Headers list (isolate, context, headers);
2528
- args.GetReturnValue ().Set (stream->SubmitFile (fd, *list, list.length (),
2529
- offset, length, options));
2530
- DEBUG_HTTP2STREAM2 (stream, " file response submitted for fd %d" , fd);
2531
- }
2532
2408
2533
2409
// Submits informational headers on the Http2Stream
2534
2410
void Http2Stream::Info (const FunctionCallbackInfo<Value>& args) {
@@ -2891,7 +2767,6 @@ void Initialize(Local<Object> target,
2891
2767
env->SetProtoMethod (stream, " priority" , Http2Stream::Priority);
2892
2768
env->SetProtoMethod (stream, " pushPromise" , Http2Stream::PushPromise);
2893
2769
env->SetProtoMethod (stream, " info" , Http2Stream::Info);
2894
- env->SetProtoMethod (stream, " respondFD" , Http2Stream::RespondFD);
2895
2770
env->SetProtoMethod (stream, " respond" , Http2Stream::Respond);
2896
2771
env->SetProtoMethod (stream, " rstStream" , Http2Stream::RstStream);
2897
2772
env->SetProtoMethod (stream, " refreshState" , Http2Stream::RefreshState);
0 commit comments