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

Side by Side Diff: net/socket/socket_posix.cc

Issue 2034433002: Try to tolerate running on contexts with SIGPIPE enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « net/socket/socket_descriptor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/socket_posix.h" 5 #include "net/socket/socket_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/in.h> 8 #include <netinet/in.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/posix/eintr_wrapper.h" 15 #include "base/posix/eintr_wrapper.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "build/build_config.h"
17 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
18 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/base/sockaddr_storage.h" 21 #include "net/base/sockaddr_storage.h"
21 22
22 namespace net { 23 namespace net {
23 24
24 namespace { 25 namespace {
25 26
26 int MapAcceptError(int os_error) { 27 int MapAcceptError(int os_error) {
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return; 435 return;
435 436
436 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); 437 bool ok = read_socket_watcher_.StopWatchingFileDescriptor();
437 DCHECK(ok); 438 DCHECK(ok);
438 read_buf_ = NULL; 439 read_buf_ = NULL;
439 read_buf_len_ = 0; 440 read_buf_len_ = 0;
440 base::ResetAndReturn(&read_callback_).Run(rv); 441 base::ResetAndReturn(&read_callback_).Run(rv);
441 } 442 }
442 443
443 int SocketPosix::DoWrite(IOBuffer* buf, int buf_len) { 444 int SocketPosix::DoWrite(IOBuffer* buf, int buf_len) {
445 #if defined(OS_LINUX) || defined(OS_ANDROID)
446 // Disable SIGPIPE for this write. Although Chromium globally disables
447 // SIGPIPE, the net stack may be used in other consumers which do not do
448 // this. MSG_NOSIGNAL is a Linux-only API. On OS X, this is a setsockopt on
449 // socket creation.
450 int rv = HANDLE_EINTR(send(socket_fd_, buf->data(), buf_len, MSG_NOSIGNAL));
451 #else
444 int rv = HANDLE_EINTR(write(socket_fd_, buf->data(), buf_len)); 452 int rv = HANDLE_EINTR(write(socket_fd_, buf->data(), buf_len));
453 #endif
445 return rv >= 0 ? rv : MapSystemError(errno); 454 return rv >= 0 ? rv : MapSystemError(errno);
446 } 455 }
447 456
448 void SocketPosix::WriteCompleted() { 457 void SocketPosix::WriteCompleted() {
449 int rv = DoWrite(write_buf_.get(), write_buf_len_); 458 int rv = DoWrite(write_buf_.get(), write_buf_len_);
450 if (rv == ERR_IO_PENDING) 459 if (rv == ERR_IO_PENDING)
451 return; 460 return;
452 461
453 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); 462 bool ok = write_socket_watcher_.StopWatchingFileDescriptor();
454 DCHECK(ok); 463 DCHECK(ok);
(...skipping 25 matching lines...) Expand all
480 write_buf_ = NULL; 489 write_buf_ = NULL;
481 write_buf_len_ = 0; 490 write_buf_len_ = 0;
482 write_callback_.Reset(); 491 write_callback_.Reset();
483 } 492 }
484 493
485 waiting_connect_ = false; 494 waiting_connect_ = false;
486 peer_address_.reset(); 495 peer_address_.reset();
487 } 496 }
488 497
489 } // namespace net 498 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_descriptor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698