mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1915369 - track bytes sent and received when using quinn-udp r=necko-reviewers,valentin
An `nsIUDPSocket` tracks the number of bytes sent and received through its methods, e.g. `RecvWithAddr`. The number of bytes is then displayed in about:networking#sockets. With `network.http.http3.use_nspr_for_io` set to `false` `Http3Session` uses `quinn-udp` instead of `NSPR` for HTTP/3 QUIC UDP IO. Thus it does not use `nsIUDPSocket` `RecvWithAddr`, but instead optains a raw file descriptor via `nsIUDPSocket` `GetFileDescriptor` and then does its IO directly. Thereby the number of bytes sent and received in `nsIUDPSocket` are not updated, i.e. stay at `0`. This commit exposes two new methods in `nsIUDPSocket`, namely `addOutputBytes` and `addInputBytes` which are each called after any IO operation on the raw file descriptor optained through `nsIUDPSocket` `GetFileDescriptor`. Differential Revision: https://phabricator.services.mozilla.com/D220379
This commit is contained in:
parent
68e45cc38b
commit
4b478f1f10
@ -255,14 +255,38 @@ interface nsIUDPSocket : nsISupports
|
||||
[const, optional] in NetAddrPtr iface);
|
||||
|
||||
/**
|
||||
* getFileDescriptor
|
||||
*
|
||||
* Get the file descriptor of the socket.
|
||||
*
|
||||
* @return The file descriptor.
|
||||
*/
|
||||
* getFileDescriptor
|
||||
*
|
||||
* Get the file descriptor of the socket.
|
||||
*
|
||||
* @return The file descriptor.
|
||||
*/
|
||||
[noscript, notxpcom] int64_t getFileDescriptor();
|
||||
|
||||
/**
|
||||
* addOutputBytes
|
||||
*
|
||||
* Add number of bytes written to the socket. Used when sending data through
|
||||
* file descriptor optained from getFileDescriptor instead of nsIUDPSocket
|
||||
* methods.
|
||||
*
|
||||
* @param aBytes
|
||||
* The number of bytes written.
|
||||
*/
|
||||
[noscript, notxpcom] void addOutputBytes(in uint32_t aBytes);
|
||||
|
||||
/**
|
||||
* addInputBytes
|
||||
*
|
||||
* Add number of bytes read from the socket. Used when reading data through
|
||||
* file descriptor optained from getFileDescriptor instead of nsIUDPSocket
|
||||
* methods.
|
||||
*
|
||||
* @param aBytes
|
||||
* The number of bytes read.
|
||||
*/
|
||||
[noscript, notxpcom] void addInputBytes(in uint32_t aBytes);
|
||||
|
||||
/**
|
||||
* multicastLoopback
|
||||
*
|
||||
|
@ -257,11 +257,16 @@ nsUDPSocket::nsUDPSocket() {
|
||||
|
||||
nsUDPSocket::~nsUDPSocket() { CloseSocket(); }
|
||||
|
||||
void nsUDPSocket::AddOutputBytes(int32_t aBytes) {
|
||||
void nsUDPSocket::AddOutputBytes(uint32_t aBytes) {
|
||||
mByteWriteCount += aBytes;
|
||||
profiler_count_bandwidth_written_bytes(aBytes);
|
||||
}
|
||||
|
||||
void nsUDPSocket::AddInputBytes(uint32_t aBytes) {
|
||||
mByteReadCount += aBytes;
|
||||
profiler_count_bandwidth_read_bytes(aBytes);
|
||||
}
|
||||
|
||||
void nsUDPSocket::OnMsgClose() {
|
||||
UDPSOCKET_LOG(("nsUDPSocket::OnMsgClose [this=%p]\n", this));
|
||||
|
||||
@ -430,8 +435,7 @@ void nsUDPSocket::OnSocketReady(PRFileDesc* fd, int16_t outFlags) {
|
||||
("nsUDPSocket::OnSocketReady: PR_RecvFrom failed [this=%p]\n", this));
|
||||
return;
|
||||
}
|
||||
mByteReadCount += count;
|
||||
profiler_count_bandwidth_read_bytes(count);
|
||||
this->AddInputBytes(count);
|
||||
|
||||
FallibleTArray<uint8_t> data;
|
||||
if (!data.AppendElements(buff, count, fallible)) {
|
||||
@ -1238,8 +1242,8 @@ nsUDPSocket::RecvWithAddr(NetAddr* addr, nsTArray<uint8_t>& aData) {
|
||||
("nsUDPSocket::RecvWithAddr: PR_RecvFrom failed [this=%p]\n", this));
|
||||
return NS_OK;
|
||||
}
|
||||
mByteReadCount += count;
|
||||
profiler_count_bandwidth_read_bytes(count);
|
||||
|
||||
this->AddInputBytes(count);
|
||||
PRNetAddrToNetAddr(&prAddr, addr);
|
||||
|
||||
if (!aData.AppendElements(buff, count, fallible)) {
|
||||
|
@ -34,8 +34,6 @@ class nsUDPSocket final : public nsASocketHandler, public nsIUDPSocket {
|
||||
uint64_t ByteCountSent() override { return mByteWriteCount; }
|
||||
uint64_t ByteCountReceived() override { return mByteReadCount; }
|
||||
|
||||
void AddOutputBytes(int32_t aBytes);
|
||||
|
||||
nsUDPSocket();
|
||||
|
||||
private:
|
||||
|
@ -429,6 +429,7 @@ nsresult Http3Session::ProcessInput(nsIUDPSocket* socket) {
|
||||
return rv.result;
|
||||
}
|
||||
mTotalBytesRead += rv.bytes_read;
|
||||
socket->AddInputBytes(rv.bytes_read);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -982,6 +983,7 @@ nsresult Http3Session::ProcessOutput(nsIUDPSocket* socket) {
|
||||
if (rv.bytes_written != 0) {
|
||||
mTotalBytesWritten += rv.bytes_written;
|
||||
mLastWriteTime = PR_IntervalNow();
|
||||
socket->AddOutputBytes(rv.bytes_written);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user