Remove unnecessary WriteAll call when sending DTLS packets

As discussed recently, DTLS encryption won't split writes over records -
in fact the |next_packet_options_| depends on that. As such, we can
remove the |WriteAll()| helper and just CHECK that a single |Write()|
call either sends the entire data buffer, or fails it all.

Bug: None
Change-Id: I98ab169d26f89ce4f13b624f804b8b61689f2ddc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/421680
Auto-Submit: Tony Herre <herre@google.com>
Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#46099}
This commit is contained in:
Tony Herre 2025-10-30 08:21:28 +01:00 committed by WebRTC LUCI CQ
parent 76dba7e516
commit bec6948036
3 changed files with 5 additions and 36 deletions

View File

@ -591,7 +591,7 @@ int DtlsTransportInternalImpl::SendPacket(
// an encrypted packet, rather than calling the
// StreamInterfaceChannel::Write function. Such change would remove the
// need of the next_packet_options_.
StreamResult result = dtls_->WriteAll(
StreamResult result = dtls_->Write(
MakeArrayView(reinterpret_cast<const uint8_t*>(data), size),
written, error);
if (result != SR_SUCCESS) {
@ -600,6 +600,10 @@ int DtlsTransportInternalImpl::SendPacket(
downward_->ClearNextPacketOptions();
return -1;
}
// For DTLS, a SSL_Write operation will either send the entire data in a
// single record, or fail the entire send. See for example the
// documentation on SSL_write in boringssl/src/include/openssl/ssl.h
RTC_CHECK(written == size);
return static_cast<int>(size);
}
case DtlsTransportState::kFailed:

View File

@ -9,10 +9,7 @@
*/
#include "rtc_base/stream.h"
#include <cstdint>
#include <cstring>
#include "api/array_view.h"
namespace webrtc {
@ -20,23 +17,6 @@ namespace webrtc {
// StreamInterface
///////////////////////////////////////////////////////////////////////////////
StreamResult StreamInterface::WriteAll(ArrayView<const uint8_t> data,
size_t& written,
int& error) {
StreamResult result = SR_SUCCESS;
size_t total_written = 0, current_written;
while (total_written < data.size()) {
ArrayView<const uint8_t> this_slice =
data.subview(total_written, data.size() - total_written);
result = Write(this_slice, current_written, error);
if (result != SR_SUCCESS)
break;
total_written += current_written;
}
written = total_written;
return result;
}
bool StreamInterface::Flush() {
return false;
}

View File

@ -103,21 +103,6 @@ class RTC_EXPORT StreamInterface {
// Return true if flush is successful.
virtual bool Flush();
//
// CONVENIENCE METHODS
//
// These methods are implemented in terms of other methods, for convenience.
//
// WriteAll is a helper function which repeatedly calls Write until all the
// data is written, or something other than SR_SUCCESS is returned. Note that
// unlike Write, the argument 'written' is always set, and may be non-zero
// on results other than SR_SUCCESS. The remaining arguments have the
// same semantics as Write.
StreamResult WriteAll(ArrayView<const uint8_t> data,
size_t& written,
int& error);
protected:
StreamInterface();