OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 class ClientSocketFactory; | 24 class ClientSocketFactory; |
25 | 25 |
26 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)> | 26 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)> |
27 OnHostResolutionCallback; | 27 OnHostResolutionCallback; |
28 | 28 |
29 class NET_EXPORT_PRIVATE TransportSocketParams | 29 class NET_EXPORT_PRIVATE TransportSocketParams |
30 : public base::RefCounted<TransportSocketParams> { | 30 : public base::RefCounted<TransportSocketParams> { |
31 public: | 31 public: |
| 32 // CombineConnectAndWrite currently translates to using TCP FastOpen. |
| 33 // TCP FastOpen should not be used if the first write to the socket may |
| 34 // be non-idempotent, as the underlying socket could retransmit the data |
| 35 // on failure of the first transmission. |
| 36 // NOTE: Currently, COMBINE_CONNECT_AND_WRITE_DESIRED is used if the data in |
| 37 // the write is known to be idempotent, and COMBINE_CONNECT_AND_WRITE_DEFAULT |
| 38 // is used as a default for other cases (including non-idempotent writes). |
| 39 enum CombineConnectAndWritePolicy { |
| 40 COMBINE_CONNECT_AND_WRITE_DEFAULT, // Default policy, implemented in |
| 41 // TransportSocketParams constructor. |
| 42 COMBINE_CONNECT_AND_WRITE_DESIRED, // Combine if supported by socket. |
| 43 COMBINE_CONNECT_AND_WRITE_PROHIBITED // Do not combine. |
| 44 }; |
| 45 |
32 // |host_resolution_callback| will be invoked after the the hostname is | 46 // |host_resolution_callback| will be invoked after the the hostname is |
33 // resolved. If |host_resolution_callback| does not return OK, then the | 47 // resolved. If |host_resolution_callback| does not return OK, then the |
34 // connection will be aborted with that value. | 48 // connection will be aborted with that value. |combine_connect_and_write| |
| 49 // defines the policy for use of TCP FastOpen on this socket. |
35 TransportSocketParams( | 50 TransportSocketParams( |
36 const HostPortPair& host_port_pair, | 51 const HostPortPair& host_port_pair, |
37 bool disable_resolver_cache, | 52 bool disable_resolver_cache, |
38 bool ignore_limits, | 53 bool ignore_limits, |
39 const OnHostResolutionCallback& host_resolution_callback); | 54 const OnHostResolutionCallback& host_resolution_callback, |
| 55 CombineConnectAndWritePolicy combine_connect_and_write); |
40 | 56 |
41 const HostResolver::RequestInfo& destination() const { return destination_; } | 57 const HostResolver::RequestInfo& destination() const { return destination_; } |
42 bool ignore_limits() const { return ignore_limits_; } | 58 bool ignore_limits() const { return ignore_limits_; } |
43 const OnHostResolutionCallback& host_resolution_callback() const { | 59 const OnHostResolutionCallback& host_resolution_callback() const { |
44 return host_resolution_callback_; | 60 return host_resolution_callback_; |
45 } | 61 } |
46 | 62 |
| 63 CombineConnectAndWritePolicy combine_connect_and_write() const { |
| 64 return combine_connect_and_write_; |
| 65 } |
| 66 |
47 private: | 67 private: |
48 friend class base::RefCounted<TransportSocketParams>; | 68 friend class base::RefCounted<TransportSocketParams>; |
49 ~TransportSocketParams(); | 69 ~TransportSocketParams(); |
50 | 70 |
51 HostResolver::RequestInfo destination_; | 71 HostResolver::RequestInfo destination_; |
52 bool ignore_limits_; | 72 bool ignore_limits_; |
53 const OnHostResolutionCallback host_resolution_callback_; | 73 const OnHostResolutionCallback host_resolution_callback_; |
| 74 CombineConnectAndWritePolicy combine_connect_and_write_; |
54 | 75 |
55 DISALLOW_COPY_AND_ASSIGN(TransportSocketParams); | 76 DISALLOW_COPY_AND_ASSIGN(TransportSocketParams); |
56 }; | 77 }; |
57 | 78 |
58 // Common data and logic shared between TransportConnectJob and | 79 // Common data and logic shared between TransportConnectJob and |
59 // WebSocketTransportConnectJob. | 80 // WebSocketTransportConnectJob. |
60 class NET_EXPORT_PRIVATE TransportConnectJobHelper { | 81 class NET_EXPORT_PRIVATE TransportConnectJobHelper { |
61 public: | 82 public: |
62 enum State { | 83 enum State { |
63 STATE_RESOLVE_HOST, | 84 STATE_RESOLVE_HOST, |
(...skipping 19 matching lines...) Expand all Loading... |
83 ~TransportConnectJobHelper(); | 104 ~TransportConnectJobHelper(); |
84 | 105 |
85 ClientSocketFactory* client_socket_factory() { | 106 ClientSocketFactory* client_socket_factory() { |
86 return client_socket_factory_; | 107 return client_socket_factory_; |
87 } | 108 } |
88 | 109 |
89 const AddressList& addresses() const { return addresses_; } | 110 const AddressList& addresses() const { return addresses_; } |
90 State next_state() const { return next_state_; } | 111 State next_state() const { return next_state_; } |
91 void set_next_state(State next_state) { next_state_ = next_state; } | 112 void set_next_state(State next_state) { next_state_ = next_state; } |
92 CompletionCallback on_io_complete() const { return on_io_complete_; } | 113 CompletionCallback on_io_complete() const { return on_io_complete_; } |
| 114 const TransportSocketParams* params() { return params_.get(); } |
93 | 115 |
94 int DoResolveHost(RequestPriority priority, const BoundNetLog& net_log); | 116 int DoResolveHost(RequestPriority priority, const BoundNetLog& net_log); |
95 int DoResolveHostComplete(int result, const BoundNetLog& net_log); | 117 int DoResolveHostComplete(int result, const BoundNetLog& net_log); |
96 | 118 |
97 template <class T> | 119 template <class T> |
98 int DoConnectInternal(T* job); | 120 int DoConnectInternal(T* job); |
99 | 121 |
100 template <class T> | 122 template <class T> |
101 void SetOnIOComplete(T* job); | 123 void SetOnIOComplete(T* job); |
102 | 124 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 break; | 355 break; |
334 } | 356 } |
335 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 357 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
336 | 358 |
337 return rv; | 359 return rv; |
338 } | 360 } |
339 | 361 |
340 } // namespace net | 362 } // namespace net |
341 | 363 |
342 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 364 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |