| 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 "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/sockaddr_storage.h" | 19 #include "net/base/sockaddr_storage.h" |
| 20 | 20 |
| 21 #include "base/trace_event/trace_event.h" |
| 22 |
| 21 namespace net { | 23 namespace net { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 int MapAcceptError(int os_error) { | 27 int MapAcceptError(int os_error) { |
| 26 switch (os_error) { | 28 switch (os_error) { |
| 27 // If the client aborts the connection before the server calls accept, | 29 // If the client aborts the connection before the server calls accept, |
| 28 // POSIX specifies accept should fail with ECONNABORTED. The server can | 30 // POSIX specifies accept should fail with ECONNABORTED. The server can |
| 29 // ignore the error and just call accept again, so we map the error to | 31 // ignore the error and just call accept again, so we map the error to |
| 30 // ERR_IO_PENDING. See UNIX Network Programming, Vol. 1, 3rd Ed., Sec. | 32 // ERR_IO_PENDING. See UNIX Network Programming, Vol. 1, 3rd Ed., Sec. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 PLOG(ERROR) << "close() returned an error, errno=" << errno; | 343 PLOG(ERROR) << "close() returned an error, errno=" << errno; |
| 342 socket_fd_ = kInvalidSocket; | 344 socket_fd_ = kInvalidSocket; |
| 343 } | 345 } |
| 344 } | 346 } |
| 345 | 347 |
| 346 void SocketPosix::DetachFromThread() { | 348 void SocketPosix::DetachFromThread() { |
| 347 thread_checker_.DetachFromThread(); | 349 thread_checker_.DetachFromThread(); |
| 348 } | 350 } |
| 349 | 351 |
| 350 void SocketPosix::OnFileCanReadWithoutBlocking(int fd) { | 352 void SocketPosix::OnFileCanReadWithoutBlocking(int fd) { |
| 353 TRACE_EVENT0("net", "net::SocketPosix::OnFileCanReadWithoutBlocking"); |
| 351 DCHECK(!accept_callback_.is_null() || !read_callback_.is_null()); | 354 DCHECK(!accept_callback_.is_null() || !read_callback_.is_null()); |
| 352 if (!accept_callback_.is_null()) { | 355 if (!accept_callback_.is_null()) { |
| 353 AcceptCompleted(); | 356 AcceptCompleted(); |
| 354 } else { // !read_callback_.is_null() | 357 } else { // !read_callback_.is_null() |
| 355 ReadCompleted(); | 358 ReadCompleted(); |
| 356 } | 359 } |
| 357 } | 360 } |
| 358 | 361 |
| 359 void SocketPosix::OnFileCanWriteWithoutBlocking(int fd) { | 362 void SocketPosix::OnFileCanWriteWithoutBlocking(int fd) { |
| 360 DCHECK(!write_callback_.is_null()); | 363 DCHECK(!write_callback_.is_null()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 write_buf_ = NULL; | 481 write_buf_ = NULL; |
| 479 write_buf_len_ = 0; | 482 write_buf_len_ = 0; |
| 480 write_callback_.Reset(); | 483 write_callback_.Reset(); |
| 481 } | 484 } |
| 482 | 485 |
| 483 waiting_connect_ = false; | 486 waiting_connect_ = false; |
| 484 peer_address_.reset(); | 487 peer_address_.reset(); |
| 485 } | 488 } |
| 486 | 489 |
| 487 } // namespace net | 490 } // namespace net |
| OLD | NEW |