[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 <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38408}
This commit is contained in:
Tommi 2022-10-17 08:36:16 +02:00 committed by WebRTC LUCI CQ
parent 1b3f531da4
commit a92ba28922

View File

@ -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;
}