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 #ifndef NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 5 #ifndef NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
6 #define NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 6 #define NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // | 81 // |
82 // TODO(yzshen): Change logging format and let TCPClientSocket log the | 82 // TODO(yzshen): Change logging format and let TCPClientSocket log the |
83 // start/end of a series of connect attempts itself. | 83 // start/end of a series of connect attempts itself. |
84 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); | 84 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); |
85 void EndLoggingMultipleConnectAttempts(int net_error); | 85 void EndLoggingMultipleConnectAttempts(int net_error); |
86 | 86 |
87 const BoundNetLog& net_log() const { return net_log_; } | 87 const BoundNetLog& net_log() const { return net_log_; } |
88 | 88 |
89 private: | 89 private: |
90 // States that using a socket with TCP FastOpen can lead to. | 90 // States that using a socket with TCP FastOpen can lead to. |
91 enum FastOpenStatus { | 91 enum TCPFastOpenStatus { |
92 FAST_OPEN_STATUS_UNKNOWN, | 92 TCP_FASTOPEN_STATUS_UNKNOWN, |
93 | 93 |
94 // The initial TCP FastOpen connect attempted returned synchronously, | 94 // The initial FastOpen connect attempted returned synchronously, |
95 // indicating that we had and sent a cookie along with the initial data. | 95 // indicating that we had and sent a cookie along with the initial data. |
96 FAST_OPEN_FAST_CONNECT_RETURN, | 96 TCP_FASTOPEN_FAST_CONNECT_RETURN, |
97 | 97 |
98 // The initial TCP FastOpen connect attempted returned asynchronously, | 98 // The initial FastOpen connect attempted returned asynchronously, |
99 // indicating that we did not have a cookie for the server. | 99 // indicating that we did not have a cookie for the server. |
100 FAST_OPEN_SLOW_CONNECT_RETURN, | 100 TCP_FASTOPEN_SLOW_CONNECT_RETURN, |
101 | 101 |
102 // Some other error occurred on connection, so we couldn't tell if | 102 // Some other error occurred on connection, so we couldn't tell if |
103 // TCP FastOpen would have worked. | 103 // FastOpen would have worked. |
104 FAST_OPEN_ERROR, | 104 TCP_FASTOPEN_ERROR, |
105 | 105 |
106 // An attempt to do a TCP FastOpen succeeded immediately | 106 // An attempt to do a FastOpen succeeded immediately |
107 // (FAST_OPEN_FAST_CONNECT_RETURN) and we later confirmed that the server | 107 // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and we later confirmed that the server |
108 // had acked the data we sent. | 108 // had acked the data we sent. |
109 FAST_OPEN_SYN_DATA_ACK, | 109 TCP_FASTOPEN_SYN_DATA_ACK, |
110 | 110 |
111 // An attempt to do a TCP FastOpen succeeded immediately | 111 // An attempt to do a FastOpen succeeded immediately |
112 // (FAST_OPEN_FAST_CONNECT_RETURN) and we later confirmed that the server | 112 // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and we later confirmed that the server |
113 // had nacked the data we sent. | 113 // had nacked the data we sent. |
114 FAST_OPEN_SYN_DATA_NACK, | 114 TCP_FASTOPEN_SYN_DATA_NACK, |
115 | 115 |
116 // An attempt to do a TCP FastOpen succeeded immediately | 116 // An attempt to do a FastOpen succeeded immediately |
117 // (FAST_OPEN_FAST_CONNECT_RETURN) and our probe to determine if the | 117 // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and our probe to determine if the |
118 // socket was using TCP FastOpen failed. | 118 // socket was using FastOpen failed. |
119 FAST_OPEN_SYN_DATA_FAILED, | 119 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED, |
120 | 120 |
121 // An attempt to do a TCP FastOpen failed (FAST_OPEN_SLOW_CONNECT_RETURN) | 121 // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
122 // and we later confirmed that the server had acked initial data. This | 122 // and we later confirmed that the server had acked initial data. This |
123 // should never happen (we didn't send data, so it shouldn't have | 123 // should never happen (we didn't send data, so it shouldn't have |
124 // been acked). | 124 // been acked). |
125 FAST_OPEN_NO_SYN_DATA_ACK, | 125 TCP_FASTOPEN_NO_SYN_DATA_ACK, |
126 | 126 |
127 // An attempt to do a TCP FastOpen failed (FAST_OPEN_SLOW_CONNECT_RETURN) | 127 // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
128 // and we later discovered that the server had nacked initial data. This | 128 // and we later discovered that the server had nacked initial data. This |
129 // is the expected case results for FAST_OPEN_SLOW_CONNECT_RETURN. | 129 // is the expected case results for TCP_FASTOPEN_SLOW_CONNECT_RETURN. |
130 FAST_OPEN_NO_SYN_DATA_NACK, | 130 TCP_FASTOPEN_NO_SYN_DATA_NACK, |
131 | 131 |
132 // An attempt to do a TCP FastOpen failed (FAST_OPEN_SLOW_CONNECT_RETURN) | 132 // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
133 // and our later probe for ack/nack state failed. | 133 // and our later probe for ack/nack state failed. |
134 FAST_OPEN_NO_SYN_DATA_FAILED, | 134 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED, |
135 | 135 |
136 FAST_OPEN_MAX_VALUE | 136 // The initial FastOpen connect+write succeeded immediately |
| 137 // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and a subsequent attempt to read from |
| 138 // the connection failed. |
| 139 TCP_FASTOPEN_FAST_CONNECT_READ_FAILED, |
| 140 |
| 141 // The initial FastOpen connect+write failed |
| 142 // (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
| 143 // and a subsequent attempt to read from the connection failed. |
| 144 TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED, |
| 145 |
| 146 // We didn't try FastOpen because it had failed in the past |
| 147 // (g_tcp_fastopen_has_failed was true.) |
| 148 // NOTE: This status is currently registered before a connect/write call |
| 149 // is attempted, and may capture some cases where the status is registered |
| 150 // but no connect is subsequently attempted. |
| 151 // TODO(jri): The expectation is that such cases are not the common case |
| 152 // with TCP FastOpen for SSL sockets however. Change code to be more |
| 153 // accurate when TCP FastOpen is used for more than just SSL sockets. |
| 154 TCP_FASTOPEN_PREVIOUSLY_FAILED, |
| 155 |
| 156 TCP_FASTOPEN_MAX_VALUE |
137 }; | 157 }; |
138 | 158 |
139 void AcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 159 void AcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
140 IPEndPoint* address, | 160 IPEndPoint* address, |
141 const CompletionCallback& callback, | 161 const CompletionCallback& callback, |
142 int rv); | 162 int rv); |
143 int HandleAcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 163 int HandleAcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
144 IPEndPoint* address, | 164 IPEndPoint* address, |
145 int rv); | 165 int rv); |
146 int BuildTcpSocketLibevent(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 166 int BuildTcpSocketLibevent(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
147 IPEndPoint* address); | 167 IPEndPoint* address); |
148 | 168 |
149 void ConnectCompleted(const CompletionCallback& callback, int rv) const; | 169 void ConnectCompleted(const CompletionCallback& callback, int rv) const; |
150 int HandleConnectCompleted(int rv) const; | 170 int HandleConnectCompleted(int rv) const; |
151 void LogConnectBegin(const AddressList& addresses) const; | 171 void LogConnectBegin(const AddressList& addresses) const; |
152 void LogConnectEnd(int net_error) const; | 172 void LogConnectEnd(int net_error) const; |
153 | 173 |
154 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 174 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
155 const CompletionCallback& callback, | 175 const CompletionCallback& callback, |
156 int rv); | 176 int rv); |
157 int HandleReadCompleted(IOBuffer* buf, int rv); | 177 int HandleReadCompleted(IOBuffer* buf, int rv); |
158 | 178 |
159 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 179 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
160 const CompletionCallback& callback, | 180 const CompletionCallback& callback, |
161 int rv) const; | 181 int rv); |
162 int HandleWriteCompleted(IOBuffer* buf, int rv) const; | 182 int HandleWriteCompleted(IOBuffer* buf, int rv); |
163 int TcpFastOpenWrite(IOBuffer* buf, | 183 int TcpFastOpenWrite(IOBuffer* buf, |
164 int buf_len, | 184 int buf_len, |
165 const CompletionCallback& callback); | 185 const CompletionCallback& callback); |
166 | 186 |
167 // Called when the socket is known to be in a connected state. | 187 // Called after the first read completes on a TCP FastOpen socket. |
168 void RecordFastOpenStatus(); | 188 void UpdateTCPFastOpenStatusAfterRead(); |
169 | 189 |
170 scoped_ptr<SocketLibevent> socket_; | 190 scoped_ptr<SocketLibevent> socket_; |
171 scoped_ptr<SocketLibevent> accept_socket_; | 191 scoped_ptr<SocketLibevent> accept_socket_; |
172 | 192 |
173 // Enables experimental TCP FastOpen option. | 193 // Enables experimental TCP FastOpen option. |
174 bool use_tcp_fastopen_; | 194 bool use_tcp_fastopen_; |
175 | 195 |
| 196 // True when TCP FastOpen is in use and we have attempted the |
| 197 // connect with write. |
| 198 bool tcp_fastopen_write_attempted_; |
| 199 |
176 // True when TCP FastOpen is in use and we have done the connect. | 200 // True when TCP FastOpen is in use and we have done the connect. |
177 bool tcp_fastopen_connected_; | 201 bool tcp_fastopen_connected_; |
178 FastOpenStatus fast_open_status_; | 202 |
| 203 TCPFastOpenStatus tcp_fastopen_status_; |
179 | 204 |
180 bool logging_multiple_connect_attempts_; | 205 bool logging_multiple_connect_attempts_; |
181 | 206 |
182 BoundNetLog net_log_; | 207 BoundNetLog net_log_; |
183 | 208 |
184 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); | 209 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); |
185 }; | 210 }; |
186 | 211 |
187 } // namespace net | 212 } // namespace net |
188 | 213 |
189 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 214 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
OLD | NEW |