diff --git a/netwerk/base/nsIUDPSocket.idl b/netwerk/base/nsIUDPSocket.idl index d9c120a073ef..b75e0d652d78 100644 --- a/netwerk/base/nsIUDPSocket.idl +++ b/netwerk/base/nsIUDPSocket.idl @@ -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 * diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 3e3c09674a34..43a1ea658086 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -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 data; if (!data.AppendElements(buff, count, fallible)) { @@ -1238,8 +1242,8 @@ nsUDPSocket::RecvWithAddr(NetAddr* addr, nsTArray& 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)) { diff --git a/netwerk/base/nsUDPSocket.h b/netwerk/base/nsUDPSocket.h index bd616d52069a..d58d1750a76a 100644 --- a/netwerk/base/nsUDPSocket.h +++ b/netwerk/base/nsUDPSocket.h @@ -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: diff --git a/netwerk/protocol/http/Http3Session.cpp b/netwerk/protocol/http/Http3Session.cpp index e6f23ff4f91c..ac426f746846 100644 --- a/netwerk/protocol/http/Http3Session.cpp +++ b/netwerk/protocol/http/Http3Session.cpp @@ -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;