From a92ba289224ed9425bffe59edc41a0cc79292fb1 Mon Sep 17 00:00:00 2001 From: Tommi Date: Mon, 17 Oct 2022 08:36:16 +0200 Subject: [PATCH] [TurnPort] Fix error return value in TurnPort::SendTo While looking into chromium:1374310 I noticed that the function was returning 0 in a particular case. 0 isn't a valid return value as per this shortened snippet from connection.cc [1] specifically meant to catch this: int sent = port_->SendTo(...); if (sent <= 0) { RTC_DCHECK(sent < 0); error_ = port_->GetError(); ... [1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/p2p/base/connection.cc;l=1687 Also propagating the socket error value in case of failure. Bug: chromium:1374310 Change-Id: Ie00f60388d53d4127c1d419ab0352e0574044485 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279282 Reviewed-by: Harald Alvestrand Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#38408} --- p2p/base/turn_port.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index c8b7f3095b..3b060f73e4 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -653,7 +653,12 @@ int TurnPort::SendTo(const void* data, if (!entry) { RTC_LOG(LS_ERROR) << "Did not find the TurnEntry for address " << addr.ToSensitiveString(); - return 0; + // Although not finding an entry isn't a socket error, at this level we need + // to return SOCKET_ERROR (-1) and for ease of troubleshooting/debugging + // assign a value to `error_` that makes some semantic sense. In this case + // we pick EADDRNOTAVAIL (10049 on Windows, 9903 in errno.h). + error_ = EADDRNOTAVAIL; + return SOCKET_ERROR; } if (!ready()) { @@ -666,6 +671,7 @@ int TurnPort::SendTo(const void* data, CopyPortInformationToPacketInfo(&modified_options.info_signaled_after_sent); int sent = entry->Send(data, size, payload, modified_options); if (sent <= 0) { + error_ = socket_->GetError(); return SOCKET_ERROR; }