Skip to content

Commit

Permalink
Initial ReadMulti plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Oct 28, 2024
1 parent 38e817e commit 1d67b6e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 4 deletions.
22 changes: 18 additions & 4 deletions net/quic/quic_chromium_packet_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const size_t kReadBufferSize =
static_cast<size_t>(quic::kMaxIncomingPacketSize + 1);
} // namespace

bool QuicChromiumPacketReader::avoid_read_multi_ = false;

QuicChromiumPacketReader::QuicChromiumPacketReader(
DatagramClientSocket* socket,
const quic::QuicClock* clock,
Expand Down Expand Up @@ -49,10 +51,22 @@ void QuicChromiumPacketReader::StartReading() {

CHECK(socket_);
read_pending_ = true;
int rv =
socket_->Read(read_buffer_.get(), read_buffer_->size(),
base::BindOnce(&QuicChromiumPacketReader::OnReadComplete,
weak_factory_.GetWeakPtr()));
int rv = OK;
if (!avoid_read_multi_) {
rv = socket_->ReadMulti(
read_buffer_.get(), read_buffer_->size(),
base::BindOnce(&QuicChromiumPacketReader::OnReadComplete,
weak_factory_.GetWeakPtr()));
if (rv == ERR_NOT_IMPLEMENTED)
avoid_read_multi_ = true;
}
if (avoid_read_multi_) {
rv = socket_->Read(
read_buffer_.get(), read_buffer_->size(),
base::BindOnce(&QuicChromiumPacketReader::OnReadComplete,
weak_factory_.GetWeakPtr()));
}

UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.AsyncRead", rv == ERR_IO_PENDING);
if (rv == ERR_IO_PENDING) {
num_packets_read_ = 0;
Expand Down
4 changes: 4 additions & 0 deletions net/quic/quic_chromium_packet_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class NET_EXPORT_PRIVATE QuicChromiumPacketReader {
NetLogWithSource net_log_;

base::WeakPtrFactory<QuicChromiumPacketReader> weak_factory_{this};

// Static flag to remember when ReadMulti has ever returned
// ERR_NOT_IMPLEMENTED
static bool avoid_read_multi_;
};

} // namespace net
Expand Down
6 changes: 6 additions & 0 deletions net/socket/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Socket::Socket() = default;

Socket::~Socket() = default;

int Socket::ReadMulti(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
return ERR_NOT_IMPLEMENTED;
}

int Socket::ReadIfReady(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
Expand Down
3 changes: 3 additions & 0 deletions net/socket/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class NET_EXPORT Socket {
virtual int Read(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) = 0;
virtual int ReadMulti(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback);

// Reads data, up to |buf_len| bytes, into |buf| without blocking. Default
// implementation returns ERR_READ_IF_READY_NOT_IMPLEMENTED. Caller should
Expand Down
6 changes: 6 additions & 0 deletions net/socket/udp_client_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ void UDPClientSocket::ApplySocketTag(const SocketTag& tag) {
socket_.ApplySocketTag(tag);
}

int UDPClientSocket::ReadMulti(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
return socket_.ReadMulti(buf, buf_len, std::move(callback));
}

int UDPClientSocket::Read(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
Expand Down
4 changes: 4 additions & 0 deletions net/socket/udp_client_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket {
int Read(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) override;
int ReadMulti(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) override;

int Write(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback,
Expand Down
7 changes: 7 additions & 0 deletions net/socket/udp_socket_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ int UDPSocketStarboard::GetLocalAddress(IPEndPoint* address) const {
return OK;
}

int UDPSocketStarboard::ReadMulti(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
LOG(WARNING) << __FUNCTION__ << " ReadMulti not implemented";
return ERR_NOT_IMPLEMENTED;
}

int UDPSocketStarboard::Read(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) {
Expand Down
1 change: 1 addition & 0 deletions net/socket/udp_socket_starboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class NET_EXPORT UDPSocketStarboard
// Reads from the socket.
// Only usable from the client-side of a UDP socket, after the socket
// has been connected.
int ReadMulti(IOBuffer* buf, int buf_len, CompletionOnceCallback callback);
int Read(IOBuffer* buf, int buf_len, CompletionOnceCallback callback);

// Writes to the socket.
Expand Down

0 comments on commit 1d67b6e

Please sign in to comment.