Apache Mesos
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
process::network::internal::SocketImpl Class Referenceabstract

Implementation interface for a Socket. More...

#include <socket.hpp>

Inheritance diagram for process::network::internal::SocketImpl:
process::network::internal::LibeventSSLSocketImpl process::network::internal::PollSocketImpl

Public Types

enum  Kind { Kind::POLL }
 Available kinds of implementations. More...
 

Public Member Functions

virtual ~SocketImpl ()
 
int_fd get () const
 Returns the file descriptor wrapped by this implementation. More...
 
Try< Addressaddress () const
 Returns the Address with the assigned ip and assigned port. More...
 
Try< Addresspeer () const
 Returns the peer's Address for the accepted or connected socket. More...
 
Try< Addressbind (const Address &address)
 Assigns the specified address to the socket. More...
 
virtual Try< Nothinglisten (int backlog)=0
 
virtual Future
< std::shared_ptr< SocketImpl > > 
accept ()=0
 Returns an implementation corresponding to the next pending connection for the listening socket. More...
 
virtual Future< Nothingconnect (const Address &address)=0
 
virtual Future< size_t > recv (char *data, size_t size)=0
 
virtual Future< size_t > send (const char *data, size_t size)=0
 
virtual Future< size_t > sendfile (int_fd fd, off_t offset, size_t size)=0
 
virtual Future< std::string > recv (const Option< ssize_t > &size=None())
 An overload of recv, which receives data based on the specified 'size' parameter. More...
 
virtual Future< Nothingsend (const std::string &data)
 An overload of send, which sends all of the specified data. More...
 
virtual Try< Nothingshutdown (int how)
 Shuts down the socket. More...
 
virtual Kind kind () const =0
 

Static Public Member Functions

static Kind DEFAULT_KIND ()
 Returns the default Kind of implementation. More...
 
static Try< std::shared_ptr
< SocketImpl > > 
create (int_fd s, Kind kind=DEFAULT_KIND())
 Returns an instance of a SocketImpl using the specified kind of implementation. More...
 
static Try< std::shared_ptr
< SocketImpl > > 
create (Address::Family family, Kind kind=DEFAULT_KIND())
 Returns an instance of a SocketImpl using the specified kind of implementation. More...
 

Protected Member Functions

 SocketImpl (int_fd _s)
 
int_fd release ()
 Releases ownership of the file descriptor. More...
 

Static Protected Member Functions

template<typename T >
static std::shared_ptr< T > shared (T *t)
 Returns a std::shared_ptr<T> from this implementation. More...
 

Protected Attributes

int_fd s
 

Detailed Description

Implementation interface for a Socket.

Each socket is:

Multiple implementations are supported via the Pimpl pattern, rather than forcing each Socket implementation to do this themselves.

See Also
process::network::Socket
Pimpl pattern

Member Enumeration Documentation

Available kinds of implementations.

See Also
process::network::internal::PollSocketImpl
process::network::internal::LibeventSSLSocketImpl
Enumerator
POLL 

Constructor & Destructor Documentation

virtual process::network::internal::SocketImpl::~SocketImpl ( )
inlinevirtual
process::network::internal::SocketImpl::SocketImpl ( int_fd  _s)
inlineexplicitprotected

Member Function Documentation

virtual Future<std::shared_ptr<SocketImpl> > process::network::internal::SocketImpl::accept ( )
pure virtual

Returns an implementation corresponding to the next pending connection for the listening socket.

All implementations will set the NONBLOCK and CLOEXEC options on the returned socket.

TODO(josephw): MESOS-5729: Consider making the CLOEXEC option configurable by the caller of the interface.

Implemented in process::network::internal::LibeventSSLSocketImpl, and process::network::internal::PollSocketImpl.

Try<Address> process::network::internal::SocketImpl::address ( ) const

Returns the Address with the assigned ip and assigned port.

Returns
An Address or an error if the getsockname system call fails or the family type is not supported.
Try<Address> process::network::internal::SocketImpl::bind ( const Address address)

Assigns the specified address to the socket.

Returns
The assigned Address or an error if the bind system call fails.
virtual Future<Nothing> process::network::internal::SocketImpl::connect ( const Address address)
pure virtual
static Try<std::shared_ptr<SocketImpl> > process::network::internal::SocketImpl::create ( int_fd  s,
Kind  kind = DEFAULT_KIND() 
)
static

Returns an instance of a SocketImpl using the specified kind of implementation.

Parameters
s.The existing file descriptor to use.
kindOptional. The desired implementation.
Returns
An instance of a SocketImpl.
static Try<std::shared_ptr<SocketImpl> > process::network::internal::SocketImpl::create ( Address::Family  family,
Kind  kind = DEFAULT_KIND() 
)
static

Returns an instance of a SocketImpl using the specified kind of implementation.

The NONBLOCK and CLOEXEC options will be set on the underlying file descriptor for the socket.

Parameters
kindOptional. The desired implementation.
Returns
An instance of a SocketImpl.
static Kind process::network::internal::SocketImpl::DEFAULT_KIND ( )
static

Returns the default Kind of implementation.

int_fd process::network::internal::SocketImpl::get ( ) const
inline

Returns the file descriptor wrapped by this implementation.

virtual Kind process::network::internal::SocketImpl::kind ( ) const
pure virtual
virtual Try<Nothing> process::network::internal::SocketImpl::listen ( int  backlog)
pure virtual
Try<Address> process::network::internal::SocketImpl::peer ( ) const

Returns the peer's Address for the accepted or connected socket.

Returns
An Address or an error if the getpeername system call fails or the family type is not supported.
virtual Future<size_t> process::network::internal::SocketImpl::recv ( char *  data,
size_t  size 
)
pure virtual
virtual Future<std::string> process::network::internal::SocketImpl::recv ( const Option< ssize_t > &  size = None())
virtual

An overload of recv, which receives data based on the specified 'size' parameter.

Parameters
size
Value Semantics
0 Returns an empty string.
-1 Receives until EOF.
N Returns a string of size N.
'None' Returns a string of the available data.
If 'None' is specified, whenever data becomes available on the socket, that much data will be returned.
int_fd process::network::internal::SocketImpl::release ( )
inlineprotected

Releases ownership of the file descriptor.

Not exposed via the Socket interface as this is only intended to support Socket::Impl implementations that need to override the file descriptor ownership.

virtual Future<size_t> process::network::internal::SocketImpl::send ( const char *  data,
size_t  size 
)
pure virtual
virtual Future<Nothing> process::network::internal::SocketImpl::send ( const std::string &  data)
virtual

An overload of send, which sends all of the specified data.

Parameters
dataThe specified data to send.
Returns
Nothing or an error in case the sending fails.
virtual Future<size_t> process::network::internal::SocketImpl::sendfile ( int_fd  fd,
off_t  offset,
size_t  size 
)
pure virtual
template<typename T >
static std::shared_ptr<T> process::network::internal::SocketImpl::shared ( T *  t)
inlinestaticprotected

Returns a std::shared_ptr<T> from this implementation.

virtual Try<Nothing> process::network::internal::SocketImpl::shutdown ( int  how)
inlinevirtual

Shuts down the socket.

Accepts an integer which specifies the shutdown mode.

Reimplemented in process::network::internal::LibeventSSLSocketImpl.

Member Data Documentation

int_fd process::network::internal::SocketImpl::s
protected

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