#include <XrdNet.hh>
|
| XrdNet (XrdSysError *erp, XrdNetSecurity *secp=0) |
|
virtual | ~XrdNet () |
| Destructor. More...
|
|
int | Accept (XrdNetAddr &myAddr, int opts=0, int timeout=-1) |
|
int | Accept (XrdNetPeer &myPeer, int opts=0, int timeout=-1) |
|
int | Bind (char *path, const char *contype="stream") |
|
int | Bind (int port, const char *contype="tcp") |
|
int | Connect (XrdNetAddr &myAddr, const char *dest, int port=-1, int opts=0, int timeout=-1) |
|
int | Connect (XrdNetPeer &myPeer, const char *dest, int port=-1, int opts=0, int timeout=-1) |
|
int | Port () |
|
int | Relay (const char *dest) |
|
int | Relay (XrdNetPeer &Peer, const char *dest, int opts=0) |
|
virtual void | Secure (XrdNetSecurity *secp) |
|
void | setDefaults (int options, int buffsz=0) |
|
void | setDomain (const char *dname) |
|
void | Trim (char *hname) |
|
void | unBind () |
| Unbind the network from any bound resouces. More...
|
|
int | WSize () |
|
Definition at line 51 of file XrdNet.hh.
◆ XrdNet()
Constructor
- Parameters
-
erp | The error object for printing error messages. It must be supplied. |
secp | The initial NetSecurity object. This secp object must not be deleted nor directly used after the call as this object assumes its ownership and may delete it at any time. |
Definition at line 60 of file XrdNet.cc.
References BuffQ, Domain, Domlen, eDest, iofd, netOpts, Police, Portnum, PortType, and Windowsz.
◆ ~XrdNet()
Destructor.
Definition at line 74 of file XrdNet.cc.
void unBind()
Unbind the network from any bound resouces.
References Domain, and unBind().
◆ Accept() [1/2]
int XrdNet::Accept |
( |
XrdNetAddr & |
myAddr, |
|
|
int |
opts = 0 , |
|
|
int |
timeout = -1 |
|
) |
| |
Accept incoming TCP connection. This is the preferred method for TCP.
- Parameters
-
myAddr | the address object to contain connection information. |
opts | processing options: XRDNET_DELAY - do not set nodelay on socket. XRDNET_KEEPALIVE - use TCP keep alive on socket. XRDNET_NOCLOSEX - do not allow socket to close on exec() XRDNET_NOEMSG - supress printing error messages XRDNET_NOLINGER - Do not linger when closing socket. |
timeout | maximum seconds to wait for a conection. When negative, the default, no time limit applies. |
- Returns
- !0 Successful connection occurred, myAddr holds information.
-
=0 Failure, a timeout or permanent error occurred.
Definition at line 84 of file XrdNet.cc.
93 eDest->
Emsg(
"Accept",
"Network not bound to a port.");
101 eDest->
Emsg(
"Accept",
"UDP network not supported for NetAddr call.");
107 do {
if (timeout >= 0)
108 {
struct pollfd sfd = {
iofd,
109 POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI|POLLHUP,0};
110 do {retc = poll(&sfd, 1, timeout*1000);}
111 while(retc < 0 && (errno == EAGAIN || errno == EINTR));
114 eDest->
Emsg(
"Accept",
"Accept timed out.");
118 }
while(!do_Accept_TCP(myAddr,
opts));
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
References eDest, XrdSysError::Emsg(), iofd, netOpts, opts, PortType, and XRDNET_NOEMSG.
Referenced by XrdInet::Accept().
◆ Accept() [2/2]
int XrdNet::Accept |
( |
XrdNetPeer & |
myPeer, |
|
|
int |
opts = 0 , |
|
|
int |
timeout = -1 |
|
) |
| |
Accept incoming TCP or UDP connection. This method should only be used for UDP-style networks. The previous method is preferred for TCP-style networks.
- Parameters
-
myPeer | the peer object to contain connection information. |
opts | processing options: XRDNET_DELAY - TCP: do not set nodelay on socket. XRDNET_KEEPALIVE - TCP: use TCP keep alive on socket. XRDNET_NEWFD - UDP: obtain new file descriptor XRDNET_NOCLOSEX - ALL: keep socket across exec() calls XRDNET_NODNTRIM - ALL: don't trim domain name in myPeer XRDNET_NOEMSG - ALL: supress printing error messages XRDNET_NORLKUP - ALL: avoid doing reverse DNS look-up XRDNET_USETLS - ALL: enable TLS upon connection |
timeout | maximum seconds to wait for a conection. When negative, the default, no time limit applies. |
- Returns
- !0 Successful connection occurred, myPeer holds information.
-
=0 Failure, a timeout or permanent error occurred.
Definition at line 125 of file XrdNet.cc.
134 eDest->
Emsg(
"Accept",
"Network not bound to a port.");
140 do {
if (timeout >= 0)
141 {
struct pollfd sfd = {
iofd,
142 POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI|POLLHUP,0};
143 do {retc = poll(&sfd, 1, timeout*1000);}
144 while(retc < 0 && (errno == EAGAIN || errno == EINTR));
147 eDest->
Emsg(
"Accept",
"Accept timed out.");
151 }
while(!(
PortType == SOCK_STREAM ? do_Accept_TCP(myPeer,
opts)
152 : do_Accept_UDP(myPeer,
opts)));
References Domain, eDest, XrdSysError::Emsg(), XrdNetPeer::InetName, iofd, netOpts, opts, PortType, Trim(), XRDNET_NODNTRIM, and XRDNET_NOEMSG.
◆ Bind() [1/2]
int XrdNet::Bind |
( |
char * |
path, |
|
|
const char * |
contype = "stream" |
|
) |
| |
Bind a network object to a Unix named socket.
- Parameters
-
path | the file system path to a named socket to bind with. |
contype | Either "stream" to use TCP-tyle streaming protocol or "datagram" to use UDP-style messaging. |
- Returns
- 0 Successfully bound the port.
-
!0 Failure, return value is -errno describing the error.
Definition at line 206 of file XrdNet.cc.
215 {
eDest->
Emsg(
"Bind",
"Invalid bind path -", path);
225 if (*contype !=
'd')
PortType = SOCK_STREAM;
233 if (mySocket.Open(path, -1,
opts, buffsz) < 0)
return -mySocket.LastError();
237 iofd = mySocket.Detach();
References BuffQ, BuffSize, XrdNetSocket::Detach(), eDest, XrdSysError::Emsg(), iofd, XrdNetSocket::LastError(), netOpts, XrdNetSocket::Open(), opts, PortType, unBind(), Windowsz, XRDNET_SERVER, XRDNET_UDPBUFFSZ, and XRDNET_UDPSOCKET.
◆ Bind() [2/2]
int XrdNet::Bind |
( |
int |
port, |
|
|
const char * |
contype = "tcp" |
|
) |
| |
Bind a network object to a TCP or UDP port number.
- Parameters
-
port | the port number to bind to. Use 0 for arbitrary port. |
contype | Either "tcp" for TCP networks or "udp" for UDP networks. |
- Returns
- 0 Successfully bound the port.
-
!0 Failure, return value is -errno describing the error.
Definition at line 164 of file XrdNet.cc.
176 if (*contype !=
'u')
PortType = SOCK_STREAM;
184 if (mySocket.Open(0, bindport,
opts, buffsz) < 0)
185 return -mySocket.LastError();
189 iofd = mySocket.Detach();
static int Port(int fd, const char **eText=0)
References BuffQ, BuffSize, XrdNetSocket::Detach(), eDest, iofd, XrdNetSocket::LastError(), netOpts, XrdNetSocket::Open(), opts, XrdNetUtils::Port(), Portnum, PortType, unBind(), Windowsz, XRDNET_SERVER, XRDNET_UDPBUFFSZ, and XRDNET_UDPSOCKET.
Referenced by XrdInet::BindSD().
◆ Connect() [1/2]
int XrdNet::Connect |
( |
XrdNetAddr & |
myAddr, |
|
|
const char * |
dest, |
|
|
int |
port = -1 , |
|
|
int |
opts = 0 , |
|
|
int |
timeout = -1 |
|
) |
| |
Create a TCP socket and connect it to the given host and port. This is the preferred method for making TCP based connections.
- Parameters
-
myAddr | address object where connection information is returned. |
dest | destination hostname or IP address. |
port | the port number to connect to. If < 0 then the dest param must contain the port number preceeded by a colon. |
opts | processing options: XRDNET_NOCLOSEX - do not allow socket to close on exec() XRDNET_NOEMSG - supress printing error messages XRDNET_NORLKUP - avoid doing reverse DNS look-up |
timeout | the maximum number of seconds to wait for the connection to complete. A negative value waits forever. Values greater than 255 seconds are set to 255. |
- Returns
- true Connection completed, myAddr holds connection information.
-
false Connection failed.
Definition at line 252 of file XrdNet.cc.
264 if (mySocket.Open(host, port,
opts,
Windowsz) < 0)
return 0;
265 myAddr.
Set(mySocket.Detach());
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
References XrdNetSocket::Detach(), eDest, XrdNetAddrInfo::Name(), netOpts, XrdNetSocket::Open(), opts, XrdNetAddr::Set(), Windowsz, XRDNET_NOEMSG, XRDNET_NORLKUP, XRDNET_TOUT, and XRDNET_UDPSOCKET.
Referenced by XrdInet::Connect(), and Relay().
◆ Connect() [2/2]
int XrdNet::Connect |
( |
XrdNetPeer & |
myPeer, |
|
|
const char * |
dest, |
|
|
int |
port = -1 , |
|
|
int |
opts = 0 , |
|
|
int |
timeout = -1 |
|
) |
| |
Create a TCP or UDP socket and connect it to the given host and port. The previous method is preferred for creating TCP sockets.
- Parameters
-
myPeer | peer object where connection information is returned. |
dest | destination hostname or IP address. |
port | the port number to connect to. If < 0 then the dest param must contain the port number preceeded by a colon. |
opts | processing options: XRDNET_NOCLOSEX - do not allow socket to close on exec() XRDNET_NODNTRIM - do not trim domain name in myPeer. XRDNET_NOEMSG - supress printing error messages XRDNET_NORLKUP - avoid doing reverse DNS look-up XRDNET_UDPSOCKET - create a UDP socket (o/w use TCP). |
timeout | the maximum number of seconds to wait for the connection to complete. A negative value waits forever. Values greater than 255 seconds are set to 255. |
- Returns
- true Connection completed, myPeer holds connection information.
-
false Connection failed.
Definition at line 272 of file XrdNet.cc.
276 const struct sockaddr *sap;
287 if (mySocket.Open(host, port,
opts, buffsz) < 0)
return 0;
291 memset((
void *)&myPeer.
Inet, 0,
sizeof(myPeer.
Inet));
293 const char *pn = mySocket.Peername(&sap);
294 if (pn) {memcpy((
void *)&myPeer.
Inet, sap,
sizeof(myPeer.
Inet));
298 memset((
void *)&myPeer.
Inet, 0,
sizeof(myPeer.
Inet));
299 myPeer.
InetName = strdup(
"unknown");
302 myPeer.
fd = mySocket.Detach();
References XrdNetSocket::Detach(), Domain, eDest, XrdNetPeer::fd, XrdNetPeer::Inet, XrdNetPeer::InetName, netOpts, XrdNetSocket::Open(), opts, XrdNetSocket::Peername(), Trim(), Windowsz, XRDNET_NODNTRIM, XRDNET_NOEMSG, XRDNET_TOUT, XRDNET_UDPBUFFSZ, and XRDNET_UDPSOCKET.
◆ Port()
Get the port number, if any, bound to this network.
- Returns
- >0 The bound port number.
-
<=0 The network is not bound to a port.
Definition at line 191 of file XrdNet.hh.
References Portnum.
Referenced by XrdgetProtocol().
◆ Relay() [1/2]
int XrdNet::Relay |
( |
const char * |
dest | ) |
|
◆ Relay() [2/2]
int XrdNet::Relay |
( |
XrdNetPeer & |
Peer, |
|
|
const char * |
dest, |
|
|
int |
opts = 0 |
|
) |
| |
◆ Secure()
Add a NetSecurity object to the existing accept() security constraints.
- Parameters
-
secp | Pointer to the network security object. This object must not be deleted nor directly used after the call as this object assumes its ownership and may delete it at any time. |
Reimplemented in XrdInet.
Definition at line 329 of file XrdNet.cc.
void Merge(XrdNetSecurity *srcp)
References XrdNetSecurity::Merge(), and Police.
◆ setDefaults()
void XrdNet::setDefaults |
( |
int |
options, |
|
|
int |
buffsz = 0 |
|
) |
| |
|
inline |
Set network defaults.
- Parameters
-
options | The options to be added to Accept(), Bind() and Connect() calls. These options cannot be turned off, so be careful. |
buffsz | The UDP buffer size (the initial default is 32K) or the TCP window size (initial default is OS dependent). |
Definition at line 223 of file XrdNet.hh.
References netOpts, and Windowsz.
◆ setDomain()
void XrdNet::setDomain |
( |
const char * |
dname | ) |
|
|
inline |
Set network domain name.
- Parameters
-
dname | The domain name which indicates to Trim() what part of the host name is so common that it can be trimmed. |
Definition at line 233 of file XrdNet.hh.
References Domain, and Domlen.
◆ Trim()
void XrdNet::Trim |
( |
char * |
hname | ) |
|
◆ unBind()
◆ WSize()
Get the current TCP RCVBUF window size.
- Returns
- >0 The current window size.
-
<=0 Either the network is not bound to a port or an error has occurred. Window size is unavailable.
Definition at line 368 of file XrdNet.cc.
static int getWindow(int fd, int &Windowsz, XrdSysError *eDest=0)
References eDest, XrdNetSocket::getWindow(), and iofd.
◆ BuffQ
◆ BuffSize
◆ Domain
◆ Domlen
◆ eDest
◆ iofd
◆ netOpts
◆ Police
◆ Portnum
◆ PortType
◆ Windowsz
The documentation for this class was generated from the following files: