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