| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_CLIENT_SOCKET_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_H_ |
| 6 #define NET_SOCKET_CLIENT_SOCKET_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_LINUX) || defined(OS_MACOSX) | 10 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "net/socket/socket.h" | 14 #include "net/socket/socket.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 class LoadLog; |
| 19 |
| 18 class ClientSocket : public Socket { | 20 class ClientSocket : public Socket { |
| 19 public: | 21 public: |
| 20 // Called to establish a connection. Returns OK if the connection could be | 22 // Called to establish a connection. Returns OK if the connection could be |
| 21 // established synchronously. Otherwise, ERR_IO_PENDING is returned and the | 23 // established synchronously. Otherwise, ERR_IO_PENDING is returned and the |
| 22 // given callback will run asynchronously when the connection is established | 24 // given callback will run asynchronously when the connection is established |
| 23 // or when an error occurs. The result is some other error code if the | 25 // or when an error occurs. The result is some other error code if the |
| 24 // connection could not be established. | 26 // connection could not be established. |
| 25 // | 27 // |
| 26 // The socket's Read and Write methods may not be called until Connect | 28 // The socket's Read and Write methods may not be called until Connect |
| 27 // succeeds. | 29 // succeeds. |
| 28 // | 30 // |
| 29 // It is valid to call Connect on an already connected socket, in which case | 31 // It is valid to call Connect on an already connected socket, in which case |
| 30 // OK is simply returned. | 32 // OK is simply returned. |
| 31 // | 33 // |
| 32 // Connect may also be called again after a call to the Disconnect method. | 34 // Connect may also be called again after a call to the Disconnect method. |
| 33 // | 35 // |
| 34 virtual int Connect(CompletionCallback* callback) = 0; | 36 virtual int Connect(CompletionCallback* callback, LoadLog* load_log) = 0; |
| 35 | 37 |
| 36 // Called to disconnect a socket. Does nothing if the socket is already | 38 // Called to disconnect a socket. Does nothing if the socket is already |
| 37 // disconnected. After calling Disconnect it is possible to call Connect | 39 // disconnected. After calling Disconnect it is possible to call Connect |
| 38 // again to establish a new connection. | 40 // again to establish a new connection. |
| 39 // | 41 // |
| 40 // If IO (Connect, Read, or Write) is pending when the socket is | 42 // If IO (Connect, Read, or Write) is pending when the socket is |
| 41 // disconnected, the pending IO is cancelled, and the completion callback | 43 // disconnected, the pending IO is cancelled, and the completion callback |
| 42 // will not be called. | 44 // will not be called. |
| 43 virtual void Disconnect() = 0; | 45 virtual void Disconnect() = 0; |
| 44 | 46 |
| 45 // Called to test if the connection is still alive. Returns false if a | 47 // Called to test if the connection is still alive. Returns false if a |
| 46 // connection wasn't established or the connection is dead. | 48 // connection wasn't established or the connection is dead. |
| 47 virtual bool IsConnected() const = 0; | 49 virtual bool IsConnected() const = 0; |
| 48 | 50 |
| 49 // Called to test if the connection is still alive and idle. Returns false | 51 // Called to test if the connection is still alive and idle. Returns false |
| 50 // if a connection wasn't established, the connection is dead, or some data | 52 // if a connection wasn't established, the connection is dead, or some data |
| 51 // have been received. | 53 // have been received. |
| 52 virtual bool IsConnectedAndIdle() const = 0; | 54 virtual bool IsConnectedAndIdle() const = 0; |
| 53 | 55 |
| 54 #if defined(OS_LINUX) || defined(OS_MACOSX) | 56 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 55 // Identical to posix system call getpeername(). | 57 // Identical to posix system call getpeername(). |
| 56 // Needed by ssl_client_socket_nss and ssl_client_socket_mac. | 58 // Needed by ssl_client_socket_nss and ssl_client_socket_mac. |
| 57 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); | 59 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); |
| 58 #endif | 60 #endif |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 } // namespace net | 63 } // namespace net |
| 62 | 64 |
| 63 #endif // NET_SOCKET_CLIENT_SOCKET_H_ | 65 #endif // NET_SOCKET_CLIENT_SOCKET_H_ |
| OLD | NEW |