1+ #include " ngtcp2/ngtcp2.h"
12#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
23
34#include " application.h"
@@ -95,6 +96,20 @@ Maybe<Session::Application_Options> Session::Application_Options::From(
9596 return Just<Application_Options>(options);
9697}
9798
99+ // ============================================================================
100+
101+ std::string Session::Application::StreamData::ToString () const {
102+ DebugIndentScope indent;
103+ auto prefix = indent.Prefix ();
104+ std::string res (" {" );
105+ res += prefix + " count: " + std::to_string (count);
106+ res += prefix + " remaining: " + std::to_string (remaining);
107+ res += prefix + " id: " + std::to_string (id);
108+ res += prefix + " fin: " + std::to_string (fin);
109+ res += indent.Close ();
110+ return res;
111+ }
112+
98113Session::Application::Application (Session* session, const Options& options)
99114 : session_(session) {}
100115
@@ -251,13 +266,15 @@ void Session::Application::SendPendingData() {
251266 };
252267
253268 for (;;) {
254- ssize_t ndatalen;
269+ ssize_t ndatalen = 0 ;
255270 StreamData stream_data;
256271
257272 err = GetStreamData (&stream_data);
258273
259274 if (err < 0 ) {
260275 session_->last_error_ = QuicError::ForNgtcp2Error (NGTCP2_ERR_INTERNAL);
276+ Debug (session_, " Application failed to get stream data with error %s" ,
277+ session_->last_error_ );
261278 return session_->Close (Session::CloseMethod::SILENT);
262279 }
263280
@@ -270,13 +287,19 @@ void Session::Application::SendPendingData() {
270287 pos = ngtcp2_vec (*packet).base ;
271288 }
272289
290+ Debug (session_, " Application using stream data: %s" , stream_data);
291+ DCHECK_NOT_NULL (pos);
292+ DCHECK_NOT_NULL (stream_data.buf );
273293 ssize_t nwrite = WriteVStream (&path, pos, &ndatalen, stream_data);
294+ Debug (session_, " Application accepted %zu bytes" , ndatalen);
274295
275296 if (nwrite <= 0 ) {
276297 switch (nwrite) {
277- case 0 :
298+ case 0 : {
299+ Debug (session_, " Congestion limited. Sending nothing." );
278300 if (stream_data.id >= 0 ) ResumeStream (stream_data.id );
279301 return congestionLimited (std::move (packet));
302+ }
280303 case NGTCP2_ERR_STREAM_DATA_BLOCKED: {
281304 session ().StreamDataBlocked (stream_data.id );
282305 if (session ().max_data_left () == 0 ) {
@@ -287,6 +310,8 @@ void Session::Application::SendPendingData() {
287310 continue ;
288311 }
289312 case NGTCP2_ERR_STREAM_SHUT_WR: {
313+ Debug (session_, " Stream %" PRIi64 " is closed for writing" ,
314+ stream_data.id );
290315 // Indicates that the writable side of the stream has been closed
291316 // locally or the stream is being reset. In either case, we can't send
292317 // any stream data!
@@ -299,6 +324,7 @@ void Session::Application::SendPendingData() {
299324 continue ;
300325 }
301326 case NGTCP2_ERR_WRITE_MORE: {
327+ Debug (session_, " Application should write more to packet" );
302328 CHECK_GT (ndatalen, 0 );
303329 if (!StreamCommit (&stream_data, ndatalen)) return session_->Close ();
304330 pos += ndatalen;
@@ -308,6 +334,8 @@ void Session::Application::SendPendingData() {
308334
309335 packet->Done (UV_ECANCELED);
310336 session_->last_error_ = QuicError::ForNgtcp2Error (nwrite);
337+ Debug (session_, " Application failed to write stream data with error %s" ,
338+ session_->last_error_ );
311339 return session_->Close (Session::CloseMethod::SILENT);
312340 }
313341
@@ -322,9 +350,10 @@ void Session::Application::SendPendingData() {
322350
323351 if (stream_data.id >= 0 && ndatalen < 0 ) ResumeStream (stream_data.id );
324352
353+ Debug (session_, " Packet ready to send with %zu bytes" , nwrite);
325354 packet->Truncate (nwrite);
326- session_->Send (std::move ( packet) , path);
327-
355+ session_->Send (packet, path);
356+ packet = nullptr ;
328357 pos = nullptr ;
329358
330359 if (++packetSendCount == maxPacketCount) {
@@ -343,10 +372,12 @@ ssize_t Session::Application::WriteVStream(PathStorage* path,
343372 uint32_t flags = NGTCP2_WRITE_STREAM_FLAG_NONE;
344373 if (stream_data.remaining > 0 ) flags |= NGTCP2_WRITE_STREAM_FLAG_MORE;
345374 if (stream_data.fin ) flags |= NGTCP2_WRITE_STREAM_FLAG_FIN;
375+ ngtcp2_pkt_info pi;
376+
346377 ssize_t ret = ngtcp2_conn_writev_stream (
347378 *session_,
348379 &path->path ,
349- nullptr ,
380+ &pi ,
350381 buf,
351382 ngtcp2_conn_get_max_tx_udp_payload_size (*session_),
352383 ndatalen,
0 commit comments