Skip to content

Commit 2001ab0

Browse files
committed
Bug 1852924 - When pacer returns a small delay, pretend to wait and get the next packet to send, r=mt
Differential Revision: https://phabricator.services.mozilla.com/D191325 UltraBlame original commit: f5d7c3a00f2bdc43070a0a547ddcd9027f3a2d02
1 parent 7716ea1 commit 2001ab0

File tree

9 files changed

+177
-103
lines changed

9 files changed

+177
-103
lines changed

dom/network/UDPSocketParent.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ void UDPSocketParent::Send(const nsTArray<uint8_t>& aData,
360360
}
361361
case UDPSocketAddr::TNetAddr: {
362362
const NetAddr& addr(aAddr.get_NetAddr());
363-
rv = mSocket->SendWithAddress(&addr, aData, &count);
363+
rv = mSocket->SendWithAddress(&addr, aData.Elements(), aData.Length(),
364+
&count);
364365
break;
365366
}
366367
default:

modules/libpref/init/StaticPrefList.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -12429,6 +12429,14 @@
1242912429
mirror: always
1243012430
rust: true
1243112431

12432+
# It represents the maximum duration that we used to accumulate
12433+
# callback timeouts before we set a timer and break out of the loop.
12434+
- name: network.http.http3.max_accumlated_time_ms
12435+
type: RelaxedAtomicUint32
12436+
value: 1
12437+
mirror: always
12438+
rust: true
12439+
1243212440
# When true, a http request will be upgraded to https when HTTPS RR is
1243312441
# available.
1243412442
- name: network.dns.upgrade_with_https_rr

netwerk/base/nsIUDPSocket.idl

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ interface nsIUDPSocket : nsISupports
194194
* @return number of bytes written. (0 or length of data)
195195
*/
196196
[noscript] unsigned long sendWithAddress([const] in NetAddrPtr addr,
197-
in Array<uint8_t> data);
197+
[array, size_is(length), const] in uint8_t data,
198+
in unsigned long length);
198199

199200
/**
200201
* sendBinaryStream

netwerk/base/nsUDPSocket.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,8 @@ PendingSend::OnLookupComplete(nsICancelable* request, nsIDNSRecord* aRecord,
10041004
NetAddr addr;
10051005
if (NS_SUCCEEDED(rec->GetNextAddr(mPort, &addr))) {
10061006
uint32_t count;
1007-
nsresult rv = mSocket->SendWithAddress(&addr, mData, &count);
1007+
nsresult rv = mSocket->SendWithAddress(&addr, mData.Elements(),
1008+
mData.Length(), &count);
10081009
NS_ENSURE_SUCCESS(rv, rv);
10091010
}
10101011

@@ -1069,7 +1070,7 @@ class SendRequestRunnable : public Runnable {
10691070
NS_IMETHODIMP
10701071
SendRequestRunnable::Run() {
10711072
uint32_t count;
1072-
mSocket->SendWithAddress(&mAddr, mData, &count);
1073+
mSocket->SendWithAddress(&mAddr, mData.Elements(), mData.Length(), &count);
10731074
return NS_OK;
10741075
}
10751076

@@ -1137,13 +1138,12 @@ nsUDPSocket::SendWithAddr(nsINetAddr* aAddr, const nsTArray<uint8_t>& aData,
11371138

11381139
NetAddr netAddr;
11391140
aAddr->GetNetAddr(&netAddr);
1140-
return SendWithAddress(&netAddr, aData, _retval);
1141+
return SendWithAddress(&netAddr, aData.Elements(), aData.Length(), _retval);
11411142
}
11421143

11431144
NS_IMETHODIMP
1144-
nsUDPSocket::SendWithAddress(const NetAddr* aAddr,
1145-
const nsTArray<uint8_t>& aData,
1146-
uint32_t* _retval) {
1145+
nsUDPSocket::SendWithAddress(const NetAddr* aAddr, const uint8_t* aData,
1146+
uint32_t aLength, uint32_t* _retval) {
11471147
NS_ENSURE_ARG(aAddr);
11481148
NS_ENSURE_ARG_POINTER(_retval);
11491149

@@ -1167,8 +1167,7 @@ nsUDPSocket::SendWithAddress(const NetAddr* aAddr,
11671167
return NS_ERROR_FAILURE;
11681168
}
11691169
int32_t count =
1170-
PR_SendTo(mFD, aData.Elements(), sizeof(uint8_t) * aData.Length(), 0,
1171-
&prAddr, PR_INTERVAL_NO_WAIT);
1170+
PR_SendTo(mFD, aData, aLength, 0, &prAddr, PR_INTERVAL_NO_WAIT);
11721171
if (count < 0) {
11731172
PRErrorCode code = PR_GetError();
11741173
return ErrorAccordingToNSPR(code);
@@ -1177,15 +1176,15 @@ nsUDPSocket::SendWithAddress(const NetAddr* aAddr,
11771176
*_retval = count;
11781177
} else {
11791178
FallibleTArray<uint8_t> fallibleArray;
1180-
if (!fallibleArray.InsertElementsAt(0, aData, fallible)) {
1179+
if (!fallibleArray.AppendElements(aData, aLength, fallible)) {
11811180
return NS_ERROR_OUT_OF_MEMORY;
11821181
}
11831182

11841183
nsresult rv = mSts->Dispatch(
11851184
new SendRequestRunnable(this, *aAddr, std::move(fallibleArray)),
11861185
NS_DISPATCH_NORMAL);
11871186
NS_ENSURE_SUCCESS(rv, rv);
1188-
*_retval = aData.Length();
1187+
*_retval = aLength;
11891188
}
11901189
return NS_OK;
11911190
}

netwerk/protocol/http/Http3Session.cpp

+53-43
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,18 @@ Http3Session::Http3Session() {
7171
mThroughCaptivePortal = gHttpHandler->GetThroughCaptivePortal();
7272
}
7373

74-
static nsresult StringAndPortToNetAddr(nsACString& remoteAddrStr,
75-
uint16_t remotePort, NetAddr* netAddr) {
76-
if (NS_FAILED(netAddr->InitFromString(remoteAddrStr, remotePort))) {
77-
return NS_ERROR_FAILURE;
74+
static nsresult RawBytesToNetAddr(uint16_t aFamily, const uint8_t* aRemoteAddr,
75+
uint16_t remotePort, NetAddr* netAddr) {
76+
if (aFamily == AF_INET) {
77+
netAddr->inet.family = AF_INET;
78+
netAddr->inet.port = htons(remotePort);
79+
memcpy(&netAddr->inet.ip, aRemoteAddr, 4);
80+
} else if (aFamily == AF_INET6) {
81+
netAddr->inet6.family = AF_INET6;
82+
netAddr->inet6.port = htons(remotePort);
83+
memcpy(&netAddr->inet6.ip.u8, aRemoteAddr, 16);
84+
} else {
85+
return NS_ERROR_UNEXPECTED;
7886
}
7987

8088
return NS_OK;
@@ -133,6 +141,7 @@ nsresult Http3Session::Init(const nsHttpConnectionInfo* aConnInfo,
133141
StaticPrefs::network_http_http3_max_stream_data(),
134142
StaticPrefs::network_http_http3_version_negotiation_enabled(),
135143
mConnInfo->GetWebTransport(), gHttpHandler->Http3QlogDir(), datagramSize,
144+
StaticPrefs::network_http_http3_max_accumlated_time_ms(),
136145
getter_AddRefs(mHttp3Connection));
137146
if (NS_FAILED(rv)) {
138147
return rv;
@@ -882,46 +891,46 @@ nsresult Http3Session::ProcessOutput(nsIUDPSocket* socket) {
882891
LOG(("Http3Session::ProcessOutput reader=%p, [this=%p]", mUdpConn.get(),
883892
this));
884893

885-
886-
887-
while (true) {
888-
nsTArray<uint8_t> packetToSend;
889-
nsAutoCString remoteAddrStr;
890-
uint16_t port = 0;
891-
uint64_t timeout = 0;
892-
if (!mHttp3Connection->ProcessOutput(&remoteAddrStr, &port, packetToSend,
893-
&timeout)) {
894-
SetupTimer(timeout);
895-
break;
896-
}
897-
MOZ_ASSERT(packetToSend.Length());
898-
LOG(
899-
("Http3Session::ProcessOutput sending packet with %u bytes to %s "
900-
"port=%d [this=%p].",
901-
(uint32_t)packetToSend.Length(),
902-
PromiseFlatCString(remoteAddrStr).get(), port, this));
903-
904-
uint32_t written = 0;
905-
NetAddr addr;
906-
if (NS_FAILED(StringAndPortToNetAddr(remoteAddrStr, port, &addr))) {
907-
continue;
908-
}
909-
nsresult rv = socket->SendWithAddress(&addr, packetToSend, &written);
894+
mSocket = socket;
895+
nsresult rv = mHttp3Connection->ProcessOutputAndSend(
896+
this,
897+
[](void* aContext, uint16_t aFamily, const uint8_t* aAddr, uint16_t aPort,
898+
const uint8_t* aData, uint32_t aLength) {
899+
Http3Session* self = (Http3Session*)aContext;
900+
901+
uint32_t written = 0;
902+
NetAddr addr;
903+
if (NS_FAILED(RawBytesToNetAddr(aFamily, aAddr, aPort, &addr))) {
904+
return NS_OK;
905+
}
910906

911-
LOG(("Http3Session::ProcessOutput sending packet rv=%d osError=%d",
912-
static_cast<int32_t>(rv), NS_FAILED(rv) ? PR_GetOSError() : 0));
913-
if (NS_FAILED(rv) && (rv != NS_BASE_STREAM_WOULD_BLOCK)) {
914-
mSocketError = rv;
915-
916-
917-
918-
return rv;
919-
}
920-
mTotalBytesWritten += packetToSend.Length();
921-
mLastWriteTime = PR_IntervalNow();
922-
}
907+
LOG3(
908+
("Http3Session::ProcessOutput sending packet with %u bytes to %s "
909+
"port=%d [this=%p].",
910+
aLength, addr.ToString().get(), aPort, self));
923911

924-
return NS_OK;
912+
nsresult rv =
913+
self->mSocket->SendWithAddress(&addr, aData, aLength, &written);
914+
915+
LOG(("Http3Session::ProcessOutput sending packet rv=%d osError=%d",
916+
static_cast<int32_t>(rv), NS_FAILED(rv) ? PR_GetOSError() : 0));
917+
if (NS_FAILED(rv) && (rv != NS_BASE_STREAM_WOULD_BLOCK)) {
918+
self->mSocketError = rv;
919+
920+
921+
922+
return rv;
923+
}
924+
self->mTotalBytesWritten += aLength;
925+
self->mLastWriteTime = PR_IntervalNow();
926+
return NS_OK;
927+
},
928+
[](void* aContext, uint64_t timeout) {
929+
Http3Session* self = (Http3Session*)aContext;
930+
self->SetupTimer(timeout);
931+
});
932+
mSocket = nullptr;
933+
return rv;
925934
}
926935

927936

@@ -955,7 +964,8 @@ void Http3Session::SetupTimer(uint64_t aTimeout) {
955964
return;
956965
}
957966

958-
LOG(("Http3Session::SetupTimer to %" PRIu64 "ms [this=%p].", aTimeout, this));
967+
LOG3(
968+
("Http3Session::SetupTimer to %" PRIu64 "ms [this=%p].", aTimeout, this));
959969

960970

961971
mTimerShouldTrigger =

netwerk/protocol/http/Http3Session.h

+4
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ class Http3Session final : public nsAHttpTransaction, public nsAHttpConnection {
375375
bool mHasWebTransportSession = false;
376376

377377
bool mDontExclude = false;
378+
379+
380+
381+
nsIUDPSocket* mSocket;
378382
};
379383

380384
NS_DEFINE_STATIC_IID_ACCESSOR(Http3Session, NS_HTTP3SESSION_IID);

netwerk/socket/neqo_glue/NeqoHttp3Conn.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class NeqoHttp3Conn final {
1919
uint64_t aMaxData, uint64_t aMaxStreamData,
2020
bool aVersionNegotiation, bool aWebTransport,
2121
const nsACString& aQlogDir, uint32_t aDatagramSize,
22-
NeqoHttp3Conn** aConn) {
23-
return neqo_http3conn_new(&aOrigin, &aAlpn, &aLocalAddr, &aRemoteAddr,
24-
aMaxTableSize, aMaxBlockedStreams, aMaxData,
25-
aMaxStreamData, aVersionNegotiation,
26-
aWebTransport, &aQlogDir, aDatagramSize,
27-
(const mozilla::net::NeqoHttp3Conn**)aConn);
22+
uint32_t aMaxAccumulatedTime, NeqoHttp3Conn** aConn) {
23+
return neqo_http3conn_new(
24+
&aOrigin, &aAlpn, &aLocalAddr, &aRemoteAddr, aMaxTableSize,
25+
aMaxBlockedStreams, aMaxData, aMaxStreamData, aVersionNegotiation,
26+
aWebTransport, &aQlogDir, aDatagramSize, aMaxAccumulatedTime,
27+
(const mozilla::net::NeqoHttp3Conn**)aConn);
2828
}
2929

3030
void Close(uint64_t aError) { neqo_http3conn_close(this, aError); }
@@ -46,11 +46,10 @@ class NeqoHttp3Conn final {
4646
return neqo_http3conn_process_input(this, &aRemoteAddr, &aPacket);
4747
}
4848

49-
bool ProcessOutput(nsACString* aRemoteAddr, uint16_t* aPort,
50-
nsTArray<uint8_t>& aData, uint64_t* aTimeout) {
51-
aData.TruncateLength(0);
52-
return neqo_http3conn_process_output(this, aRemoteAddr, aPort, &aData,
53-
aTimeout);
49+
nsresult ProcessOutputAndSend(void* aContext, SendFunc aSendFunc,
50+
SetTimerFunc aSetTimerFunc) {
51+
return neqo_http3conn_process_output_and_send(this, aContext, aSendFunc,
52+
aSetTimerFunc);
5453
}
5554

5655
nsresult GetEvent(Http3Event* aEvent, nsTArray<uint8_t>& aData) {

0 commit comments

Comments
 (0)