OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 | 717 |
718 bool MockClientSocket::IsConnected() const { | 718 bool MockClientSocket::IsConnected() const { |
719 return connected_; | 719 return connected_; |
720 } | 720 } |
721 | 721 |
722 bool MockClientSocket::IsConnectedAndIdle() const { | 722 bool MockClientSocket::IsConnectedAndIdle() const { |
723 return connected_; | 723 return connected_; |
724 } | 724 } |
725 | 725 |
726 int MockClientSocket::GetPeerAddress(IPEndPoint* address) const { | 726 int MockClientSocket::GetPeerAddress(IPEndPoint* address) const { |
| 727 if (!IsConnected()) |
| 728 return ERR_SOCKET_NOT_CONNECTED; |
727 *address = peer_addr_; | 729 *address = peer_addr_; |
728 return OK; | 730 return OK; |
729 } | 731 } |
730 | 732 |
731 int MockClientSocket::GetLocalAddress(IPEndPoint* address) const { | 733 int MockClientSocket::GetLocalAddress(IPEndPoint* address) const { |
732 IPAddressNumber ip; | 734 IPAddressNumber ip; |
733 bool rv = ParseIPLiteralToNumber("192.0.2.33", &ip); | 735 bool rv = ParseIPLiteralToNumber("192.0.2.33", &ip); |
734 CHECK(rv); | 736 CHECK(rv); |
735 *address = IPEndPoint(ip, 123); | 737 *address = IPEndPoint(ip, 123); |
736 return OK; | 738 return OK; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 // If the buffer is already in use, a read is already in progress! | 815 // If the buffer is already in use, a read is already in progress! |
814 DCHECK(pending_buf_ == NULL); | 816 DCHECK(pending_buf_ == NULL); |
815 | 817 |
816 // Store our async IO data. | 818 // Store our async IO data. |
817 pending_buf_ = buf; | 819 pending_buf_ = buf; |
818 pending_buf_len_ = buf_len; | 820 pending_buf_len_ = buf_len; |
819 pending_callback_ = callback; | 821 pending_callback_ = callback; |
820 | 822 |
821 if (need_read_data_) { | 823 if (need_read_data_) { |
822 read_data_ = data_->GetNextRead(); | 824 read_data_ = data_->GetNextRead(); |
| 825 if (read_data_.result == ERR_CONNECTION_CLOSED) { |
| 826 // This MockRead is just a marker to instruct us to set |
| 827 // peer_closed_connection_. |
| 828 peer_closed_connection_ = true; |
| 829 } |
823 if (read_data_.result == ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ) { | 830 if (read_data_.result == ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ) { |
824 // This MockRead is just a marker to instruct us to set | 831 // This MockRead is just a marker to instruct us to set |
825 // peer_closed_connection_. Skip it and get the next one. | 832 // peer_closed_connection_. Skip it and get the next one. |
826 read_data_ = data_->GetNextRead(); | 833 read_data_ = data_->GetNextRead(); |
827 peer_closed_connection_ = true; | 834 peer_closed_connection_ = true; |
828 } | 835 } |
829 // ERR_IO_PENDING means that the SocketDataProvider is taking responsibility | 836 // ERR_IO_PENDING means that the SocketDataProvider is taking responsibility |
830 // to complete the async IO manually later (via OnReadComplete). | 837 // to complete the async IO manually later (via OnReadComplete). |
831 if (read_data_.result == ERR_IO_PENDING) { | 838 if (read_data_.result == ERR_IO_PENDING) { |
832 // We need to be using async IO in this case. | 839 // We need to be using async IO in this case. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket( | 978 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket( |
972 net::NetLog* net_log, DeterministicSocketData* data) | 979 net::NetLog* net_log, DeterministicSocketData* data) |
973 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), | 980 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), |
974 write_pending_(false), | 981 write_pending_(false), |
975 write_result_(0), | 982 write_result_(0), |
976 read_data_(), | 983 read_data_(), |
977 read_buf_(NULL), | 984 read_buf_(NULL), |
978 read_buf_len_(0), | 985 read_buf_len_(0), |
979 read_pending_(false), | 986 read_pending_(false), |
980 data_(data), | 987 data_(data), |
981 was_used_to_convey_data_(false) { | 988 was_used_to_convey_data_(false), |
| 989 peer_closed_connection_(false) { |
982 peer_addr_ = data->connect_data().peer_addr; | 990 peer_addr_ = data->connect_data().peer_addr; |
983 } | 991 } |
984 | 992 |
985 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {} | 993 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {} |
986 | 994 |
987 void DeterministicMockTCPClientSocket::CompleteWrite() { | 995 void DeterministicMockTCPClientSocket::CompleteWrite() { |
988 was_used_to_convey_data_ = true; | 996 was_used_to_convey_data_ = true; |
989 write_pending_ = false; | 997 write_pending_ = false; |
990 write_callback_.Run(write_result_); | 998 write_callback_.Run(write_result_); |
991 } | 999 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 int DeterministicMockTCPClientSocket::Read( | 1053 int DeterministicMockTCPClientSocket::Read( |
1046 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { | 1054 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { |
1047 if (!connected_) | 1055 if (!connected_) |
1048 return ERR_UNEXPECTED; | 1056 return ERR_UNEXPECTED; |
1049 | 1057 |
1050 read_data_ = data_->GetNextRead(); | 1058 read_data_ = data_->GetNextRead(); |
1051 // The buffer should always be big enough to contain all the MockRead data. To | 1059 // The buffer should always be big enough to contain all the MockRead data. To |
1052 // use small buffers, split the data into multiple MockReads. | 1060 // use small buffers, split the data into multiple MockReads. |
1053 DCHECK_LE(read_data_.data_len, buf_len); | 1061 DCHECK_LE(read_data_.data_len, buf_len); |
1054 | 1062 |
| 1063 if (read_data_.result == ERR_CONNECTION_CLOSED) { |
| 1064 // This MockRead is just a marker to instruct us to set |
| 1065 // peer_closed_connection_. |
| 1066 peer_closed_connection_ = true; |
| 1067 } |
| 1068 |
1055 read_buf_ = buf; | 1069 read_buf_ = buf; |
1056 read_buf_len_ = buf_len; | 1070 read_buf_len_ = buf_len; |
1057 read_callback_ = callback; | 1071 read_callback_ = callback; |
1058 | 1072 |
1059 if (read_data_.mode == ASYNC || (read_data_.result == ERR_IO_PENDING)) { | 1073 if (read_data_.mode == ASYNC || (read_data_.result == ERR_IO_PENDING)) { |
1060 read_pending_ = true; | 1074 read_pending_ = true; |
1061 DCHECK(!read_callback_.is_null()); | 1075 DCHECK(!read_callback_.is_null()); |
1062 return ERR_IO_PENDING; | 1076 return ERR_IO_PENDING; |
1063 } | 1077 } |
1064 | 1078 |
(...skipping 12 matching lines...) Expand all Loading... |
1077 return ERR_IO_PENDING; | 1091 return ERR_IO_PENDING; |
1078 } | 1092 } |
1079 return data_->connect_data().result; | 1093 return data_->connect_data().result; |
1080 } | 1094 } |
1081 | 1095 |
1082 void DeterministicMockTCPClientSocket::Disconnect() { | 1096 void DeterministicMockTCPClientSocket::Disconnect() { |
1083 MockClientSocket::Disconnect(); | 1097 MockClientSocket::Disconnect(); |
1084 } | 1098 } |
1085 | 1099 |
1086 bool DeterministicMockTCPClientSocket::IsConnected() const { | 1100 bool DeterministicMockTCPClientSocket::IsConnected() const { |
1087 return connected_; | 1101 return connected_ && !peer_closed_connection_; |
1088 } | 1102 } |
1089 | 1103 |
1090 bool DeterministicMockTCPClientSocket::IsConnectedAndIdle() const { | 1104 bool DeterministicMockTCPClientSocket::IsConnectedAndIdle() const { |
1091 return IsConnected(); | 1105 return IsConnected(); |
1092 } | 1106 } |
1093 | 1107 |
1094 bool DeterministicMockTCPClientSocket::WasEverUsed() const { | 1108 bool DeterministicMockTCPClientSocket::WasEverUsed() const { |
1095 return was_used_to_convey_data_; | 1109 return was_used_to_convey_data_; |
1096 } | 1110 } |
1097 | 1111 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 | 1700 |
1687 const char kSOCKS5OkRequest[] = | 1701 const char kSOCKS5OkRequest[] = |
1688 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1702 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
1689 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1703 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
1690 | 1704 |
1691 const char kSOCKS5OkResponse[] = | 1705 const char kSOCKS5OkResponse[] = |
1692 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1706 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
1693 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1707 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
1694 | 1708 |
1695 } // namespace net | 1709 } // namespace net |
OLD | NEW |