OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 if (net_error != ERR_IO_PENDING) | 604 if (net_error != ERR_IO_PENDING) |
605 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); | 605 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); |
606 return net_error; | 606 return net_error; |
607 } | 607 } |
608 | 608 |
609 IPEndPoint ip_end_point; | 609 IPEndPoint ip_end_point; |
610 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) { | 610 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) { |
611 NOTREACHED(); | 611 NOTREACHED(); |
612 if (IGNORE_EINTR(close(new_socket)) < 0) | 612 if (IGNORE_EINTR(close(new_socket)) < 0) |
613 PLOG(ERROR) << "close"; | 613 PLOG(ERROR) << "close"; |
614 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, | 614 int net_error = ERR_ADDRESS_INVALID; |
615 ERR_ADDRESS_INVALID); | 615 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); |
616 return ERR_ADDRESS_INVALID; | 616 return net_error; |
617 } | 617 } |
618 scoped_ptr<TCPSocketLibevent> tcp_socket(new TCPSocketLibevent( | 618 scoped_ptr<TCPSocketLibevent> tcp_socket(new TCPSocketLibevent( |
619 net_log_.net_log(), net_log_.source())); | 619 net_log_.net_log(), net_log_.source())); |
620 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point); | 620 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point); |
621 if (adopt_result != OK) { | 621 if (adopt_result != OK) { |
622 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result); | 622 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result); |
623 return adopt_result; | 623 return adopt_result; |
624 } | 624 } |
625 *socket = tcp_socket.Pass(); | 625 *socket = tcp_socket.Pass(); |
626 *address = ip_end_point; | 626 *address = ip_end_point; |
627 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, | 627 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, |
628 CreateNetLogIPEndPointCallback(&ip_end_point)); | 628 CreateNetLogIPEndPointCallback(&ip_end_point)); |
629 return OK; | 629 return OK; |
630 } | 630 } |
631 | 631 |
632 int TCPSocketLibevent::DoConnect() { | 632 int TCPSocketLibevent::DoConnect() { |
633 DCHECK_EQ(0, connect_os_error_); | 633 DCHECK_EQ(0, connect_os_error_); |
634 | 634 |
635 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, | 635 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, |
636 CreateNetLogIPEndPointCallback(peer_address_.get())); | 636 CreateNetLogIPEndPointCallback(peer_address_.get())); |
637 | 637 |
638 // Connect the socket. | 638 // Connect the socket. |
639 if (!use_tcp_fastopen_) { | 639 if (!use_tcp_fastopen_) { |
640 SockaddrStorage storage; | 640 SockaddrStorage storage; |
641 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) | 641 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) |
642 return ERR_INVALID_ARGUMENT; | 642 return ERR_ADDRESS_INVALID; |
643 | 643 |
644 if (!HANDLE_EINTR(connect(socket_, storage.addr, storage.addr_len))) { | 644 if (!HANDLE_EINTR(connect(socket_, storage.addr, storage.addr_len))) { |
645 // Connected without waiting! | 645 // Connected without waiting! |
646 return OK; | 646 return OK; |
647 } | 647 } |
648 } else { | 648 } else { |
649 // With TCP FastOpen, we pretend that the socket is connected. | 649 // With TCP FastOpen, we pretend that the socket is connected. |
650 DCHECK(!tcp_fastopen_connected_); | 650 DCHECK(!tcp_fastopen_connected_); |
651 return OK; | 651 return OK; |
652 } | 652 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 accept_callback_.Reset(); | 818 accept_callback_.Reset(); |
819 callback.Run(result); | 819 callback.Run(result); |
820 } | 820 } |
821 } | 821 } |
822 | 822 |
823 int TCPSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { | 823 int TCPSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { |
824 int nwrite; | 824 int nwrite; |
825 if (use_tcp_fastopen_ && !tcp_fastopen_connected_) { | 825 if (use_tcp_fastopen_ && !tcp_fastopen_connected_) { |
826 SockaddrStorage storage; | 826 SockaddrStorage storage; |
827 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) { | 827 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) { |
828 errno = EINVAL; | 828 errno = EADDRNOTAVAIL; |
wtc
2014/03/04 00:43:28
Setting errno to EINVAL here was apparently an att
eroman
2014/03/04 03:01:10
That is kind of gross
| |
829 return -1; | 829 return -1; |
830 } | 830 } |
831 | 831 |
832 int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN. | 832 int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN. |
833 #if defined(OS_LINUX) | 833 #if defined(OS_LINUX) |
834 // sendto() will fail with EPIPE when the system doesn't support TCP Fast | 834 // sendto() will fail with EPIPE when the system doesn't support TCP Fast |
835 // Open. Theoretically that shouldn't happen since the caller should check | 835 // Open. Theoretically that shouldn't happen since the caller should check |
836 // for system support on startup, but users may dynamically disable TCP Fast | 836 // for system support on startup, but users may dynamically disable TCP Fast |
837 // Open via sysctl. | 837 // Open via sysctl. |
838 flags |= MSG_NOSIGNAL; | 838 flags |= MSG_NOSIGNAL; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 } | 895 } |
896 } else { | 896 } else { |
897 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? | 897 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? |
898 FAST_OPEN_SYN_DATA_FAILED : | 898 FAST_OPEN_SYN_DATA_FAILED : |
899 FAST_OPEN_NO_SYN_DATA_FAILED); | 899 FAST_OPEN_NO_SYN_DATA_FAILED); |
900 } | 900 } |
901 } | 901 } |
902 } | 902 } |
903 | 903 |
904 } // namespace net | 904 } // namespace net |
OLD | NEW |