@@ -1369,30 +1369,6 @@ inline void Http2Stream::AddChunk(const uint8_t* data, size_t len) {
13691369 data_chunks_.emplace (uv_buf_init (buf, len));
13701370}
13711371
1372- // The Http2Stream class is a subclass of StreamBase. The DoWrite method
1373- // receives outbound chunks of data to send as outbound DATA frames. These
1374- // are queued in an internal linked list of uv_buf_t structs that are sent
1375- // when nghttp2 is ready to serialize the data frame.
1376- int Http2Stream::DoWrite (WriteWrap* req_wrap,
1377- uv_buf_t * bufs,
1378- size_t count,
1379- uv_stream_t * send_handle) {
1380- CHECK (!this ->IsDestroyed ());
1381- session_->SetChunksSinceLastWrite ();
1382-
1383- nghttp2_stream_write_t * req = new nghttp2_stream_write_t ;
1384- req->data = req_wrap;
1385-
1386- auto AfterWrite = [](nghttp2_stream_write_t * req, int status) {
1387- WriteWrap* wrap = static_cast <WriteWrap*>(req->data );
1388- wrap->Done (status);
1389- delete req;
1390- };
1391- req_wrap->Dispatched ();
1392- Write (req, bufs, count, AfterWrite);
1393- return 0 ;
1394- }
1395-
13961372
13971373inline void Http2Stream::Close (int32_t code) {
13981374 CHECK (!this ->IsDestroyed ());
@@ -1447,7 +1423,7 @@ inline void Http2Stream::Destroy() {
14471423 // we still have qeueued outbound writes.
14481424 while (!stream->queue_ .empty ()) {
14491425 nghttp2_stream_write* head = stream->queue_ .front ();
1450- head->cb (head-> req , UV_ECANCELED);
1426+ head->req_wrap -> Done ( UV_ECANCELED);
14511427 delete head;
14521428 stream->queue_ .pop ();
14531429 }
@@ -1616,26 +1592,32 @@ inline int Http2Stream::ReadStop() {
16161592 return 0 ;
16171593}
16181594
1595+ // The Http2Stream class is a subclass of StreamBase. The DoWrite method
1596+ // receives outbound chunks of data to send as outbound DATA frames. These
1597+ // are queued in an internal linked list of uv_buf_t structs that are sent
1598+ // when nghttp2 is ready to serialize the data frame.
1599+ //
16191600// Queue the given set of uv_but_t handles for writing to an
1620- // nghttp2_stream. The callback will be invoked once the chunks
1621- // of data have been flushed to the underlying nghttp2_session.
1601+ // nghttp2_stream. The WriteWrap's Done callback will be invoked once the
1602+ // chunks of data have been flushed to the underlying nghttp2_session.
16221603// Note that this does *not* mean that the data has been flushed
16231604// to the socket yet.
1624- inline int Http2Stream::Write ( nghttp2_stream_write_t * req ,
1625- const uv_buf_t bufs[] ,
1626- unsigned int nbufs,
1627- nghttp2_stream_write_cb cb ) {
1605+ inline int Http2Stream::DoWrite (WriteWrap* req_wrap ,
1606+ uv_buf_t * bufs,
1607+ size_t nbufs,
1608+ uv_stream_t * send_handle ) {
16281609 CHECK (!this ->IsDestroyed ());
1610+ CHECK_EQ (send_handle, nullptr );
16291611 Http2Scope h2scope (this );
1612+ session_->SetChunksSinceLastWrite ();
1613+ req_wrap->Dispatched ();
16301614 if (!IsWritable ()) {
1631- if (cb != nullptr )
1632- cb (req, UV_EOF);
1615+ req_wrap->Done (UV_EOF);
16331616 return 0 ;
16341617 }
16351618 DEBUG_HTTP2STREAM2 (this , " queuing %d buffers to send" , id_, nbufs);
16361619 nghttp2_stream_write* item = new nghttp2_stream_write;
1637- item->cb = cb;
1638- item->req = req;
1620+ item->req_wrap = req_wrap;
16391621 item->nbufs = nbufs;
16401622 item->bufs .AllocateSufficientStorage (nbufs);
16411623 memcpy (*(item->bufs ), bufs, nbufs * sizeof (*bufs));
@@ -1824,7 +1806,7 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,
18241806 stream->queue_offset_ = 0 ;
18251807 }
18261808 if (stream->queue_index_ == head->nbufs ) {
1827- head->cb (head-> req , 0 );
1809+ head->req_wrap -> Done ( 0 );
18281810 delete head;
18291811 stream->queue_ .pop ();
18301812 stream->queue_offset_ = 0 ;
0 commit comments