From a3834a292510bc0eecb8980337a0a8ca71910623 Mon Sep 17 00:00:00 2001 From: Dragana Damjanovic Date: Mon, 20 Jan 2020 21:06:07 +0000 Subject: [PATCH] Bug 1608967 - Adapt necko to new neqo r=michal - process_timer used to be called by process_output, that is not the case any more, therefore we nee$ - how closing/closed event has change: on idle-timeout only closed even is called which means that neqo connection is completely closed and should not be kept alive. Differential Revision: https://phabricator.services.mozilla.com/D59801 --HG-- extra : moz-landing-system : lando --- netwerk/protocol/http/Http3Session.cpp | 27 ++++++++++++++++++------ netwerk/protocol/http/Http3Session.h | 1 + netwerk/socket/neqo_glue/NeqoHttp3Conn.h | 4 ++++ netwerk/socket/neqo_glue/src/lib.rs | 10 +++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/netwerk/protocol/http/Http3Session.cpp b/netwerk/protocol/http/Http3Session.cpp index 4888416d6a4a..dc342f0e30eb 100644 --- a/netwerk/protocol/http/Http3Session.cpp +++ b/netwerk/protocol/http/Http3Session.cpp @@ -59,6 +59,7 @@ Http3Session::Http3Session() mCleanShutdown(false), mGoawayReceived(false), mShouldClose(false), + mIsClosedByNeqo(false), mError(NS_OK), mBeforeConnectedError(false) { MOZ_ASSERT(OnSocketThread(), "not on socket thread"); @@ -331,8 +332,9 @@ nsresult Http3Session::ProcessEvents(uint32_t count, uint32_t* countWritten, if (NS_SUCCEEDED(mError) && !IsClosing()) { mError = NS_ERROR_NET_HTTP3_PROTOCOL_ERROR; } - CloseInternal(false); - mState = CLOSED; + mIsClosedByNeqo = true; + // We need to return here and let nsHttpConnection close the session. + return mError; break; default: break; @@ -430,6 +432,7 @@ nsresult Http3Session::ProcessOutput() { // This is only called when timer expires. nsresult Http3Session::ProcessOutputAndEvents() { MOZ_ASSERT(OnSocketThread(), "not on socket thread"); + mHttp3Connection->ProcessTimer(); nsresult rv = ProcessOutput(); if (NS_FAILED(rv)) { return rv; @@ -437,8 +440,8 @@ nsresult Http3Session::ProcessOutputAndEvents() { mHttp3Connection->ProcessHttp3(); bool notUsed; uint32_t n = 0; - Unused << ProcessEvents(nsIOService::gDefaultSegmentSize, &n, ¬Used); - if (mState == CLOSED) { + rv = ProcessEvents(nsIOService::gDefaultSegmentSize, &n, ¬Used); + if (NS_FAILED(rv)) { // Now we can remove all references and Http3Session will be destroyed. if (mTimer) { mTimer->Cancel(); @@ -446,6 +449,7 @@ nsresult Http3Session::ProcessOutputAndEvents() { mConnection = nullptr; mSocketTransport = nullptr; mSegmentReaderWriter = nullptr; + mState = CLOSED; } return NS_OK; } @@ -794,6 +798,14 @@ nsresult Http3Session::WriteSegmentsAgain(nsAHttpSegmentWriter* writer, if (NS_SUCCEEDED(rv)) { Unused << mConnection->ResumeRecv(); } + + uint64_t timeout = mHttp3Connection->ProcessOutput(); + + // Check if we have datagrams to send. If we have let's poll for writing. + if (mConnection && mHttp3Connection->HasDataToSend()) { + Unused << mConnection->ResumeSend(); + } + SetupTimer(timeout); return rv; } @@ -802,8 +814,10 @@ void Http3Session::Close(nsresult aReason) { mError = aReason; CloseInternal(true); - if (mCleanShutdown) { - // It is network-tear-down. We need to remove all references, so that + if (mCleanShutdown || mIsClosedByNeqo) { + // It is network-tear-down or neqo is state CLOSED(it does not need to send + // any more packets or wait for new packets). + // We need to remove all references, so that // Http3Session will be destroyed. if (mTimer) { mTimer->Cancel(); @@ -811,6 +825,7 @@ void Http3Session::Close(nsresult aReason) { mConnection = nullptr; mSocketTransport = nullptr; mSegmentReaderWriter = nullptr; + mState = CLOSED; } } diff --git a/netwerk/protocol/http/Http3Session.h b/netwerk/protocol/http/Http3Session.h index eaed24f34b68..6010511b5cc2 100644 --- a/netwerk/protocol/http/Http3Session.h +++ b/netwerk/protocol/http/Http3Session.h @@ -150,6 +150,7 @@ class Http3Session final : public nsAHttpTransaction, bool mCleanShutdown; bool mGoawayReceived; bool mShouldClose; + bool mIsClosedByNeqo; nsresult mError; bool mBeforeConnectedError; uint64_t mCurrentForegroundTabOuterContentWindowId; diff --git a/netwerk/socket/neqo_glue/NeqoHttp3Conn.h b/netwerk/socket/neqo_glue/NeqoHttp3Conn.h index 6aad24826397..5625411604d6 100644 --- a/netwerk/socket/neqo_glue/NeqoHttp3Conn.h +++ b/netwerk/socket/neqo_glue/NeqoHttp3Conn.h @@ -43,6 +43,10 @@ class NeqoHttp3Conn final { uint64_t ProcessOutput() { return neqo_http3conn_process_output(this); } + void ProcessTimer() { neqo_http3conn_process_timer(this); } + + bool HasDataToSend() { return neqo_http3conn_has_data_to_send(this); } + nsresult GetDataToSend(nsTArray& aData) { aData.TruncateLength(0); return neqo_http3conn_get_data_to_send(this, &aData); diff --git a/netwerk/socket/neqo_glue/src/lib.rs b/netwerk/socket/neqo_glue/src/lib.rs index c422c2a4583b..6435f829b505 100644 --- a/netwerk/socket/neqo_glue/src/lib.rs +++ b/netwerk/socket/neqo_glue/src/lib.rs @@ -180,6 +180,16 @@ pub extern "C" fn neqo_http3conn_process_output(conn: &mut NeqoHttp3Conn) -> u64 } } +#[no_mangle] +pub extern "C" fn neqo_http3conn_process_timer(conn: &mut NeqoHttp3Conn) { + conn.conn.process_timer(Instant::now()); +} + +#[no_mangle] +pub extern "C" fn neqo_http3conn_has_data_to_send(conn: &mut NeqoHttp3Conn) -> bool { + !conn.packets_to_send.is_empty() +} + #[no_mangle] pub extern "C" fn neqo_http3conn_get_data_to_send( conn: &mut NeqoHttp3Conn,