OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BASE_CLIENT_SOCKET_HANDLE_H_ | 5 #ifndef NET_BASE_CLIENT_SOCKET_HANDLE_H_ |
6 #define NET_BASE_CLIENT_SOCKET_HANDLE_H_ | 6 #define NET_BASE_CLIENT_SOCKET_HANDLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "net/base/client_socket.h" | 12 #include "net/base/client_socket.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/host_resolver.h" |
14 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 class ClientSocketPool; | 19 class ClientSocketPool; |
19 | 20 |
20 // A container for a ClientSocket. | 21 // A container for a ClientSocket. |
21 // | 22 // |
22 // The handle's |group_name| uniquely identifies the origin and type of the | 23 // The handle's |group_name| uniquely identifies the origin and type of the |
23 // connection. It is used by the ClientSocketPool to group similar connected | 24 // connection. It is used by the ClientSocketPool to group similar connected |
24 // client socket objects. | 25 // client socket objects. |
25 // | 26 // |
26 class ClientSocketHandle { | 27 class ClientSocketHandle { |
27 public: | 28 public: |
28 explicit ClientSocketHandle(ClientSocketPool* pool); | 29 explicit ClientSocketHandle(ClientSocketPool* pool); |
29 ~ClientSocketHandle(); | 30 ~ClientSocketHandle(); |
30 | 31 |
31 // Initializes a ClientSocketHandle object, which involves talking to the | 32 // Initializes a ClientSocketHandle object, which involves talking to the |
32 // ClientSocketPool to obtain a connected socket, possibly reusing one. This | 33 // ClientSocketPool to obtain a connected socket, possibly reusing one. This |
33 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| | 34 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| |
34 // is used to determine the placement in ClientSocketPool's wait list. | 35 // is used to determine the placement in ClientSocketPool's wait list. |
35 // | 36 // |
36 // If this method succeeds, then the socket member will be set to an existing | 37 // If this method succeeds, then the socket member will be set to an existing |
37 // connected socket if an existing connected socket was available to reuse, | 38 // connected socket if an existing connected socket was available to reuse, |
38 // otherwise it will be set to a new connected socket. Consumers can then | 39 // otherwise it will be set to a new connected socket. Consumers can then |
39 // call is_reused() to see if the socket was reused. If not reusing an | 40 // call is_reused() to see if the socket was reused. If not reusing an |
40 // existing socket, ClientSocketPool may need to establish a new | 41 // existing socket, ClientSocketPool may need to establish a new |
41 // connection to the |host| |port| pair. | 42 // connection to the |resolve_info.host| |resolve_info.port| pair. |
42 // | 43 // |
43 // This method returns ERR_IO_PENDING if it cannot complete synchronously, in | 44 // This method returns ERR_IO_PENDING if it cannot complete synchronously, in |
44 // which case the consumer will be notified of completion via |callback|. | 45 // which case the consumer will be notified of completion via |callback|. |
45 // | 46 // |
46 // Init may be called multiple times. | 47 // Init may be called multiple times. |
47 // | 48 // |
48 int Init(const std::string& group_name, | 49 int Init(const std::string& group_name, |
49 const std::string& host, | 50 const HostResolver::RequestInfo& resolve_info, |
50 int port, | |
51 int priority, | 51 int priority, |
52 CompletionCallback* callback); | 52 CompletionCallback* callback); |
53 | 53 |
54 // An initialized handle can be reset, which causes it to return to the | 54 // An initialized handle can be reset, which causes it to return to the |
55 // un-initialized state. This releases the underlying socket, which in the | 55 // un-initialized state. This releases the underlying socket, which in the |
56 // case of a socket that still has an established connection, indicates that | 56 // case of a socket that still has an established connection, indicates that |
57 // the socket may be kept alive for use by a subsequent ClientSocketHandle. | 57 // the socket may be kept alive for use by a subsequent ClientSocketHandle. |
58 // | 58 // |
59 // NOTE: To prevent the socket from being kept alive, be sure to call its | 59 // NOTE: To prevent the socket from being kept alive, be sure to call its |
60 // Disconnect method. This will result in the ClientSocketPool deleting the | 60 // Disconnect method. This will result in the ClientSocketPool deleting the |
(...skipping 30 matching lines...) Expand all Loading... |
91 bool is_reused_; | 91 bool is_reused_; |
92 CompletionCallbackImpl<ClientSocketHandle> callback_; | 92 CompletionCallbackImpl<ClientSocketHandle> callback_; |
93 CompletionCallback* user_callback_; | 93 CompletionCallback* user_callback_; |
94 | 94 |
95 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); | 95 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); |
96 }; | 96 }; |
97 | 97 |
98 } // namespace net | 98 } // namespace net |
99 | 99 |
100 #endif // NET_BASE_CLIENT_SOCKET_HANDLE_H_ | 100 #endif // NET_BASE_CLIENT_SOCKET_HANDLE_H_ |
OLD | NEW |