| 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_POSIX_H_ | 5 #ifndef NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| 6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ | 6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 18 #include "net/log/net_log_with_source.h" | 18 #include "net/log/net_log_with_source.h" |
| 19 #include "net/socket/socket_descriptor.h" |
| 19 #include "net/socket/socket_performance_watcher.h" | 20 #include "net/socket/socket_performance_watcher.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class TimeDelta; | 23 class TimeDelta; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 | 27 |
| 27 class AddressList; | 28 class AddressList; |
| 28 class IOBuffer; | 29 class IOBuffer; |
| 29 class IPEndPoint; | 30 class IPEndPoint; |
| 30 class SocketPosix; | 31 class SocketPosix; |
| 31 class NetLog; | 32 class NetLog; |
| 32 struct NetLogSource; | 33 struct NetLogSource; |
| 33 | 34 |
| 34 class NET_EXPORT TCPSocketPosix { | 35 class NET_EXPORT TCPSocketPosix { |
| 35 public: | 36 public: |
| 36 // |socket_performance_watcher| is notified of the performance metrics related | 37 // |socket_performance_watcher| is notified of the performance metrics related |
| 37 // to this socket. |socket_performance_watcher| may be null. | 38 // to this socket. |socket_performance_watcher| may be null. |
| 38 TCPSocketPosix( | 39 TCPSocketPosix( |
| 39 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 40 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 40 NetLog* net_log, | 41 NetLog* net_log, |
| 41 const NetLogSource& source); | 42 const NetLogSource& source); |
| 42 virtual ~TCPSocketPosix(); | 43 virtual ~TCPSocketPosix(); |
| 43 | 44 |
| 44 int Open(AddressFamily family); | 45 int Open(AddressFamily family); |
| 45 | 46 |
| 46 // Takes ownership of |socket_fd|. | 47 // Takes ownership of |socket|, which is known to already be connected to the |
| 47 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); | 48 // given peer address. However, peer address may be the empty address, for |
| 49 // compatibility. The given peer address will be returned by GetPeerAddress. |
| 50 int AdoptConnectedSocket(SocketDescriptor socket, |
| 51 const IPEndPoint& peer_address); |
| 52 // Takes ownership of |socket|, which may or may not be open, bound, or |
| 53 // listening. The caller must determine the state of the socket based on its |
| 54 // provenance and act accordingly. The socket may have connections waiting |
| 55 // to be accepted, but must not be actually connected. |
| 56 int AdoptUnconnectedSocket(SocketDescriptor socket); |
| 48 | 57 |
| 49 int Bind(const IPEndPoint& address); | 58 int Bind(const IPEndPoint& address); |
| 50 | 59 |
| 51 int Listen(int backlog); | 60 int Listen(int backlog); |
| 52 int Accept(std::unique_ptr<TCPSocketPosix>* socket, | 61 int Accept(std::unique_ptr<TCPSocketPosix>* socket, |
| 53 IPEndPoint* address, | 62 IPEndPoint* address, |
| 54 const CompletionCallback& callback); | 63 const CompletionCallback& callback); |
| 55 | 64 |
| 56 int Connect(const IPEndPoint& address, const CompletionCallback& callback); | 65 int Connect(const IPEndPoint& address, const CompletionCallback& callback); |
| 57 bool IsConnected() const; | 66 bool IsConnected() const; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // NetLogEventType::TCP_CONNECT. These methods set the start/end of | 115 // NetLogEventType::TCP_CONNECT. These methods set the start/end of |
| 107 // NetLogEventType::TCP_CONNECT. | 116 // NetLogEventType::TCP_CONNECT. |
| 108 // | 117 // |
| 109 // TODO(yzshen): Change logging format and let TCPClientSocket log the | 118 // TODO(yzshen): Change logging format and let TCPClientSocket log the |
| 110 // start/end of a series of connect attempts itself. | 119 // start/end of a series of connect attempts itself. |
| 111 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); | 120 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); |
| 112 void EndLoggingMultipleConnectAttempts(int net_error); | 121 void EndLoggingMultipleConnectAttempts(int net_error); |
| 113 | 122 |
| 114 const NetLogWithSource& net_log() const { return net_log_; } | 123 const NetLogWithSource& net_log() const { return net_log_; } |
| 115 | 124 |
| 125 // Return the underlying SocketDescriptor and clean up this object, which may |
| 126 // no longer be used. This method should be used only for testing. No read, |
| 127 // write, or accept operations should be pending. |
| 128 SocketDescriptor ReleaseSocketDescriptorForTesting(); |
| 129 |
| 116 private: | 130 private: |
| 117 // States that using a socket with TCP FastOpen can lead to. | 131 // States that using a socket with TCP FastOpen can lead to. |
| 118 enum TCPFastOpenStatus { | 132 enum TCPFastOpenStatus { |
| 119 TCP_FASTOPEN_STATUS_UNKNOWN, | 133 TCP_FASTOPEN_STATUS_UNKNOWN, |
| 120 | 134 |
| 121 // The initial FastOpen connect attempted returned synchronously, | 135 // The initial FastOpen connect attempted returned synchronously, |
| 122 // indicating that we had and sent a cookie along with the initial data. | 136 // indicating that we had and sent a cookie along with the initial data. |
| 123 TCP_FASTOPEN_FAST_CONNECT_RETURN, | 137 TCP_FASTOPEN_FAST_CONNECT_RETURN, |
| 124 | 138 |
| 125 // The initial FastOpen connect attempted returned asynchronously, | 139 // The initial FastOpen connect attempted returned asynchronously, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 bool logging_multiple_connect_attempts_; | 256 bool logging_multiple_connect_attempts_; |
| 243 | 257 |
| 244 NetLogWithSource net_log_; | 258 NetLogWithSource net_log_; |
| 245 | 259 |
| 246 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); | 260 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
| 247 }; | 261 }; |
| 248 | 262 |
| 249 } // namespace net | 263 } // namespace net |
| 250 | 264 |
| 251 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ | 265 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| OLD | NEW |