xrootd
Public Types | Public Member Functions | Private Member Functions | Private 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. More...
 
Status Initialize (int family=AF_INET)
 Initialize the socket. More...
 
Status SetFlags (int flags)
 Set the socket flags (man fcntl) More...
 
Status GetFlags (int &flags)
 Get the socket flags (man fcntl) More...
 
Status GetSockOpt (int level, int optname, void *optval, socklen_t *optlen)
 Get socket options. More...
 
Status SetSockOpt (int level, int optname, const void *optval, socklen_t optlen)
 Set socket options. More...
 
Status Connect (const std::string &host, uint16_t port, uint16_t timout=10)
 
Status ConnectToAddress (const XrdNetAddr &addr, uint16_t timout=10)
 
void Close ()
 Disconnect. More...
 
SocketStatus GetStatus () const
 Get the socket status. More...
 
void SetStatus (SocketStatus status)
 Set socket status - do not use unless you know what you're doing. More...
 
Status ReadRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesRead)
 
Status WriteRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesWritten)
 
ssize_t Send (void *buffer, uint32_t size)
 
ssize_t WriteV (iovec *iov, int iovcnt)
 
int GetFD ()
 Get the file descriptor. More...
 
std::string GetSockName () const
 Get the name of the socket. More...
 
std::string GetPeerName () const
 Get the name of the remote peer. More...
 
std::string GetName () const
 Get the string representation of the socket. More...
 
const XrdNetAddrGetServerAddress () const
 Get the server address. More...
 
void SetChannelID (AnyObject *channelID)
 
const AnyObjectGetChannelID () const
 

Private Member Functions

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

Private Attributes

int pSocket
 
SocketStatus pStatus
 
XrdNetAddr pServerAddr
 
std::string pSockName
 
std::string pPeerName
 
std::string pName
 
int pProtocolFamily
 
AnyObjectpChannelID
 

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 
)
inline

Constructor

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

◆ ~Socket()

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

Desctuctor.

References Close().

Member Function Documentation

◆ Close()

void XrdCl::Socket::Close ( )

Disconnect.

Referenced by ~Socket().

◆ Connect()

Status 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()

Status 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)

◆ 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()

Status 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()

Status 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()

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

Initialize the socket.

◆ Poll()

Status XrdCl::Socket::Poll ( bool  readyForReading,
bool  readyForWriting,
int32_t  timeout 
)
private

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

◆ ReadRaw()

Status 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

◆ Send()

ssize_t XrdCl::Socket::Send ( void *  buffer,
uint32_t  size 
)

Portable wrapper around SIGPIPE free send

Parameters
buffer: data to be written
size: size of the data buffer
Returns
: 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()

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

Set the socket flags (man fcntl)

◆ SetSockOpt()

Status 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.

◆ WriteRaw()

Status 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

◆ WriteV()

ssize_t XrdCl::Socket::WriteV ( iovec *  iov,
int  iovcnt 
)

Wrapper around writev

Parameters
iov: buffers to be written
iovcnt: number of buffers
Returns
: the amount of data actually written

Member Data Documentation

◆ pChannelID

AnyObject* XrdCl::Socket::pChannelID
private

Referenced by GetChannelID(), and SetChannelID().

◆ pName

std::string XrdCl::Socket::pName
mutableprivate

◆ pPeerName

std::string XrdCl::Socket::pPeerName
mutableprivate

◆ pProtocolFamily

int XrdCl::Socket::pProtocolFamily
private

◆ pServerAddr

XrdNetAddr XrdCl::Socket::pServerAddr
private

Referenced by GetServerAddress().

◆ pSocket

int XrdCl::Socket::pSocket
private

Referenced by GetFD().

◆ pSockName

std::string XrdCl::Socket::pSockName
mutableprivate

◆ pStatus

SocketStatus XrdCl::Socket::pStatus
private

Referenced by GetStatus(), and SetStatus().


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