xrootd
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
XrdCl::Socket Class Reference

A network socket. More...

#include <XrdClSocket.hh>

Collaboration diagram for XrdCl::Socket:
Collaboration graph
[legend]

Public Types

enum  SocketStatus { Disconnected = 1 , Connected = 2 , Connecting = 3 }
 Status of the socket. More...
 

Public Member Functions

 Socket (int socket=-1, SocketStatus status=Disconnected)
 
virtual ~Socket ()
 Desctuctor.
 
XRootDStatus Initialize (int family=AF_INET)
 Initialize the socket.
 
XRootDStatus SetFlags (int flags)
 Set the socket flags (man fcntl)
 
XRootDStatus GetFlags (int &flags)
 Get the socket flags (man fcntl)
 
XRootDStatus GetSockOpt (int level, int optname, void *optval, socklen_t *optlen)
 Get socket options.
 
XRootDStatus SetSockOpt (int level, int optname, const void *optval, socklen_t optlen)
 Set socket options.
 
XRootDStatus Connect (const std::string &host, uint16_t port, uint16_t timout=10)
 
XRootDStatus ConnectToAddress (const XrdNetAddr &addr, uint16_t timout=10)
 
void Close ()
 Disconnect.
 
SocketStatus GetStatus () const
 Get the socket status.
 
void SetStatus (SocketStatus status)
 Set socket status - do not use unless you know what you're doing.
 
XRootDStatus ReadRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesRead)
 
XRootDStatus WriteRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesWritten)
 
virtual XRootDStatus Send (const char *buffer, size_t size, int &bytesWritten)
 
XRootDStatus Send (XrdSys::KernelBuffer &kbuff, int &bytesWritten)
 
XRootDStatus Send (Message &msg, const std::string &strmname)
 
virtual XRootDStatus Read (char *buffer, size_t size, int &bytesRead)
 
XRootDStatus ReadV (iovec *iov, int iocnt, int &bytesRead)
 
int GetFD ()
 Get the file descriptor.
 
std::string GetSockName () const
 Get the name of the socket.
 
std::string GetPeerName () const
 Get the name of the remote peer.
 
std::string GetName () const
 Get the string representation of the socket.
 
const XrdNetAddrGetServerAddress () const
 Get the server address.
 
void SetChannelID (AnyObject *channelID)
 
const AnyObjectGetChannelID () const
 
XRootDStatus Cork ()
 
XRootDStatus Uncork ()
 
XRootDStatus Flash ()
 
bool IsCorked () const
 
uint8_t MapEvent (uint8_t event)
 
XRootDStatus TlsHandShake (AsyncSocketHandler *socketHandler, const std::string &thehost=std::string())
 
bool IsEncrypted ()
 

Static Public Member Functions

static XRootDStatus ClassifyErrno (int error)
 

Protected Member Functions

XRootDStatus Poll (bool readyForReading, bool readyForWriting, int32_t timeout)
 

Protected Attributes

int pSocket
 
SocketStatus pStatus
 
std::unique_ptr< XrdNetAddrpServerAddr
 
std::string pSockName
 
std::string pPeerName
 
std::string pName
 
int pProtocolFamily
 
AnyObjectpChannelID
 
bool pCorked
 
std::unique_ptr< TlspTls
 

Detailed Description

A network socket.

Member Enumeration Documentation

◆ SocketStatus

Status of the socket.

Enumerator
Disconnected 

The socket is disconnected.

Connected 

The socket is connected.

Connecting 

The connection process is in progress.

Constructor & Destructor Documentation

◆ Socket()

XrdCl::Socket::Socket ( int  socket = -1,
SocketStatus  status = Disconnected 
)

Constructor

Parameters
socketalready connected socket if available, -1 otherwise
statusstatus of a socket if available

◆ ~Socket()

virtual XrdCl::Socket::~Socket ( )
virtual

Desctuctor.

Member Function Documentation

◆ ClassifyErrno()

static XRootDStatus XrdCl::Socket::ClassifyErrno ( int  error)
static

◆ Close()

void XrdCl::Socket::Close ( )

Disconnect.

◆ Connect()

XRootDStatus XrdCl::Socket::Connect ( const std::string &  host,
uint16_t  port,
uint16_t  timout = 10 
)

Connect to the given host name

Parameters
hostname of the host to connect to
portport to connect to
timouttimeout in seconds, 0 for no timeout handling (may be used for non blocking IO)

◆ ConnectToAddress()

XRootDStatus XrdCl::Socket::ConnectToAddress ( const XrdNetAddr addr,
uint16_t  timout = 10 
)

Connect to the given host address

Parameters
addraddress of the host to connect to
timouttimeout in seconds, 0 for no timeout handling (may be used for non blocking IO)

◆ Cork()

XRootDStatus XrdCl::Socket::Cork ( )

◆ Flash()

XRootDStatus XrdCl::Socket::Flash ( )

◆ GetChannelID()

const AnyObject * XrdCl::Socket::GetChannelID ( ) const
inline

Get Channel ID (an object that allows to identify all sockets corresponding to the same channel)

References pChannelID.

◆ GetFD()

int XrdCl::Socket::GetFD ( )
inline

Get the file descriptor.

References pSocket.

◆ GetFlags()

XRootDStatus XrdCl::Socket::GetFlags ( int &  flags)

Get the socket flags (man fcntl)

◆ GetName()

std::string XrdCl::Socket::GetName ( ) const

Get the string representation of the socket.

◆ GetPeerName()

std::string XrdCl::Socket::GetPeerName ( ) const

Get the name of the remote peer.

◆ GetServerAddress()

const XrdNetAddr * XrdCl::Socket::GetServerAddress ( ) const
inline

Get the server address.

References pServerAddr.

◆ GetSockName()

std::string XrdCl::Socket::GetSockName ( ) const

Get the name of the socket.

◆ GetSockOpt()

XRootDStatus XrdCl::Socket::GetSockOpt ( int  level,
int  optname,
void *  optval,
socklen_t *  optlen 
)

Get socket options.

◆ GetStatus()

SocketStatus XrdCl::Socket::GetStatus ( ) const
inline

Get the socket status.

References pStatus.

◆ Initialize()

XRootDStatus XrdCl::Socket::Initialize ( int  family = AF_INET)

Initialize the socket.

◆ IsCorked()

bool XrdCl::Socket::IsCorked ( ) const
inline

References pCorked.

◆ IsEncrypted()

bool XrdCl::Socket::IsEncrypted ( )

◆ MapEvent()

uint8_t XrdCl::Socket::MapEvent ( uint8_t  event)

◆ Poll()

XRootDStatus XrdCl::Socket::Poll ( bool  readyForReading,
bool  readyForWriting,
int32_t  timeout 
)
protected

Poll the socket to see whether it is ready for IO

Parameters
readyForReadingpoll for readiness to read
readyForWritingpoll for readiness to write
timeouttimeout in seconds, -1 to wait indefinitely
Returns
stOK - ready for IO errSocketDisconnected - on disconnection errSocketError - on socket error errSocketTimeout - on socket timeout errInvalidOp - when called on a non connected socket

◆ Read()

virtual XRootDStatus XrdCl::Socket::Read ( char *  buffer,
size_t  size,
int &  bytesRead 
)
virtual

Read helper for raw socket

Parameters
buffer: the sink for the data
size: size of the sink
bytesRead: number of bytes actually written into the sink
Returns
: success : ( stOK ) EAGAIN : ( stOK, suRetry ) EWOULDBLOCK : ( stOK, suRetry ) other error : ( stError, errSocketError )

Referenced by XrdCl::AsyncMsgReader::ReadAttnActnum(), and XrdCl::AsyncRawReaderIntfc::ReadBytesAsync().

◆ ReadRaw()

XRootDStatus XrdCl::Socket::ReadRaw ( void *  buffer,
uint32_t  size,
int32_t  timeout,
uint32_t &  bytesRead 
)

Read raw bytes from the socket

Parameters
bufferdata to be sent
sizesize of the data buffer
timeouttimout value in seconds, -1 to wait indefinitely
bytesReadthe amount of data actually read

◆ ReadV()

XRootDStatus XrdCl::Socket::ReadV ( iovec *  iov,
int  iocnt,
int &  bytesRead 
)

ReadV helper for raw socket

Parameters
iov: the buffers for the data
iocnt: number of buffers
bytesRead: number of bytes actually written into the sink
Returns
: success : ( stOK ) EAGAIN : ( stOK, suRetry ) EWOULDBLOCK : ( stOK, suRetry ) other error : ( stError, errSocketError )

Referenced by XrdCl::AsyncPageReader::Read().

◆ Send() [1/3]

virtual XRootDStatus XrdCl::Socket::Send ( const char *  buffer,
size_t  size,
int &  bytesWritten 
)
virtual

Portable wrapper around SIGPIPE free send

Parameters
buffer: data to be written
size: size of the data buffer
bytesWritten: the amount of data actually written

Referenced by XrdCl::AsyncHSWriter::Write(), and XrdCl::AsyncMsgWriter::Write().

◆ Send() [2/3]

XRootDStatus XrdCl::Socket::Send ( Message msg,
const std::string &  strmname 
)

Write message to the socket

Parameters
msg: message (request) to be sent
strmname: stream name (for logging purposes)

◆ Send() [3/3]

XRootDStatus XrdCl::Socket::Send ( XrdSys::KernelBuffer kbuff,
int &  bytesWritten 
)

Write data from a kernel buffer to the socket

Parameters
kbuff: data to be written
bytesWritten: the amount of data actually written

◆ SetChannelID()

void XrdCl::Socket::SetChannelID ( AnyObject channelID)
inline

Set Channel ID (an object that allows to identify all sockets corresponding to the same channel)

References pChannelID.

◆ SetFlags()

XRootDStatus XrdCl::Socket::SetFlags ( int  flags)

Set the socket flags (man fcntl)

◆ SetSockOpt()

XRootDStatus XrdCl::Socket::SetSockOpt ( int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

Set socket options.

◆ SetStatus()

void XrdCl::Socket::SetStatus ( SocketStatus  status)
inline

Set socket status - do not use unless you know what you're doing.

References pStatus.

◆ TlsHandShake()

XRootDStatus XrdCl::Socket::TlsHandShake ( AsyncSocketHandler socketHandler,
const std::string &  thehost = std::string() 
)

◆ Uncork()

XRootDStatus XrdCl::Socket::Uncork ( )

◆ WriteRaw()

XRootDStatus XrdCl::Socket::WriteRaw ( void *  buffer,
uint32_t  size,
int32_t  timeout,
uint32_t &  bytesWritten 
)

Write raw bytes to the socket

Parameters
bufferdata to be written
sizesize of the data buffer
timeouttimeout value in seconds, -1 to wait indefinitely
bytesWrittenthe amount of data actually written

Member Data Documentation

◆ pChannelID

AnyObject* XrdCl::Socket::pChannelID
protected

Referenced by GetChannelID(), and SetChannelID().

◆ pCorked

bool XrdCl::Socket::pCorked
protected

Referenced by IsCorked().

◆ pName

std::string XrdCl::Socket::pName
mutableprotected

◆ pPeerName

std::string XrdCl::Socket::pPeerName
mutableprotected

◆ pProtocolFamily

int XrdCl::Socket::pProtocolFamily
protected

◆ pServerAddr

std::unique_ptr<XrdNetAddr> XrdCl::Socket::pServerAddr
protected

Referenced by GetServerAddress().

◆ pSocket

int XrdCl::Socket::pSocket
protected

Referenced by GetFD().

◆ pSockName

std::string XrdCl::Socket::pSockName
mutableprotected

◆ pStatus

SocketStatus XrdCl::Socket::pStatus
protected

Referenced by GetStatus(), and SetStatus().

◆ pTls

std::unique_ptr<Tls> XrdCl::Socket::pTls
protected

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