Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: webrtc/base/physicalsocketserver.cc

Issue 1616153007: Stay writable after partial socket writes. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More feedback. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/physicalsocketserver.h ('k') | webrtc/base/physicalsocketserver_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include "webrtc/base/physicalsocketserver.h" 10 #include "webrtc/base/physicalsocketserver.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return -1; 264 return -1;
265 if (opt == OPT_DONTFRAGMENT) { 265 if (opt == OPT_DONTFRAGMENT) {
266 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 266 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
267 value = (value) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT; 267 value = (value) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
268 #endif 268 #endif
269 } 269 }
270 return ::setsockopt(s_, slevel, sopt, (SockOptArg)&value, sizeof(value)); 270 return ::setsockopt(s_, slevel, sopt, (SockOptArg)&value, sizeof(value));
271 } 271 }
272 272
273 int PhysicalSocket::Send(const void* pv, size_t cb) { 273 int PhysicalSocket::Send(const void* pv, size_t cb) {
274 int sent = ::send(s_, reinterpret_cast<const char *>(pv), (int)cb, 274 int sent = DoSend(s_, reinterpret_cast<const char *>(pv),
275 static_cast<int>(cb),
275 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 276 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
276 // Suppress SIGPIPE. Without this, attempting to send on a socket whose 277 // Suppress SIGPIPE. Without this, attempting to send on a socket whose
277 // other end is closed will result in a SIGPIPE signal being raised to 278 // other end is closed will result in a SIGPIPE signal being raised to
278 // our process, which by default will terminate the process, which we 279 // our process, which by default will terminate the process, which we
279 // don't want. By specifying this flag, we'll just get the error EPIPE 280 // don't want. By specifying this flag, we'll just get the error EPIPE
280 // instead and can handle the error gracefully. 281 // instead and can handle the error gracefully.
281 MSG_NOSIGNAL 282 MSG_NOSIGNAL
282 #else 283 #else
283 0 284 0
284 #endif 285 #endif
285 ); 286 );
286 UpdateLastError(); 287 UpdateLastError();
287 MaybeRemapSendError(); 288 MaybeRemapSendError();
288 // We have seen minidumps where this may be false. 289 // We have seen minidumps where this may be false.
289 ASSERT(sent <= static_cast<int>(cb)); 290 ASSERT(sent <= static_cast<int>(cb));
290 if ((sent < 0) && IsBlockingError(GetError())) { 291 if ((sent > 0 && sent < static_cast<int>(cb)) ||
292 (sent < 0 && IsBlockingError(GetError()))) {
291 enabled_events_ |= DE_WRITE; 293 enabled_events_ |= DE_WRITE;
292 } 294 }
293 return sent; 295 return sent;
294 } 296 }
295 297
296 int PhysicalSocket::SendTo(const void* buffer, 298 int PhysicalSocket::SendTo(const void* buffer,
297 size_t length, 299 size_t length,
298 const SocketAddress& addr) { 300 const SocketAddress& addr) {
299 sockaddr_storage saddr; 301 sockaddr_storage saddr;
300 size_t len = addr.ToSockAddrStorage(&saddr); 302 size_t len = addr.ToSockAddrStorage(&saddr);
301 int sent = ::sendto( 303 int sent = DoSendTo(
302 s_, static_cast<const char *>(buffer), static_cast<int>(length), 304 s_, static_cast<const char *>(buffer), static_cast<int>(length),
303 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 305 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
304 // Suppress SIGPIPE. See above for explanation. 306 // Suppress SIGPIPE. See above for explanation.
305 MSG_NOSIGNAL, 307 MSG_NOSIGNAL,
306 #else 308 #else
307 0, 309 0,
308 #endif 310 #endif
309 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len)); 311 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len));
310 UpdateLastError(); 312 UpdateLastError();
311 MaybeRemapSendError(); 313 MaybeRemapSendError();
312 // We have seen minidumps where this may be false. 314 // We have seen minidumps where this may be false.
313 ASSERT(sent <= static_cast<int>(length)); 315 ASSERT(sent <= static_cast<int>(length));
314 if ((sent < 0) && IsBlockingError(GetError())) { 316 if ((sent > 0 && sent < static_cast<int>(length)) ||
317 (sent < 0 && IsBlockingError(GetError()))) {
315 enabled_events_ |= DE_WRITE; 318 enabled_events_ |= DE_WRITE;
316 } 319 }
317 return sent; 320 return sent;
318 } 321 }
319 322
320 int PhysicalSocket::Recv(void* buffer, size_t length) { 323 int PhysicalSocket::Recv(void* buffer, size_t length) {
321 int received = ::recv(s_, static_cast<char*>(buffer), 324 int received = ::recv(s_, static_cast<char*>(buffer),
322 static_cast<int>(length), 0); 325 static_cast<int>(length), 0);
323 if ((received == 0) && (length != 0)) { 326 if ((received == 0) && (length != 0)) {
324 // Note: on graceful shutdown, recv can return 0. In this case, we 327 // Note: on graceful shutdown, recv can return 0. In this case, we
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 ASSERT((0 <= value) && (value <= 65536)); 470 ASSERT((0 <= value) && (value <= 65536));
468 *mtu = value; 471 *mtu = value;
469 return 0; 472 return 0;
470 #elif defined(__native_client__) 473 #elif defined(__native_client__)
471 // Most socket operations, including this, will fail in NaCl's sandbox. 474 // Most socket operations, including this, will fail in NaCl's sandbox.
472 error_ = EACCES; 475 error_ = EACCES;
473 return -1; 476 return -1;
474 #endif 477 #endif
475 } 478 }
476 479
477
478 SOCKET PhysicalSocket::DoAccept(SOCKET socket, 480 SOCKET PhysicalSocket::DoAccept(SOCKET socket,
479 sockaddr* addr, 481 sockaddr* addr,
480 socklen_t* addrlen) { 482 socklen_t* addrlen) {
481 return ::accept(socket, addr, addrlen); 483 return ::accept(socket, addr, addrlen);
482 } 484 }
483 485
486 int PhysicalSocket::DoSend(SOCKET socket, const char* buf, int len, int flags) {
487 return ::send(socket, buf, len, flags);
488 }
489
490 int PhysicalSocket::DoSendTo(SOCKET socket,
491 const char* buf,
492 int len,
493 int flags,
494 const struct sockaddr* dest_addr,
495 socklen_t addrlen) {
496 return ::sendto(socket, buf, len, flags, dest_addr, addrlen);
497 }
498
484 void PhysicalSocket::OnResolveResult(AsyncResolverInterface* resolver) { 499 void PhysicalSocket::OnResolveResult(AsyncResolverInterface* resolver) {
485 if (resolver != resolver_) { 500 if (resolver != resolver_) {
486 return; 501 return;
487 } 502 }
488 503
489 int error = resolver_->GetError(); 504 int error = resolver_->GetError();
490 if (error == 0) { 505 if (error == 0) {
491 error = DoConnect(resolver_->address()); 506 error = DoConnect(resolver_->address());
492 } else { 507 } else {
493 Close(); 508 Close();
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 break; 1623 break;
1609 } 1624 }
1610 } 1625 }
1611 1626
1612 // Done 1627 // Done
1613 return true; 1628 return true;
1614 } 1629 }
1615 #endif // WEBRTC_WIN 1630 #endif // WEBRTC_WIN
1616 1631
1617 } // namespace rtc 1632 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/physicalsocketserver.h ('k') | webrtc/base/physicalsocketserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698