| 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_POSIX_H_ |
| 6 #define NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 6 #define NET_SOCKET_TCP_SOCKET_POSIX_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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "net/base/address_family.h" | 13 #include "net/base/address_family.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class AddressList; | 20 class AddressList; |
| 21 class IOBuffer; | 21 class IOBuffer; |
| 22 class IPEndPoint; | 22 class IPEndPoint; |
| 23 class SocketLibevent; | 23 class SocketPosix; |
| 24 | 24 |
| 25 class NET_EXPORT TCPSocketLibevent { | 25 class NET_EXPORT TCPSocketPosix { |
| 26 public: | 26 public: |
| 27 TCPSocketLibevent(NetLog* net_log, const NetLog::Source& source); | 27 TCPSocketPosix(NetLog* net_log, const NetLog::Source& source); |
| 28 virtual ~TCPSocketLibevent(); | 28 virtual ~TCPSocketPosix(); |
| 29 | 29 |
| 30 int Open(AddressFamily family); | 30 int Open(AddressFamily family); |
| 31 // Takes ownership of |socket_fd|. | 31 // Takes ownership of |socket_fd|. |
| 32 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); | 32 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); |
| 33 | 33 |
| 34 int Bind(const IPEndPoint& address); | 34 int Bind(const IPEndPoint& address); |
| 35 | 35 |
| 36 int Listen(int backlog); | 36 int Listen(int backlog); |
| 37 int Accept(scoped_ptr<TCPSocketLibevent>* socket, | 37 int Accept(scoped_ptr<TCPSocketPosix>* socket, |
| 38 IPEndPoint* address, | 38 IPEndPoint* address, |
| 39 const CompletionCallback& callback); | 39 const CompletionCallback& callback); |
| 40 | 40 |
| 41 int Connect(const IPEndPoint& address, const CompletionCallback& callback); | 41 int Connect(const IPEndPoint& address, const CompletionCallback& callback); |
| 42 bool IsConnected() const; | 42 bool IsConnected() const; |
| 43 bool IsConnectedAndIdle() const; | 43 bool IsConnectedAndIdle() const; |
| 44 | 44 |
| 45 // Multiple outstanding requests are not supported. | 45 // Multiple outstanding requests are not supported. |
| 46 // Full duplex mode (reading and writing at the same time) is supported. | 46 // Full duplex mode (reading and writing at the same time) is supported. |
| 47 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 47 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // is attempted, and may capture some cases where the status is registered | 155 // is attempted, and may capture some cases where the status is registered |
| 156 // but no connect is subsequently attempted. | 156 // but no connect is subsequently attempted. |
| 157 // TODO(jri): The expectation is that such cases are not the common case | 157 // TODO(jri): The expectation is that such cases are not the common case |
| 158 // with TCP FastOpen for SSL sockets however. Change code to be more | 158 // with TCP FastOpen for SSL sockets however. Change code to be more |
| 159 // accurate when TCP FastOpen is used for more than just SSL sockets. | 159 // accurate when TCP FastOpen is used for more than just SSL sockets. |
| 160 TCP_FASTOPEN_PREVIOUSLY_FAILED, | 160 TCP_FASTOPEN_PREVIOUSLY_FAILED, |
| 161 | 161 |
| 162 TCP_FASTOPEN_MAX_VALUE | 162 TCP_FASTOPEN_MAX_VALUE |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 void AcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 165 void AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
| 166 IPEndPoint* address, | 166 IPEndPoint* address, |
| 167 const CompletionCallback& callback, | 167 const CompletionCallback& callback, |
| 168 int rv); | 168 int rv); |
| 169 int HandleAcceptCompleted(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 169 int HandleAcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
| 170 IPEndPoint* address, | 170 IPEndPoint* address, |
| 171 int rv); | 171 int rv); |
| 172 int BuildTcpSocketLibevent(scoped_ptr<TCPSocketLibevent>* tcp_socket, | 172 int BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, |
| 173 IPEndPoint* address); | 173 IPEndPoint* address); |
| 174 | 174 |
| 175 void ConnectCompleted(const CompletionCallback& callback, int rv) const; | 175 void ConnectCompleted(const CompletionCallback& callback, int rv) const; |
| 176 int HandleConnectCompleted(int rv) const; | 176 int HandleConnectCompleted(int rv) const; |
| 177 void LogConnectBegin(const AddressList& addresses) const; | 177 void LogConnectBegin(const AddressList& addresses) const; |
| 178 void LogConnectEnd(int net_error) const; | 178 void LogConnectEnd(int net_error) const; |
| 179 | 179 |
| 180 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 180 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
| 181 const CompletionCallback& callback, | 181 const CompletionCallback& callback, |
| 182 int rv); | 182 int rv); |
| 183 int HandleReadCompleted(IOBuffer* buf, int rv); | 183 int HandleReadCompleted(IOBuffer* buf, int rv); |
| 184 | 184 |
| 185 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 185 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
| 186 const CompletionCallback& callback, | 186 const CompletionCallback& callback, |
| 187 int rv); | 187 int rv); |
| 188 int HandleWriteCompleted(IOBuffer* buf, int rv); | 188 int HandleWriteCompleted(IOBuffer* buf, int rv); |
| 189 int TcpFastOpenWrite(IOBuffer* buf, | 189 int TcpFastOpenWrite(IOBuffer* buf, |
| 190 int buf_len, | 190 int buf_len, |
| 191 const CompletionCallback& callback); | 191 const CompletionCallback& callback); |
| 192 | 192 |
| 193 // Called after the first read completes on a TCP FastOpen socket. | 193 // Called after the first read completes on a TCP FastOpen socket. |
| 194 void UpdateTCPFastOpenStatusAfterRead(); | 194 void UpdateTCPFastOpenStatusAfterRead(); |
| 195 | 195 |
| 196 scoped_ptr<SocketLibevent> socket_; | 196 scoped_ptr<SocketPosix> socket_; |
| 197 scoped_ptr<SocketLibevent> accept_socket_; | 197 scoped_ptr<SocketPosix> accept_socket_; |
| 198 | 198 |
| 199 // Enables experimental TCP FastOpen option. | 199 // Enables experimental TCP FastOpen option. |
| 200 bool use_tcp_fastopen_; | 200 bool use_tcp_fastopen_; |
| 201 | 201 |
| 202 // True when TCP FastOpen is in use and we have attempted the | 202 // True when TCP FastOpen is in use and we have attempted the |
| 203 // connect with write. | 203 // connect with write. |
| 204 bool tcp_fastopen_write_attempted_; | 204 bool tcp_fastopen_write_attempted_; |
| 205 | 205 |
| 206 // True when TCP FastOpen is in use and we have done the connect. | 206 // True when TCP FastOpen is in use and we have done the connect. |
| 207 bool tcp_fastopen_connected_; | 207 bool tcp_fastopen_connected_; |
| 208 | 208 |
| 209 TCPFastOpenStatus tcp_fastopen_status_; | 209 TCPFastOpenStatus tcp_fastopen_status_; |
| 210 | 210 |
| 211 bool logging_multiple_connect_attempts_; | 211 bool logging_multiple_connect_attempts_; |
| 212 | 212 |
| 213 BoundNetLog net_log_; | 213 BoundNetLog net_log_; |
| 214 | 214 |
| 215 DISALLOW_COPY_AND_ASSIGN(TCPSocketLibevent); | 215 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 } // namespace net | 218 } // namespace net |
| 219 | 219 |
| 220 #endif // NET_SOCKET_TCP_SOCKET_LIBEVENT_H_ | 220 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |
| OLD | NEW |