![]() |
XRootD
|
A network socket. More...
#include <XrdClSocket.hh>
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... | |
void | Close () |
Disconnect. More... | |
XRootDStatus | Connect (const std::string &host, uint16_t port, uint16_t timout=10) |
XRootDStatus | ConnectToAddress (const XrdNetAddr &addr, uint16_t timout=10) |
XRootDStatus | Cork () |
XRootDStatus | Flash () |
const AnyObject * | GetChannelID () const |
int | GetFD () |
Get the file descriptor. More... | |
XRootDStatus | GetFlags (int &flags) |
Get the socket flags (man fcntl) More... | |
std::string | GetName () const |
Get the string representation of the socket. More... | |
std::string | GetPeerName () const |
Get the name of the remote peer. More... | |
const XrdNetAddr * | GetServerAddress () const |
Get the server address. More... | |
std::string | GetSockName () const |
Get the name of the socket. More... | |
XRootDStatus | GetSockOpt (int level, int optname, void *optval, socklen_t *optlen) |
Get socket options. More... | |
SocketStatus | GetStatus () const |
Get the socket status. More... | |
XRootDStatus | Initialize (int family=AF_INET) |
Initialize the socket. More... | |
bool | IsCorked () const |
bool | IsEncrypted () |
uint8_t | MapEvent (uint8_t event) |
virtual XRootDStatus | Read (char *buffer, size_t size, int &bytesRead) |
XRootDStatus | ReadRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesRead) |
Read raw bytes from the socket. More... | |
XRootDStatus | ReadV (iovec *iov, int iocnt, int &bytesRead) |
virtual XRootDStatus | Send (const char *buffer, size_t size, int &bytesWritten) |
XRootDStatus | Send (Message &msg, const std::string &strmname) |
XRootDStatus | Send (XrdSys::KernelBuffer &kbuff, int &bytesWritten) |
void | SetChannelID (AnyObject *channelID) |
XRootDStatus | SetFlags (int flags) |
Set the socket flags (man fcntl) More... | |
XRootDStatus | SetSockOpt (int level, int optname, const void *optval, socklen_t optlen) |
Set socket options. More... | |
void | SetStatus (SocketStatus status) |
Set socket status - do not use unless you know what you're doing. More... | |
XRootDStatus | TlsHandShake (AsyncSocketHandler *socketHandler, const std::string &thehost=std::string()) |
XRootDStatus | Uncork () |
XRootDStatus | WriteRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesWritten) |
Static Public Member Functions | |
static XRootDStatus | ClassifyErrno (int error) |
Protected Member Functions | |
XRootDStatus | Poll (bool readyForReading, bool readyForWriting, int32_t timeout) |
Protected Attributes | |
AnyObject * | pChannelID |
bool | pCorked |
std::string | pName |
std::string | pPeerName |
int | pProtocolFamily |
std::unique_ptr< XrdNetAddr > | pServerAddr |
int | pSocket |
std::string | pSockName |
SocketStatus | pStatus |
std::unique_ptr< Tls > | pTls |
A network socket.
Definition at line 42 of file XrdClSocket.hh.
Status of the socket.
Enumerator | |
---|---|
Disconnected | The socket is disconnected. |
Connected | The socket is connected. |
Connecting | The connection process is in progress. |
Definition at line 48 of file XrdClSocket.hh.
XrdCl::Socket::Socket | ( | int | socket = -1 , |
SocketStatus | status = Disconnected |
||
) |
Constructor
socket | already connected socket if available, -1 otherwise |
status | status of a socket if available |
Definition at line 44 of file XrdClSocket.cc.
|
virtual |
Desctuctor.
Definition at line 55 of file XrdClSocket.cc.
References Close().
|
static |
Definition at line 692 of file XrdClSocket.cc.
References XrdCl::errInternal, XrdCl::errInvalidArgs, XrdCl::errSocketError, XrdCl::stError, XrdCl::stOK, and XrdCl::suRetry.
Referenced by Read(), ReadV(), and Send().
void XrdCl::Socket::Close | ( | ) |
Disconnect.
Definition at line 262 of file XrdClSocket.cc.
References close, Disconnected, pName, pPeerName, pSocket, pSockName, pStatus, and pTls.
Referenced by ~Socket(), XrdCl::AsyncSocketHandler::Close(), XrdCl::AsyncSocketHandler::Connect(), ConnectToAddress(), Initialize(), ReadRaw(), and WriteRaw().
XRootDStatus XrdCl::Socket::Connect | ( | const std::string & | host, |
uint16_t | port, | ||
uint16_t | timout = 10 |
||
) |
Connect to the given host name
host | name of the host to connect to |
port | port to connect to |
timout | timeout in seconds, 0 for no timeout handling (may be used for non blocking IO) |
Definition at line 183 of file XrdClSocket.cc.
References Connected, Connecting, ConnectToAddress(), XrdCl::errInvalidOp, XrdCl::Utils::GetHostAddresses(), XrdCl::DefaultEnv::GetLog(), XrdCl::Utils::IPAll, XrdCl::Utils::IPv4, XrdCl::Status::IsOK(), XrdCl::Utils::LogHostAddresses(), XrdCl::PostMasterMsg, pProtocolFamily, pSocket, pStatus, and XrdCl::stError.
XRootDStatus XrdCl::Socket::ConnectToAddress | ( | const XrdNetAddr & | addr, |
uint16_t | timout = 10 |
||
) |
Connect to the given host address
addr | address of the host to connect to |
timout | timeout in seconds, 0 for no timeout handling (may be used for non blocking IO) |
Definition at line 212 of file XrdClSocket.cc.
References Close(), XrdCl::Status::code, XrdNetConnect::Connect(), Connected, Connecting, XrdCl::errInvalidOp, XrdCl::Status::errNo, XrdCl::errSocketError, XrdCl::errSocketTimeout, pServerAddr, pSocket, pStatus, pTls, and XrdCl::stError.
Referenced by Connect(), and XrdCl::AsyncSocketHandler::Connect().
XRootDStatus XrdCl::Socket::Cork | ( | ) |
Definition at line 782 of file XrdClSocket.cc.
References XrdCl::errSocketOptError, IPPROTO_TCP, pCorked, pSocket, and XrdCl::stFatal.
Referenced by Flash(), and XrdCl::AsyncSocketHandler::OnConnectionReturn().
XRootDStatus XrdCl::Socket::Flash | ( | ) |
Definition at line 818 of file XrdClSocket.cc.
References Cork(), XrdCl::Status::IsOK(), and Uncork().
Referenced by XrdCl::AsyncHSWriter::Write(), and XrdCl::AsyncMsgWriter::Write().
|
inline |
Get Channel ID (an object that allows to identify all sockets corresponding to the same channel)
Definition at line 255 of file XrdClSocket.hh.
References pChannelID.
|
inline |
Get the file descriptor.
Definition at line 214 of file XrdClSocket.hh.
References pSocket.
Referenced by XrdCl::Tls::Tls(), and XrdCl::PollerBuiltIn::AddSocket().
XRootDStatus XrdCl::Socket::GetFlags | ( | int & | flags | ) |
Get the socket flags (man fcntl)
Definition at line 137 of file XrdClSocket.cc.
References XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), pSocket, and XrdCl::stError.
std::string XrdCl::Socket::GetName | ( | ) | const |
Get the string representation of the socket.
Definition at line 672 of file XrdClSocket.cc.
References Connected, GetPeerName(), GetSockName(), pName, and pStatus.
Referenced by XrdCl::PollerBuiltIn::AddSocket(), XrdCl::PollerBuiltIn::EnableReadNotification(), XrdCl::PollerBuiltIn::EnableWriteNotification(), XrdCl::PollerBuiltIn::RemoveSocket(), and XrdCl::PollerBuiltIn::Stop().
std::string XrdCl::Socket::GetPeerName | ( | ) | const |
Get the name of the remote peer.
Definition at line 652 of file XrdClSocket.cc.
References Connected, XrdNetUtils::IPFormat(), pPeerName, pSocket, and pStatus.
Referenced by GetName().
|
inline |
Get the server address.
Definition at line 237 of file XrdClSocket.hh.
References pServerAddr.
Referenced by XrdCl::AsyncSocketHandler::OnConnectionReturn().
std::string XrdCl::Socket::GetSockName | ( | ) | const |
Get the name of the socket.
Definition at line 632 of file XrdClSocket.cc.
References Connected, XrdNetUtils::IPFormat(), pSocket, pSockName, and pStatus.
Referenced by GetName(), and XrdCl::AsyncSocketHandler::OnConnectionReturn().
XRootDStatus XrdCl::Socket::GetSockOpt | ( | int | level, |
int | optname, | ||
void * | optval, | ||
socklen_t * | optlen | ||
) |
Get socket options.
Definition at line 152 of file XrdClSocket.cc.
References XrdCl::errInvalidOp, XrdCl::errSocketOptError, pSocket, and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::OnConnectionReturn().
|
inline |
Get the socket status.
Definition at line 125 of file XrdClSocket.hh.
References pStatus.
Referenced by XrdCl::PollerBuiltIn::AddSocket(), and XrdCl::AsyncSocketHandler::EventWrite().
XRootDStatus XrdCl::Socket::Initialize | ( | int | family = AF_INET | ) |
Initialize the socket.
Definition at line 63 of file XrdClSocket.cc.
References Close(), XrdCl::DefaultNoDelay, XrdCl::errFcntl, XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), IPPROTO_TCP, XrdCl::Status::IsOK(), pProtocolFamily, pSocket, SetSockOpt(), and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::Connect().
|
inline |
Definition at line 286 of file XrdClSocket.hh.
References pCorked.
Referenced by XrdCl::Tls::Connect(), XrdCl::Tls::Read(), and XrdCl::Tls::Send().
bool XrdCl::Socket::IsEncrypted | ( | ) |
Definition at line 867 of file XrdClSocket.cc.
References pTls.
Referenced by XrdCl::AsyncSocketHandler::HandleHandShake(), and XrdCl::XRootDMsgHandler::WriteMessageBody().
uint8_t XrdCl::Socket::MapEvent | ( | uint8_t | event | ) |
Definition at line 835 of file XrdClSocket.cc.
References pTls.
Referenced by XrdCl::AsyncSocketHandler::Event().
|
protected |
Poll the socket to see whether it is ready for IO
readyForReading | poll for readiness to read |
readyForWriting | poll for readiness to write |
timeout | timeout in seconds, -1 to wait indefinitely |
Definition at line 541 of file XrdClSocket.cc.
References Connected, XrdCl::errInvalidOp, XrdCl::errPoll, XrdCl::errSocketDisconnected, XrdCl::errSocketError, XrdCl::errSocketTimeout, pSocket, pStatus, XrdCl::stError, and XrdCl::stOK.
Referenced by ReadRaw(), and WriteRaw().
|
virtual |
Read helper for raw socket
buffer | : the sink for the data |
size | : size of the sink |
bytesRead | : number of bytes actually written into the sink |
Definition at line 740 of file XrdClSocket.cc.
References ClassifyErrno(), XrdCl::errSocketError, pSocket, pTls, read(), and XrdCl::stError.
Referenced by XrdCl::XRootDTransport::GetBody(), XrdCl::XRootDTransport::GetHeader(), XrdCl::XRootDTransport::GetMore(), and XrdCl::AsyncRawReaderIntfc::ReadBytesAsync().
XRootDStatus XrdCl::Socket::ReadRaw | ( | void * | buffer, |
uint32_t | size, | ||
int32_t | timeout, | ||
uint32_t & | bytesRead | ||
) |
Read raw bytes from the socket.
Read raw bytes from the socket
buffer | data to be sent |
size | size of the data buffer |
timeout | timout value in seconds, -1 to wait indefinitely |
bytesRead | the amount of data actually read |
Definition at line 280 of file XrdClSocket.cc.
References Close(), Connected, XrdCl::errInvalidOp, XrdCl::errSocketDisconnected, XrdCl::errSocketError, XrdCl::errSocketTimeout, Poll(), pSocket, pStatus, read(), XrdCl::Status::status, XrdCl::stError, and XrdCl::stOK.
XRootDStatus XrdCl::Socket::ReadV | ( | iovec * | iov, |
int | iocnt, | ||
int & | bytesRead | ||
) |
ReadV helper for raw socket
iov | : the buffers for the data |
iocnt | : number of buffers |
bytesRead | : number of bytes actually written into the sink |
Definition at line 761 of file XrdClSocket.cc.
References ClassifyErrno(), XrdCl::errSocketError, pSocket, pTls, readv(), and XrdCl::stError.
Referenced by XrdCl::AsyncPageReader::Read().
|
virtual |
Portable wrapper around SIGPIPE free send
buffer | : data to be written |
size | : size of the data buffer |
bytesWritten | : the amount of data actually written |
Definition at line 461 of file XrdClSocket.cc.
References ClassifyErrno(), pSocket, pTls, and write().
Referenced by Send(), XrdCl::AsyncHSWriter::Write(), XrdCl::AsyncMsgWriter::Write(), and XrdCl::XRootDMsgHandler::WriteMessageBody().
XRootDStatus XrdCl::Socket::Send | ( | Message & | msg, |
const std::string & | strmname | ||
) |
Write message to the socket
msg | : message (request) to be sent |
strmname | : stream name (for logging purposes) |
Definition at line 503 of file XrdClSocket.cc.
References XrdCl::Buffer::AdvanceCursor(), XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Log::Dump(), XrdCl::Buffer::GetBufferAtCursor(), XrdCl::Buffer::GetCursor(), XrdCl::DefaultEnv::GetLog(), XrdCl::Message::GetObfuscatedDescription(), XrdCl::Buffer::GetSize(), XrdCl::Status::IsOK(), Send(), XrdCl::Buffer::SetCursor(), and XrdCl::suRetry.
XRootDStatus XrdCl::Socket::Send | ( | XrdSys::KernelBuffer & | kbuff, |
int & | bytesWritten | ||
) |
Write data from a kernel buffer to the socket
kbuff | : data to be written |
bytesWritten | : the amount of data actually written |
Write data from a kernel buffer to the socket
kbuff | : data to be written |
Definition at line 487 of file XrdClSocket.cc.
References ClassifyErrno(), XrdCl::errNotSupported, pSocket, pTls, XrdSys::Send(), and XrdCl::stError.
|
inline |
Set Channel ID (an object that allows to identify all sockets corresponding to the same channel)
Definition at line 246 of file XrdClSocket.hh.
References pChannelID.
Referenced by XrdCl::AsyncSocketHandler::AsyncSocketHandler().
XRootDStatus XrdCl::Socket::SetFlags | ( | int | flags | ) |
Set the socket flags (man fcntl)
Definition at line 123 of file XrdClSocket.cc.
References XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), pSocket, and XrdCl::stError.
XRootDStatus XrdCl::Socket::SetSockOpt | ( | int | level, |
int | optname, | ||
const void * | optval, | ||
socklen_t | optlen | ||
) |
Set socket options.
Definition at line 167 of file XrdClSocket.cc.
References XrdCl::errInvalidOp, XrdCl::errSocketOptError, pSocket, and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::Connect(), and Initialize().
|
inline |
Set socket status - do not use unless you know what you're doing.
Definition at line 133 of file XrdClSocket.hh.
References pStatus.
Referenced by XrdCl::AsyncSocketHandler::Connect(), and XrdCl::AsyncSocketHandler::OnConnectionReturn().
XRootDStatus XrdCl::Socket::TlsHandShake | ( | AsyncSocketHandler * | socketHandler, |
const std::string & | thehost = std::string() |
||
) |
Definition at line 844 of file XrdClSocket.cc.
References XrdCl::errInvalidOp, XrdCl::errTlsError, pServerAddr, pTls, XrdCl::stError, and XrdCl::stFatal.
Referenced by XrdCl::AsyncSocketHandler::DoTlsHandShake().
XRootDStatus XrdCl::Socket::Uncork | ( | ) |
Definition at line 800 of file XrdClSocket.cc.
References XrdCl::errSocketOptError, IPPROTO_TCP, pCorked, pSocket, and XrdCl::stFatal.
Referenced by XrdCl::Tls::Connect(), Flash(), XrdCl::Tls::Read(), and XrdCl::Tls::Send().
XRootDStatus XrdCl::Socket::WriteRaw | ( | void * | buffer, |
uint32_t | size, | ||
int32_t | timeout, | ||
uint32_t & | bytesWritten | ||
) |
Write raw bytes to the socket
buffer | data to be written |
size | size of the data buffer |
timeout | timeout value in seconds, -1 to wait indefinitely |
bytesWritten | the amount of data actually written |
Definition at line 375 of file XrdClSocket.cc.
References Close(), Connected, XrdCl::errInvalidOp, XrdCl::errSocketError, XrdCl::errSocketTimeout, Poll(), pSocket, pStatus, XrdCl::Status::status, XrdCl::stError, XrdCl::stOK, and write().
|
protected |
Definition at line 334 of file XrdClSocket.hh.
Referenced by GetChannelID(), and SetChannelID().
|
protected |
Definition at line 335 of file XrdClSocket.hh.
Referenced by Cork(), IsCorked(), and Uncork().
|
mutableprotected |
Definition at line 332 of file XrdClSocket.hh.
|
mutableprotected |
Definition at line 331 of file XrdClSocket.hh.
Referenced by Close(), and GetPeerName().
|
protected |
Definition at line 333 of file XrdClSocket.hh.
Referenced by Connect(), and Initialize().
|
protected |
Definition at line 329 of file XrdClSocket.hh.
Referenced by ConnectToAddress(), GetServerAddress(), and TlsHandShake().
|
protected |
Definition at line 327 of file XrdClSocket.hh.
Referenced by Close(), Connect(), ConnectToAddress(), Cork(), GetFD(), GetFlags(), GetPeerName(), GetSockName(), GetSockOpt(), Initialize(), Poll(), Read(), ReadRaw(), ReadV(), Send(), SetFlags(), SetSockOpt(), Uncork(), and WriteRaw().
|
mutableprotected |
Definition at line 330 of file XrdClSocket.hh.
Referenced by Close(), and GetSockName().
|
protected |
Definition at line 328 of file XrdClSocket.hh.
Referenced by Close(), Connect(), ConnectToAddress(), GetName(), GetPeerName(), GetSockName(), GetStatus(), Poll(), ReadRaw(), SetStatus(), and WriteRaw().
|
protected |
Definition at line 337 of file XrdClSocket.hh.
Referenced by Close(), ConnectToAddress(), IsEncrypted(), MapEvent(), Read(), ReadV(), Send(), and TlsHandShake().