Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
CStreamSocket Class Reference

#include <CStreamSocket.hpp>

Inheritance diagram for CStreamSocket:
[legend]
Collaboration diagram for CStreamSocket:
[legend]

Public Member Functions

 CStreamSocket ()=default
 
 CStreamSocket (socket_t handle)
 
 CStreamSocket (CStreamSocket &&sock) noexcept
 
CStreamSocketoperator= (CStreamSocket &&rhs) noexcept
 
ssize_t read (const std::vector< iovec > &ranges)
 
virtual ssize_t read (void *buf, size_t n)
 
virtual ssize_t read_n (void *buf, size_t n)
 
virtual ssize_t write (const std::string &s)
 
virtual ssize_t write (const std::vector< iovec > &ranges)
 
virtual ssize_t write (const void *buf, size_t n)
 
virtual ssize_t write_n (const void *buf, size_t n)
 
virtual bool setReadTimeout (const std::chrono::microseconds &to)
 
template<class Rep , class Period >
bool setReadTimeout (const std::chrono::duration< Rep, Period > &to)
 
virtual bool setWriteTimeout (const std::chrono::microseconds &to)
 
template<class Rep , class Period >
bool write_timeout (const std::chrono::duration< Rep, Period > &to)
 
bool operator! () const
 Operador de negación.
 
 operator bool () const
 Operador de conversión a bool.
 
virtual bool bind (const CSocketAddress &address)
 Asigna una dirección a un socket.
 
bool bind (const sockaddr *address, socklen_t len) const
 
bool isOpen () const
 Comprueba que el handle del socket sea válido.
 
socket_t release ()
 Pone a -1 el handle interno y devuelve el valor anterior. Al no invalidar el file descriptor del socket, se puede usar para desasociar el socket del Sistema Operativo de un objeto CSocket concreto.
 
void reset (socket_t handle=INVALID_SOCKET)
 Asigna un nuevo handle al socket e invalida el anterior.
 
CSocket clone () const
 Crea un nuevo objeto CSocket con el mismo handle que el actual.
 
bool close ()
 Cierra el socket.
 
virtual CSocketAddressAny getAddress () const
 
virtual CSocketAddressAny getPeerAddress () const
 
virtual sa_family_t getFamily () const
 
socket_t getHandle () const
 
void setLastError (int32_t err=INT32_MAX) const
 
std::string getLastErrorString () const
 
void clearLastError (int32_t value=0) const
 
bool getOption (int32_t level, int32_t optName, void *optVal, socklen_t *optLength) const
 
template<typename T >
bool getOption (const int32_t level, const int32_t optName, T *value) const
 
bool setOption (int32_t level, int32_t optName, const void *optVal, socklen_t optLength) const
 
template<typename T >
bool setOption (const int32_t level, const int32_t optName, const T &value)
 
bool setNonBlocking (bool on=true) const
 

Static Public Member Functions

static CStreamSocket create (int32_t domain, int32_t protocol=0)
 
static bool close (socket_t h)
 
static CSocket create (int32_t domain, int32_t type, int32_t protocol=0)
 
static std::tuple< CSocket, CSocketpair (int32_t domain, int32_t type, int32_t protocol=0)
 

Static Public Attributes

static constexpr int32_t COMM_TYPE = SOCK_STREAM
 

Protected Member Functions

template<typename T >
checkRet (T ret) const
 
template<typename T >
bool checkRetBool (T ret) const
 
socket_t checkSocket (socket_t ret) const
 
bool checkSocketBool (socket_t ret) const
 
bool closeOnError ()
 

Static Protected Member Functions

static socket_t createHandle (int32_t domain)
 
static int32_t getErrno ()
 Función que devuelve el valor actual de errno.
 

Protected Attributes

socket_t m_handle
 

Private Attributes

int32_t m_lastError
 

Friends

class CAcceptorSocket
 

Constructor & Destructor Documentation

◆ CStreamSocket() [1/3]

CStreamSocket::CStreamSocket ( )
default

◆ CStreamSocket() [2/3]

CStreamSocket::CStreamSocket ( socket_t handle)
inlineexplicit

◆ CStreamSocket() [3/3]

CStreamSocket::CStreamSocket ( CStreamSocket && sock)
inlinenoexcept

Member Function Documentation

◆ bind() [1/2]

bool CSocket::bind ( const CSocketAddress & address)
virtualinherited

Asigna una dirección a un socket.

Parameters
addressDirección a la que el socket se va a asociar.
Returns
true si se ha podido asignar la dirección, false en caso contrario.

◆ bind() [2/2]

bool CSocket::bind ( const sockaddr * address,
socklen_t len ) const
inherited

◆ checkRet()

template<typename T >
T CSocket::checkRet ( T ret) const
inlineprotectedinherited

◆ checkRetBool()

template<typename T >
bool CSocket::checkRetBool ( T ret) const
inlineprotectedinherited

◆ checkSocket()

socket_t CSocket::checkSocket ( socket_t ret) const
inlineprotectedinherited

◆ checkSocketBool()

bool CSocket::checkSocketBool ( socket_t ret) const
inlineprotectedinherited

◆ clearLastError()

void CSocket::clearLastError ( int32_t value = 0) const
inherited

◆ clone()

CSocket CSocket::clone ( ) const
inherited

Crea un nuevo objeto CSocket con el mismo handle que el actual.

Note
No invalida el handle del objeto actual.
Returns
Nuevo objeto CSocket con el mismo handle que el actual.

◆ close() [1/2]

bool CSocket::close ( )
inherited

Cierra el socket.

Returns
true si se ha cerrado correctamente, false en caso contrario.

◆ close() [2/2]

bool CSocket::close ( socket_t h)
staticinherited

◆ closeOnError()

bool CSocket::closeOnError ( )
inlineprotectedinherited

◆ create() [1/2]

CSocket CSocket::create ( int32_t domain,
int32_t type,
int32_t protocol = 0 )
staticinherited

◆ create() [2/2]

CStreamSocket CStreamSocket::create ( int32_t domain,
int32_t protocol = 0 )
static

◆ createHandle()

static socket_t CStreamSocket::createHandle ( int32_t domain)
inlinestaticprotected

◆ getAddress()

CSocketAddressAny CSocket::getAddress ( ) const
virtualinherited

◆ getErrno()

int32_t CSocket::getErrno ( )
staticprotectedinherited

Función que devuelve el valor actual de errno.

Note
Esta función es estática pero protected, por lo que puede ser llamada desde las clases derivadas sin necesidad de crear un objeto de tipo CSocket.
Returns
Valor actual de errno.

◆ getFamily()

sa_family_t CSocket::getFamily ( ) const
virtualinherited

◆ getHandle()

socket_t CSocket::getHandle ( ) const
inherited

◆ getLastErrorString()

std::string CSocket::getLastErrorString ( ) const
inherited

◆ getOption() [1/2]

template<typename T >
bool CSocket::getOption ( const int32_t level,
const int32_t optName,
T * value ) const
inlineinherited

◆ getOption() [2/2]

bool CSocket::getOption ( int32_t level,
int32_t optName,
void * optVal,
socklen_t * optLength ) const
inherited

◆ getPeerAddress()

CSocketAddressAny CSocket::getPeerAddress ( ) const
virtualinherited

◆ isOpen()

bool CSocket::isOpen ( ) const
inherited

Comprueba que el handle del socket sea válido.

Returns
true si el handle es distinto de INVALID_SOCKET, false en caso contrario.

◆ operator bool()

CSocket::operator bool ( ) const
explicitinherited

Operador de conversión a bool.

Returns
true si el socket es válido y no hay ningún error, false en caso contrario.

◆ operator!()

bool CSocket::operator! ( ) const
inherited

Operador de negación.

Returns
true si el socket es válido o hay algún error, false en caso contrario.

◆ operator=()

CStreamSocket & CStreamSocket::operator= ( CStreamSocket && rhs)
inlinenoexcept

◆ pair()

std::tuple< CSocket, CSocket > CSocket::pair ( int32_t domain,
int32_t type,
int32_t protocol = 0 )
staticinherited

◆ read() [1/2]

ssize_t CStreamSocket::read ( const std::vector< iovec > & ranges)

◆ read() [2/2]

ssize_t CStreamSocket::read ( void * buf,
size_t n )
virtual

◆ read_n()

ssize_t CStreamSocket::read_n ( void * buf,
size_t n )
virtual

◆ release()

socket_t CSocket::release ( )
inherited

Pone a -1 el handle interno y devuelve el valor anterior. Al no invalidar el file descriptor del socket, se puede usar para desasociar el socket del Sistema Operativo de un objeto CSocket concreto.

Returns
Valor del handle anterior.

◆ reset()

void CSocket::reset ( socket_t handle = INVALID_SOCKET)
inherited

Asigna un nuevo handle al socket e invalida el anterior.

Parameters
handleNuevo handle a asignar.

◆ setLastError()

void CSocket::setLastError ( int32_t err = INT32_MAX) const
inherited

◆ setNonBlocking()

bool CSocket::setNonBlocking ( bool on = true) const
inherited

◆ setOption() [1/2]

template<typename T >
bool CSocket::setOption ( const int32_t level,
const int32_t optName,
const T & value )
inlineinherited

◆ setOption() [2/2]

bool CSocket::setOption ( int32_t level,
int32_t optName,
const void * optVal,
socklen_t optLength ) const
inherited

◆ setReadTimeout() [1/2]

template<class Rep , class Period >
bool CStreamSocket::setReadTimeout ( const std::chrono::duration< Rep, Period > & to)
inline

◆ setReadTimeout() [2/2]

bool CStreamSocket::setReadTimeout ( const std::chrono::microseconds & to)
virtual

◆ setWriteTimeout()

bool CStreamSocket::setWriteTimeout ( const std::chrono::microseconds & to)
virtual

◆ write() [1/3]

virtual ssize_t CStreamSocket::write ( const std::string & s)
inlinevirtual

◆ write() [2/3]

ssize_t CStreamSocket::write ( const std::vector< iovec > & ranges)
virtual

◆ write() [3/3]

ssize_t CStreamSocket::write ( const void * buf,
size_t n )
virtual

◆ write_n()

ssize_t CStreamSocket::write_n ( const void * buf,
size_t n )
virtual

◆ write_timeout()

template<class Rep , class Period >
bool CStreamSocket::write_timeout ( const std::chrono::duration< Rep, Period > & to)
inline

Friends And Related Symbol Documentation

◆ CAcceptorSocket

friend class CAcceptorSocket
friend

Member Data Documentation

◆ COMM_TYPE

int32_t CStreamSocket::COMM_TYPE = SOCK_STREAM
staticconstexpr

◆ m_handle

socket_t CSocket::m_handle
protectedinherited

◆ m_lastError

int32_t CSocket::m_lastError
mutableprivateinherited

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