Android-cuttlefish cvd tool
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Socket Class Referenceabstract

#include <socket.h>

Inheritance diagram for Socket:
Inheritance graph
[legend]

Public Types

enum class  Protocol { kTcp , kUdp }
 

Public Member Functions

virtual ~Socket ()
 
virtual bool Send (const void *data, size_t length)=0
 
virtual bool Send (std::vector< cutils_socket_buffer_t > buffers)=0
 
virtual ssize_t Receive (void *data, size_t length, int timeout_ms)=0
 
virtual ssize_t ReceiveAll (void *data, size_t length, int timeout_ms)
 
bool ReceiveTimedOut ()
 
virtual int Close ()
 
virtual std::unique_ptr< SocketAccept ()
 
int GetLocalPort ()
 

Static Public Member Functions

static std::string GetErrorMessage ()
 
static std::unique_ptr< SocketNewClient (Protocol protocol, const std::string &hostname, int port, std::string *error)
 
static std::unique_ptr< SocketNewServer (Protocol protocol, int port)
 

Protected Member Functions

 Socket (cutils_socket_t sock)
 
bool WaitForRecv (int timeout_ms)
 

Protected Attributes

cutils_socket_t sock_ = INVALID_SOCKET
 
bool receive_timed_out_ = false
 
std::function< ssize_t(cutils_socket_t, cutils_socket_buffer_t *, size_t)> socket_send_buffers_function_ = &socket_send_buffers
 

Private Member Functions

 FRIEND_TEST (SocketTest, TestTcpSendBuffers)
 
 FRIEND_TEST (SocketTest, TestUdpSendBuffers)
 
 DISALLOW_COPY_AND_ASSIGN (Socket)
 

Member Enumeration Documentation

◆ Protocol

enum class Socket::Protocol
strong
Enumerator
kTcp 
kUdp 

Constructor & Destructor Documentation

◆ ~Socket()

Socket::~Socket ( )
virtual

◆ Socket()

Socket::Socket ( cutils_socket_t  sock)
explicitprotected

Member Function Documentation

◆ Accept()

virtual std::unique_ptr< Socket > Socket::Accept ( )
inlinevirtual

Reimplemented in TcpSocket.

◆ Close()

int Socket::Close ( )
virtual

◆ DISALLOW_COPY_AND_ASSIGN()

Socket::DISALLOW_COPY_AND_ASSIGN ( Socket  )
private

◆ FRIEND_TEST() [1/2]

Socket::FRIEND_TEST ( SocketTest  ,
TestTcpSendBuffers   
)
private

◆ FRIEND_TEST() [2/2]

Socket::FRIEND_TEST ( SocketTest  ,
TestUdpSendBuffers   
)
private

◆ GetErrorMessage()

std::string Socket::GetErrorMessage ( )
static

◆ GetLocalPort()

int Socket::GetLocalPort ( )

◆ NewClient()

std::unique_ptr< Socket > Socket::NewClient ( Protocol  protocol,
const std::string &  hostname,
int  port,
std::string *  error 
)
static

◆ NewServer()

std::unique_ptr< Socket > Socket::NewServer ( Protocol  protocol,
int  port 
)
static

◆ Receive()

virtual ssize_t Socket::Receive ( void *  data,
size_t  length,
int  timeout_ms 
)
pure virtual

Implemented in UdpSocket, and TcpSocket.

◆ ReceiveAll()

ssize_t Socket::ReceiveAll ( void *  data,
size_t  length,
int  timeout_ms 
)
virtual

◆ ReceiveTimedOut()

bool Socket::ReceiveTimedOut ( )
inline

◆ Send() [1/2]

virtual bool Socket::Send ( const void *  data,
size_t  length 
)
pure virtual

Implemented in UdpSocket, and TcpSocket.

◆ Send() [2/2]

virtual bool Socket::Send ( std::vector< cutils_socket_buffer_t >  buffers)
pure virtual

Implemented in UdpSocket, and TcpSocket.

◆ WaitForRecv()

bool Socket::WaitForRecv ( int  timeout_ms)
protected

Member Data Documentation

◆ receive_timed_out_

bool Socket::receive_timed_out_ = false
protected

◆ sock_

cutils_socket_t Socket::sock_ = INVALID_SOCKET
protected

◆ socket_send_buffers_function_

std::function<ssize_t(cutils_socket_t, cutils_socket_buffer_t*, size_t)> Socket::socket_send_buffers_function_ = &socket_send_buffers
protected

The documentation for this class was generated from the following files: