|
xrootd
|
#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... | |
| Status | Initialize () |
| 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 sockaddr_in &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) |
| Read raw bytes from the socket. More... | |
| Status | WriteRaw (void *buffer, uint32_t size, int32_t timeout, uint32_t &bytesWritten) |
| ssize_t | Send (void *buffer, uint32_t size) |
| 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 sockaddr_in * | GetServerAddress () const |
| Get the server address. More... | |
Private Member Functions | |
| Status | Poll (bool readyForReading, bool readyForWriting, int32_t timeout) |
Private Attributes | |
| int | pSocket |
| SocketStatus | pStatus |
| sockaddr_in * | pServerAddr |
| std::string | pSockName |
| std::string | pPeerName |
| std::string | pName |
A network socket.
Status of the socket.
| Enumerator | |
|---|---|
| Disconnected |
The socket is disconnected. |
| Connected |
The socket is connected. |
| Connecting |
The connection process is in progress. |
|
inline |
Constructor
| socket | already connected socket if available, -1 otherwise |
| status | status of a socket if available |
|
inlinevirtual |
Desctuctor.
References Close().
| void XrdCl::Socket::Close | ( | ) |
Disconnect.
References close(), Disconnected, pName, pPeerName, pServerAddr, pSocket, pSockName, and pStatus.
Referenced by XrdCl::AsyncSocketHandler::Close(), XrdCl::AsyncSocketHandler::Connect(), ConnectToAddress(), Initialize(), ReadRaw(), WriteRaw(), and ~Socket().
| Status 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) |
References Connected, Connecting, ConnectToAddress(), XrdCl::errInvalidAddr, XrdCl::errInvalidOp, XrdSysDNS::getHostAddr(), pSocket, pStatus, and XrdCl::stError.
| Status XrdCl::Socket::ConnectToAddress | ( | const sockaddr_in & | 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) |
References Close(), XrdCl::Status::code, XrdNetConnect::Connect(), Connected, Connecting, XrdCl::errInvalidOp, XrdCl::Status::errNo, XrdCl::errSocketError, XrdCl::errSocketTimeout, pServerAddr, pSocket, pStatus, and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::Connect(), and Connect().
|
inline |
Get the file descriptor.
References pSocket.
Referenced by XrdCl::PollerBuiltIn::AddSocket(), XrdCl::PollerLibEvent::EnableReadNotification(), XrdCl::PollerLibEvent::EnableWriteNotification(), SocketHandler::Event(), XrdCl::AsyncSocketHandler::OnRead(), XrdCl::AsyncSocketHandler::OnWrite(), and XrdCl::AsyncSocketHandler::ReadMessage().
| Status XrdCl::Socket::GetFlags | ( | int & | flags | ) |
Get the socket flags (man fcntl)
References XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), pSocket, and XrdCl::stError.
| std::string XrdCl::Socket::GetName | ( | ) | const |
Get the string representation of the socket.
References Connected, GetPeerName(), GetSockName(), pName, and pStatus.
Referenced by XrdCl::PollerBuiltIn::AddSocket(), XrdCl::PollerLibEvent::AddSocket(), XrdCl::PollerBuiltIn::EnableReadNotification(), XrdCl::PollerLibEvent::EnableReadNotification(), XrdCl::PollerBuiltIn::EnableWriteNotification(), XrdCl::PollerLibEvent::EnableWriteNotification(), XrdCl::PollerBuiltIn::RemoveSocket(), and XrdCl::PollerLibEvent::RemoveSocket().
| std::string XrdCl::Socket::GetPeerName | ( | ) | const |
|
inline |
Get the server address.
References pServerAddr.
Referenced by XrdCl::AsyncSocketHandler::OnConnectionReturn().
| std::string XrdCl::Socket::GetSockName | ( | ) | const |
Get the name of the socket.
References Connected, XrdSysDNS::IPFormat(), pSocket, pSockName, and pStatus.
Referenced by SocketHandler::Event(), GetName(), and XrdCl::AsyncSocketHandler::OnConnectionReturn().
| Status XrdCl::Socket::GetSockOpt | ( | int | level, |
| int | optname, | ||
| void * | optval, | ||
| socklen_t * | optlen | ||
| ) |
Get socket options.
References XrdCl::errInvalidOp, XrdCl::errSocketOptError, pSocket, and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::OnConnectionReturn().
|
inline |
Get the socket status.
References pStatus.
Referenced by XrdCl::PollerBuiltIn::AddSocket(), XrdCl::PollerLibEvent::AddSocket(), and XrdCl::AsyncSocketHandler::Event().
| Status XrdCl::Socket::Initialize | ( | ) |
Initialize the socket.
References Close(), XrdCl::errFcntl, XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), XrdCl::Status::IsOK(), pSocket, SetSockOpt(), and XrdCl::stError.
Referenced by XrdCl::AsyncSocketHandler::Connect().
|
private |
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 |
References Connected, XrdCl::errInvalidOp, XrdCl::errPoll, XrdCl::errSocketDisconnected, XrdCl::errSocketError, XrdCl::errSocketTimeout, pSocket, pStatus, XrdCl::stError, and XrdCl::stOK.
Referenced by ReadRaw(), and WriteRaw().
| Status 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 |
References Close(), Connected, XrdCl::errInvalidOp, XrdCl::errSocketDisconnected, XrdCl::errSocketError, XrdCl::errSocketTimeout, Poll(), pSocket, pStatus, read(), XrdCl::Status::status, XrdCl::stError, and XrdCl::stOK.
| ssize_t XrdCl::Socket::Send | ( | void * | buffer, |
| uint32_t | size | ||
| ) |
Portable wrapper around SIGPIPE free send
| buffer | data to be written |
| size | size of the data buffer |
| bytesWritten | the amount of data actually written |
References pSocket, and write().
Referenced by XrdCl::AsyncSocketHandler::WriteCurrentMessage().
| Status XrdCl::Socket::SetFlags | ( | int | flags | ) |
Set the socket flags (man fcntl)
References XrdCl::errInvalidOp, XrdCl::errSocketError, fcntl(), pSocket, and XrdCl::stError.
| Status XrdCl::Socket::SetSockOpt | ( | int | level, |
| int | optname, | ||
| const void * | optval, | ||
| socklen_t | optlen | ||
| ) |
Set socket options.
References XrdCl::errInvalidOp, XrdCl::errSocketOptError, pSocket, and XrdCl::stError.
Referenced by Initialize().
|
inline |
Set socket status - do not use unless you know what you're doing.
References pStatus.
Referenced by XrdCl::AsyncSocketHandler::OnConnectionReturn().
| Status 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 |
References Close(), Connected, XrdCl::errInvalidOp, XrdCl::errSocketError, XrdCl::errSocketTimeout, Poll(), pSocket, pStatus, XrdCl::Status::status, XrdCl::stError, XrdCl::stOK, and write().
|
mutableprivate |
Referenced by Close(), and GetPeerName().
|
private |
Referenced by Close(), ConnectToAddress(), and GetServerAddress().
|
private |
Referenced by Close(), Connect(), ConnectToAddress(), GetFD(), GetFlags(), GetPeerName(), GetSockName(), GetSockOpt(), Initialize(), Poll(), ReadRaw(), Send(), SetFlags(), SetSockOpt(), and WriteRaw().
|
mutableprivate |
Referenced by Close(), and GetSockName().
|
private |
Referenced by Close(), Connect(), ConnectToAddress(), GetName(), GetPeerName(), GetSockName(), GetStatus(), Poll(), ReadRaw(), SetStatus(), and WriteRaw().
1.8.3.1