| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // NetLog::TYPE_TCP_CONNECT. | 80 // NetLog::TYPE_TCP_CONNECT. |
| 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 a fast open socket attempt can result in. | 90 // States that a FastOpen socket attempt can result in. |
| 91 enum FastOpenStatus { | 91 enum TCPFastOpenStatus { |
| 92 FAST_OPEN_STATUS_UNKNOWN, | 92 TCP_FASTOPEN_STATUS_UNKNOWN, |
| 93 | 93 |
| 94 // The initial fast open 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 fast open 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 // fast open would have worked. | 103 // FastOpen would have worked. |
| 104 FAST_OPEN_ERROR, | 104 TCP_FASTOPEN_ERROR, |
| 105 | 105 |
| 106 // An attempt to do a fast open 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 fast open 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 fast open 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 fast open 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 fast open 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 fast open 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 fast open 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 TCP_FASTOPEN_PREVIOUSLY_FAILED, |
| 149 |
| 150 TCP_FASTOPEN_MAX_VALUE |
| 137 }; | 151 }; |
| 138 | 152 |
| 139 void AcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 153 void AcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
| 140 IPEndPoint* address, | 154 IPEndPoint* address, |
| 141 const CompletionCallback& callback, | 155 const CompletionCallback& callback, |
| 142 int rv); | 156 int rv); |
| 143 int HandleAcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 157 int HandleAcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
| 144 IPEndPoint* address, | 158 IPEndPoint* address, |
| 145 int rv); | 159 int rv); |
| 146 int BuildTcpSocketLibevent(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 160 int BuildTcpSocketLibevent(scoped_ptr<TCPSocketLibevent>* tcp_socket, |
| 147 IPEndPoint* address); | 161 IPEndPoint* address); |
| 148 | 162 |
| 149 void ConnectCompleted(const CompletionCallback& callback, int rv) const; | 163 void ConnectCompleted(const CompletionCallback& callback, int rv) const; |
| 150 int HandleConnectCompleted(int rv) const; | 164 int HandleConnectCompleted(int rv) const; |
| 151 void LogConnectBegin(const AddressList& addresses) const; | 165 void LogConnectBegin(const AddressList& addresses) const; |
| 152 void LogConnectEnd(int net_error) const; | 166 void LogConnectEnd(int net_error) const; |
| 153 | 167 |
| 154 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 168 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
| 155 const CompletionCallback& callback, | 169 const CompletionCallback& callback, |
| 156 int rv); | 170 int rv); |
| 157 int HandleReadCompleted(IOBuffer* buf, int rv); | 171 int HandleReadCompleted(IOBuffer* buf, int rv); |
| 158 | 172 |
| 159 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 173 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
| 160 const CompletionCallback& callback, | 174 const CompletionCallback& callback, |
| 161 int rv) const; | 175 int rv); |
| 162 int HandleWriteCompleted(IOBuffer* buf, int rv) const; | 176 int HandleWriteCompleted(IOBuffer* buf, int rv); |
| 163 int TcpFastOpenWrite(IOBuffer* buf, | 177 int TcpFastOpenWrite(IOBuffer* buf, |
| 164 int buf_len, | 178 int buf_len, |
| 165 const CompletionCallback& callback); | 179 const CompletionCallback& callback); |
| 166 | 180 |
| 167 // Called when the socket is known to be in a connected state. | 181 // Called after the first read completes on a TCP FastOpen socket. |
| 168 void RecordFastOpenStatus(); | 182 void UpdateTCPFastOpenStatusAfterRead(); |
| 169 | 183 |
| 170 scoped_ptr<SocketLibevent> socket_; | 184 scoped_ptr<SocketLibevent> socket_; |
| 171 scoped_ptr<SocketLibevent> accept_socket_; | 185 scoped_ptr<SocketLibevent> accept_socket_; |
| 172 | 186 |
| 173 // Enables experimental TCP FastOpen option. | 187 // Enables experimental TCP FastOpen option. |
| 174 bool use_tcp_fastopen_; | 188 bool use_tcp_fastopen_; |
| 175 | 189 |
| 190 // True when TCP FastOpen is in use and we have attempted the |
| 191 // connect with write. |
| 192 bool tcp_fastopen_write_attempted_; |
| 193 |
| 176 // True when TCP FastOpen is in use and we have done the connect. | 194 // True when TCP FastOpen is in use and we have done the connect. |
| 177 bool tcp_fastopen_connected_; | 195 bool tcp_fastopen_connected_; |
| 178 FastOpenStatus fast_open_status_; | 196 |
| 197 TCPFastOpenStatus tcp_fastopen_status_; |
| 179 | 198 |
| 180 bool logging_multiple_connect_attempts_; | 199 bool logging_multiple_connect_attempts_; |
| 181 | 200 |
| 182 BoundNetLog net_log_; | 201 BoundNetLog net_log_; |
| 183 | 202 |
| 184 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); | 203 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); |
| 185 }; | 204 }; |
| 186 | 205 |
| 187 } // namespace net | 206 } // namespace net |
| 188 | 207 |
| 189 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 208 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ |
| OLD | NEW |