@@ -1369,30 +1369,6 @@ inline void Http2Stream::AddChunk(const uint8_t* data, size_t len) {
1369
1369
data_chunks_.emplace (uv_buf_init (buf, len));
1370
1370
}
1371
1371
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
-
1396
1372
1397
1373
inline void Http2Stream::Close (int32_t code) {
1398
1374
CHECK (!this ->IsDestroyed ());
@@ -1447,7 +1423,7 @@ inline void Http2Stream::Destroy() {
1447
1423
// we still have qeueued outbound writes.
1448
1424
while (!stream->queue_ .empty ()) {
1449
1425
nghttp2_stream_write* head = stream->queue_ .front ();
1450
- head->cb (head-> req , UV_ECANCELED);
1426
+ head->req_wrap -> Done ( UV_ECANCELED);
1451
1427
delete head;
1452
1428
stream->queue_ .pop ();
1453
1429
}
@@ -1616,26 +1592,32 @@ inline int Http2Stream::ReadStop() {
1616
1592
return 0 ;
1617
1593
}
1618
1594
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
+ //
1619
1600
// 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.
1622
1603
// Note that this does *not* mean that the data has been flushed
1623
1604
// 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 ) {
1628
1609
CHECK (!this ->IsDestroyed ());
1610
+ CHECK_EQ (send_handle, nullptr );
1629
1611
Http2Scope h2scope (this );
1612
+ session_->SetChunksSinceLastWrite ();
1613
+ req_wrap->Dispatched ();
1630
1614
if (!IsWritable ()) {
1631
- if (cb != nullptr )
1632
- cb (req, UV_EOF);
1615
+ req_wrap->Done (UV_EOF);
1633
1616
return 0 ;
1634
1617
}
1635
1618
DEBUG_HTTP2STREAM2 (this , " queuing %d buffers to send" , id_, nbufs);
1636
1619
nghttp2_stream_write* item = new nghttp2_stream_write;
1637
- item->cb = cb;
1638
- item->req = req;
1620
+ item->req_wrap = req_wrap;
1639
1621
item->nbufs = nbufs;
1640
1622
item->bufs .AllocateSufficientStorage (nbufs);
1641
1623
memcpy (*(item->bufs ), bufs, nbufs * sizeof (*bufs));
@@ -1824,7 +1806,7 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle,
1824
1806
stream->queue_offset_ = 0 ;
1825
1807
}
1826
1808
if (stream->queue_index_ == head->nbufs ) {
1827
- head->cb (head-> req , 0 );
1809
+ head->req_wrap -> Done ( 0 );
1828
1810
delete head;
1829
1811
stream->queue_ .pop ();
1830
1812
stream->queue_offset_ = 0 ;
0 commit comments