| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CLIENT_SOCKET_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
| 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | |
| 9 #include "net/base/net_export.h" | |
| 10 | |
| 11 // TODO(yzshen): Switch OS_POSIX to use the same platform-independent | |
| 12 // TCPClientSocket. | |
| 13 #if defined(OS_WIN) | |
| 14 | |
| 15 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 16 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 17 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 18 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
| 19 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
| 13 #include "net/base/net_export.h" |
| 20 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
| 21 #include "net/socket/stream_socket.h" | 15 #include "net/socket/stream_socket.h" |
| 22 #include "net/socket/tcp_socket.h" | 16 #include "net/socket/tcp_socket.h" |
| 23 | 17 |
| 24 #elif defined(OS_POSIX) | |
| 25 #include "net/socket/tcp_client_socket_libevent.h" | |
| 26 #endif | |
| 27 | |
| 28 namespace net { | 18 namespace net { |
| 29 | 19 |
| 30 // Enable/disable experimental TCP FastOpen option. | |
| 31 // Not thread safe. Must be called during initialization/startup only. | |
| 32 NET_EXPORT void SetTCPFastOpenEnabled(bool value); | |
| 33 | |
| 34 // Check if the TCP FastOpen option is enabled. | |
| 35 bool IsTCPFastOpenEnabled(); | |
| 36 | |
| 37 // A client socket that uses TCP as the transport layer. | 20 // A client socket that uses TCP as the transport layer. |
| 38 #if defined(OS_POSIX) | |
| 39 typedef TCPClientSocketLibevent TCPClientSocket; | |
| 40 #elif defined(OS_WIN) | |
| 41 | |
| 42 class NET_EXPORT TCPClientSocket : public StreamSocket { | 21 class NET_EXPORT TCPClientSocket : public StreamSocket { |
| 43 public: | 22 public: |
| 44 // The IP address(es) and port number to connect to. The TCP socket will try | 23 // The IP address(es) and port number to connect to. The TCP socket will try |
| 45 // each IP address in the list until it succeeds in establishing a | 24 // each IP address in the list until it succeeds in establishing a |
| 46 // connection. | 25 // connection. |
| 47 TCPClientSocket(const AddressList& addresses, | 26 TCPClientSocket(const AddressList& addresses, |
| 48 net::NetLog* net_log, | 27 net::NetLog* net_log, |
| 49 const net::NetLog::Source& source); | 28 const net::NetLog::Source& source); |
| 50 | 29 |
| 51 // Adopts the given, connected socket. This object takes ownership of the | 30 // Adopts the given, connected socket. This object takes ownership of the |
| 52 // given socket and then acts as if Connect() had been called. This function | 31 // given socket and then acts as if Connect() had been called. This function |
| 53 // is used by TCPServerSocket to adopt accepted connections and for testing. | 32 // is used by TCPServerSocket to adopt accepted connections and for testing. |
| 54 explicit TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, | 33 explicit TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, |
| 55 const IPEndPoint& peer_address); | 34 const IPEndPoint& peer_address); |
| 56 | 35 |
| 57 virtual ~TCPClientSocket(); | 36 virtual ~TCPClientSocket(); |
| 58 | 37 |
| 59 // Binds the socket to a local IP address and port. | 38 // Binds the socket to a local IP address and port. |
| 60 int Bind(const IPEndPoint& address); | 39 int Bind(const IPEndPoint& address); |
| 61 | 40 |
| 62 // StreamSocket implementation. | 41 // StreamSocket implementation. |
| 63 virtual int Connect(const CompletionCallback& callback); | 42 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 64 virtual void Disconnect(); | 43 virtual void Disconnect() OVERRIDE; |
| 65 virtual bool IsConnected() const; | 44 virtual bool IsConnected() const OVERRIDE; |
| 66 virtual bool IsConnectedAndIdle() const; | 45 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 67 virtual int GetPeerAddress(IPEndPoint* address) const; | 46 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 68 virtual int GetLocalAddress(IPEndPoint* address) const; | 47 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 69 virtual const BoundNetLog& NetLog() const { return socket_->net_log(); } | 48 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 70 virtual void SetSubresourceSpeculation(); | 49 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 71 virtual void SetOmniboxSpeculation(); | 50 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 72 virtual bool WasEverUsed() const; | 51 virtual bool WasEverUsed() const OVERRIDE; |
| 73 virtual bool UsingTCPFastOpen() const; | 52 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 74 virtual bool WasNpnNegotiated() const OVERRIDE; | 53 virtual bool WasNpnNegotiated() const OVERRIDE; |
| 75 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 54 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
| 76 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 55 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 77 | 56 |
| 78 // Socket implementation. | 57 // Socket implementation. |
| 79 // Multiple outstanding requests are not supported. | 58 // Multiple outstanding requests are not supported. |
| 80 // Full duplex mode (reading and writing at the same time) is supported | 59 // Full duplex mode (reading and writing at the same time) is supported |
| 81 virtual int Read(IOBuffer* buf, int buf_len, | 60 virtual int Read(IOBuffer* buf, int buf_len, |
| 82 const CompletionCallback& callback) OVERRIDE; | 61 const CompletionCallback& callback) OVERRIDE; |
| 83 virtual int Write(IOBuffer* buf, int buf_len, | 62 virtual int Write(IOBuffer* buf, int buf_len, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // This socket was previously disconnected and has not been re-connected. | 111 // This socket was previously disconnected and has not been re-connected. |
| 133 bool previously_disconnected_; | 112 bool previously_disconnected_; |
| 134 | 113 |
| 135 // Record of connectivity and transmissions, for use in speculative connection | 114 // Record of connectivity and transmissions, for use in speculative connection |
| 136 // histograms. | 115 // histograms. |
| 137 UseHistory use_history_; | 116 UseHistory use_history_; |
| 138 | 117 |
| 139 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); | 118 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); |
| 140 }; | 119 }; |
| 141 | 120 |
| 142 #endif | |
| 143 | |
| 144 } // namespace net | 121 } // namespace net |
| 145 | 122 |
| 146 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ | 123 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
| OLD | NEW |