[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 5 | #ifndef NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| 6 | #define NET_SOCKET_TCP_SOCKET_POSIX_H_ |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 15 | #include "net/base/address_family.h" |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 16 | #include "net/base/completion_once_callback.h" |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 17 | #include "net/base/net_export.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 18 | #include "net/log/net_log_with_source.h" |
rvera | 26f0a139 | 2017-05-02 22:25:44 | [diff] [blame] | 19 | #include "net/socket/socket_descriptor.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 20 | #include "net/socket/socket_performance_watcher.h" |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 21 | #include "net/socket/socket_tag.h" |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 22 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 23 | |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 24 | namespace base { |
tbansal | 180587c | 2017-02-16 15:13:23 | [diff] [blame] | 25 | class TimeDelta; |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 28 | namespace net { |
| 29 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 30 | class AddressList; |
| 31 | class IOBuffer; |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 32 | class IPEndPoint; |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 33 | class SocketPosix; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 34 | class NetLog; |
| 35 | struct NetLogSource; |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 36 | class SocketTag; |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 37 | |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 38 | class NET_EXPORT TCPSocketPosix { |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 39 | public: |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 40 | // |socket_performance_watcher| is notified of the performance metrics related |
| 41 | // to this socket. |socket_performance_watcher| may be null. |
| 42 | TCPSocketPosix( |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 43 | std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 44 | NetLog* net_log, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 45 | const NetLogSource& source); |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 46 | virtual ~TCPSocketPosix(); |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 47 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 48 | // Opens the socket. |
| 49 | // Returns a net error code. |
[email protected] | c9080d8 | 2013-09-15 15:14:16 | [diff] [blame] | 50 | int Open(AddressFamily family); |
tfarina | a0922c8 | 2017-04-15 11:54:49 | [diff] [blame] | 51 | |
rvera | 26f0a139 | 2017-05-02 22:25:44 | [diff] [blame] | 52 | // Takes ownership of |socket|, which is known to already be connected to the |
| 53 | // given peer address. However, peer address may be the empty address, for |
| 54 | // compatibility. The given peer address will be returned by GetPeerAddress. |
| 55 | int AdoptConnectedSocket(SocketDescriptor socket, |
| 56 | const IPEndPoint& peer_address); |
| 57 | // Takes ownership of |socket|, which may or may not be open, bound, or |
| 58 | // listening. The caller must determine the state of the socket based on its |
| 59 | // provenance and act accordingly. The socket may have connections waiting |
| 60 | // to be accepted, but must not be actually connected. |
| 61 | int AdoptUnconnectedSocket(SocketDescriptor socket); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 62 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 63 | // Binds this socket to |address|. This is generally only used on a server. |
| 64 | // Should be called after Open(). Returns a net error code. |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 65 | int Bind(const IPEndPoint& address); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 66 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 67 | // Put this socket on listen state with the given |backlog|. |
| 68 | // Returns a net error code. |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 69 | int Listen(int backlog); |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 70 | |
| 71 | // Accepts incoming connection. |
| 72 | // Returns a net error code. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 73 | int Accept(std::unique_ptr<TCPSocketPosix>* socket, |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 74 | IPEndPoint* address, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 75 | CompletionOnceCallback callback); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 76 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 77 | // Connects this socket to the given |address|. |
| 78 | // Should be called after Open(). |
| 79 | // Returns a net error code. |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 80 | int Connect(const IPEndPoint& address, CompletionOnceCallback callback); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 81 | bool IsConnected() const; |
| 82 | bool IsConnectedAndIdle() const; |
| 83 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 84 | // IO: |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 85 | // Multiple outstanding requests are not supported. |
| 86 | // Full duplex mode (reading and writing at the same time) is supported. |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 87 | |
| 88 | // Reads from the socket. |
| 89 | // Returns a net error code. |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 90 | int Read(IOBuffer* buf, int buf_len, CompletionOnceCallback callback); |
| 91 | int ReadIfReady(IOBuffer* buf, int buf_len, CompletionOnceCallback callback); |
Helen Li | a6d3b2c | 2018-05-08 16:09:07 | [diff] [blame] | 92 | int CancelReadIfReady(); |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 93 | |
| 94 | // Writes to the socket. |
| 95 | // Returns a net error code. |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 96 | int Write(IOBuffer* buf, |
| 97 | int buf_len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 98 | CompletionOnceCallback callback, |
[email protected] | 690bbea | 2017-12-08 09:05:46 | [diff] [blame] | 99 | const NetworkTrafficAnnotationTag& traffic_annotation); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 100 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 101 | // Copies the local tcp address into |address| and returns a net error code. |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 102 | int GetLocalAddress(IPEndPoint* address) const; |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 103 | |
| 104 | // Copies the remote tcp code into |address| and returns a net error code. |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 105 | int GetPeerAddress(IPEndPoint* address) const; |
| 106 | |
| 107 | // Sets various socket options. |
| 108 | // The commonly used options for server listening sockets: |
tfarina | a0922c8 | 2017-04-15 11:54:49 | [diff] [blame] | 109 | // - AllowAddressReuse(). |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 110 | int SetDefaultOptionsForServer(); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 111 | // The commonly used options for client sockets and accepted sockets: |
| 112 | // - SetNoDelay(true); |
| 113 | // - SetKeepAlive(true, 45). |
| 114 | void SetDefaultOptionsForClient(); |
tfarina | a0922c8 | 2017-04-15 11:54:49 | [diff] [blame] | 115 | int AllowAddressReuse(); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 116 | int SetReceiveBufferSize(int32_t size); |
| 117 | int SetSendBufferSize(int32_t size); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 118 | bool SetKeepAlive(bool enable, int delay); |
| 119 | bool SetNoDelay(bool no_delay); |
| 120 | |
bmcquade | 8b62f47 | 2015-07-08 16:03:54 | [diff] [blame] | 121 | // Gets the estimated RTT. Returns false if the RTT is |
| 122 | // unavailable. May also return false when estimated RTT is 0. |
| 123 | bool GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const |
| 124 | WARN_UNUSED_RESULT; |
| 125 | |
tfarina | fdec305 | 2017-04-25 13:36:25 | [diff] [blame] | 126 | // Closes the socket. |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 127 | void Close(); |
| 128 | |
jri | dcb4ae92 | 2014-09-12 23:52:39 | [diff] [blame] | 129 | void EnableTCPFastOpenIfSupported(); |
| 130 | |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 131 | bool IsValid() const; |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 132 | |
svaldez | 58804c40 | 2015-10-06 00:13:47 | [diff] [blame] | 133 | // Detachs from the current thread, to allow the socket to be transferred to |
| 134 | // a new thread. Should only be called when the object is no longer used by |
| 135 | // the old thread. |
| 136 | void DetachFromThread(); |
| 137 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 138 | // Marks the start/end of a series of connect attempts for logging purpose. |
| 139 | // |
| 140 | // TCPClientSocket may attempt to connect to multiple addresses until it |
| 141 | // succeeds in establishing a connection. The corresponding log will have |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 142 | // multiple NetLogEventType::TCP_CONNECT_ATTEMPT entries nested within a |
| 143 | // NetLogEventType::TCP_CONNECT. These methods set the start/end of |
| 144 | // NetLogEventType::TCP_CONNECT. |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 145 | // |
| 146 | // TODO(yzshen): Change logging format and let TCPClientSocket log the |
| 147 | // start/end of a series of connect attempts itself. |
| 148 | void StartLoggingMultipleConnectAttempts(const AddressList& addresses); |
| 149 | void EndLoggingMultipleConnectAttempts(int net_error); |
| 150 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 151 | const NetLogWithSource& net_log() const { return net_log_; } |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 152 | |
rvera | 26f0a139 | 2017-05-02 22:25:44 | [diff] [blame] | 153 | // Return the underlying SocketDescriptor and clean up this object, which may |
| 154 | // no longer be used. This method should be used only for testing. No read, |
| 155 | // write, or accept operations should be pending. |
| 156 | SocketDescriptor ReleaseSocketDescriptorForTesting(); |
| 157 | |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 158 | // Apply |tag| to this socket. |
| 159 | void ApplySocketTag(const SocketTag& tag); |
| 160 | |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 161 | private: |
jri | 23fdae2 | 2014-09-16 23:04:09 | [diff] [blame] | 162 | // States that using a socket with TCP FastOpen can lead to. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 163 | enum TCPFastOpenStatus { |
| 164 | TCP_FASTOPEN_STATUS_UNKNOWN, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 165 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 166 | // The initial FastOpen connect attempted returned synchronously, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 167 | // indicating that we had and sent a cookie along with the initial data. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 168 | TCP_FASTOPEN_FAST_CONNECT_RETURN, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 169 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 170 | // The initial FastOpen connect attempted returned asynchronously, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 171 | // indicating that we did not have a cookie for the server. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 172 | TCP_FASTOPEN_SLOW_CONNECT_RETURN, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 173 | |
| 174 | // Some other error occurred on connection, so we couldn't tell if |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 175 | // FastOpen would have worked. |
| 176 | TCP_FASTOPEN_ERROR, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 177 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 178 | // An attempt to do a FastOpen succeeded immediately |
| 179 | // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and we later confirmed that the server |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 180 | // had acked the data we sent. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 181 | TCP_FASTOPEN_SYN_DATA_ACK, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 182 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 183 | // An attempt to do a FastOpen succeeded immediately |
| 184 | // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and we later confirmed that the server |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 185 | // had nacked the data we sent. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 186 | TCP_FASTOPEN_SYN_DATA_NACK, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 187 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 188 | // An attempt to do a FastOpen succeeded immediately |
| 189 | // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and our probe to determine if the |
| 190 | // socket was using FastOpen failed. |
| 191 | TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 192 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 193 | // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 194 | // and we later confirmed that the server had acked initial data. This |
| 195 | // should never happen (we didn't send data, so it shouldn't have |
| 196 | // been acked). |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 197 | TCP_FASTOPEN_NO_SYN_DATA_ACK, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 198 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 199 | // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 200 | // and we later discovered that the server had nacked initial data. This |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 201 | // is the expected case results for TCP_FASTOPEN_SLOW_CONNECT_RETURN. |
| 202 | TCP_FASTOPEN_NO_SYN_DATA_NACK, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 203 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 204 | // An attempt to do a FastOpen failed (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 205 | // and our later probe for ack/nack state failed. |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 206 | TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED, |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 207 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 208 | // The initial FastOpen connect+write succeeded immediately |
| 209 | // (TCP_FASTOPEN_FAST_CONNECT_RETURN) and a subsequent attempt to read from |
| 210 | // the connection failed. |
| 211 | TCP_FASTOPEN_FAST_CONNECT_READ_FAILED, |
| 212 | |
| 213 | // The initial FastOpen connect+write failed |
| 214 | // (TCP_FASTOPEN_SLOW_CONNECT_RETURN) |
| 215 | // and a subsequent attempt to read from the connection failed. |
| 216 | TCP_FASTOPEN_SLOW_CONNECT_READ_FAILED, |
| 217 | |
| 218 | // We didn't try FastOpen because it had failed in the past |
| 219 | // (g_tcp_fastopen_has_failed was true.) |
| 220 | // NOTE: This status is currently registered before a connect/write call |
| 221 | // is attempted, and may capture some cases where the status is registered |
| 222 | // but no connect is subsequently attempted. |
| 223 | // TODO(jri): The expectation is that such cases are not the common case |
| 224 | // with TCP FastOpen for SSL sockets however. Change code to be more |
| 225 | // accurate when TCP FastOpen is used for more than just SSL sockets. |
| 226 | TCP_FASTOPEN_PREVIOUSLY_FAILED, |
| 227 | |
| 228 | TCP_FASTOPEN_MAX_VALUE |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 229 | }; |
| 230 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 231 | void AcceptCompleted(std::unique_ptr<TCPSocketPosix>* tcp_socket, |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 232 | IPEndPoint* address, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 233 | CompletionOnceCallback callback, |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 234 | int rv); |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 235 | int HandleAcceptCompleted(std::unique_ptr<TCPSocketPosix>* tcp_socket, |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 236 | IPEndPoint* address, |
| 237 | int rv); |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 238 | int BuildTcpSocketPosix(std::unique_ptr<TCPSocketPosix>* tcp_socket, |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 239 | IPEndPoint* address); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 240 | |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 241 | void ConnectCompleted(CompletionOnceCallback callback, int rv); |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 242 | int HandleConnectCompleted(int rv); |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 243 | void LogConnectBegin(const AddressList& addresses) const; |
| 244 | void LogConnectEnd(int net_error) const; |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 245 | |
[email protected] | 573e6cc | 2014-07-12 00:33:03 | [diff] [blame] | 246 | void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 247 | CompletionOnceCallback callback, |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 248 | int rv); |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 249 | void ReadIfReadyCompleted(CompletionOnceCallback callback, int rv); |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 250 | int HandleReadCompleted(IOBuffer* buf, int rv); |
xunjieli | 321a96f3 | 2017-03-07 19:42:17 | [diff] [blame] | 251 | void HandleReadCompletedHelper(int rv); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 252 | |
[email protected] | 573e6cc | 2014-07-12 00:33:03 | [diff] [blame] | 253 | void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 254 | CompletionOnceCallback callback, |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 255 | int rv); |
| 256 | int HandleWriteCompleted(IOBuffer* buf, int rv); |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 257 | int TcpFastOpenWrite(IOBuffer* buf, |
| 258 | int buf_len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 259 | CompletionOnceCallback callback); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 260 | |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 261 | // Notifies |socket_performance_watcher_| of the latest RTT estimate available |
| 262 | // from the tcp_info struct for this TCP socket. |
| 263 | void NotifySocketPerformanceWatcher(); |
| 264 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 265 | // Called after the first read completes on a TCP FastOpen socket. |
| 266 | void UpdateTCPFastOpenStatusAfterRead(); |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 267 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 268 | std::unique_ptr<SocketPosix> socket_; |
| 269 | std::unique_ptr<SocketPosix> accept_socket_; |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 270 | |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 271 | // Socket performance statistics (such as RTT) are reported to the |
| 272 | // |socket_performance_watcher_|. May be nullptr. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 273 | std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher_; |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 274 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 275 | // Enables experimental TCP FastOpen option. |
jri | dcb4ae92 | 2014-09-12 23:52:39 | [diff] [blame] | 276 | bool use_tcp_fastopen_; |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 277 | |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 278 | // True when TCP FastOpen is in use and we have attempted the |
| 279 | // connect with write. |
| 280 | bool tcp_fastopen_write_attempted_; |
| 281 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 282 | // True when TCP FastOpen is in use and we have done the connect. |
| 283 | bool tcp_fastopen_connected_; |
jri | 76442544 | 2014-10-02 01:53:41 | [diff] [blame] | 284 | |
| 285 | TCPFastOpenStatus tcp_fastopen_status_; |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 286 | |
[email protected] | 659fd67c | 2013-09-18 21:50:26 | [diff] [blame] | 287 | bool logging_multiple_connect_attempts_; |
| 288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 289 | NetLogWithSource net_log_; |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 290 | |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 291 | // Current socket tag if |socket_| is valid, otherwise the tag to apply when |
| 292 | // |socket_| is opened. |
| 293 | SocketTag tag_; |
| 294 | |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 295 | DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
[email protected] | 21160f0 | 2013-09-01 23:04:27 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | } // namespace net |
| 299 | |
tfarina | 4eb7aad8 | 2015-09-14 17:10:34 | [diff] [blame] | 300 | #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |