OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |