Loading...
Searching...
No Matches
XrdNetMsg Class Reference

`#include <XrdNetMsg.hh>`

Collaboration diagram for XrdNetMsg:

## Public Member Functions

| XrdNetMsg (XrdSysError *erp, const char *dest=0, bool *aOK=0, bool refr=false)
| ~XrdNetMsg ()
| Destructor.
int | Send (const char *buff, int blen=0, const char *dest=0, int tmo=-1)
int | Send (const char *dest, const XrdNetSockAddr &netSA, const char *buff, int blen=0, int tmo=-1)
int | Send (const struct iovec iov[], int iovcnt, const char *dest=0, int tmo=-1)

## Protected Member Functions

int | OK2Send (int timeout, const char *dest)
int | retErr (int ecode, const char *theDest)
int | retErr (int ecode, XrdNetAddr &theDest)

## Protected Attributes

bool | destOK = false
char * | dfltDest
XrdSysError * | eDest
int | FD = -1
bool | isRefr = false

## Detailed Description

Definition at line 49 of file XrdNetMsg.hh.

## Constructor & Destructor Documentation

## XrdNetMsg()

XrdNetMsg::XrdNetMsg | ( | XrdSysError * | erp,
|  | const char * | dest = 0,
|  | bool * | aOK = 0,
|  | bool | refr = false )

Constructor

Parameters

  erp | The error message object for routing error messages.
  dest | The endpint name which can be host:port or a named socket. This becomes the default endpoint. Any specified endpoint to send must be in the same family (e.g. UNIX). If not specified, then an endpoint must always be specified with send and is restricted to be in the INET family.
  aOK | If supplied, set to true upon success; false otherwise.
  refr | When true, registers to socket for address refresh. This is done by periodically (as specified by the xrd.network directive) retranslating the dest host name to see if its IP address changed and if it did, updating the IP address. This option is ignored if dest is null (i.e. unspecified).

Definition at line 47 of file XrdNetMsg.cc.

: eDest(erp)
{
XrdNet myNet(erp);
bool aok = true;
// Handle the case where no dest was specified. In this case we will always
// need the caller to specify a destination.
//
if (!dest)
{if ((FD = myNet.Relay(dest)) < 0)
{eDest->Emsg("NetMsg", "Unable to create UDP msg socket.");
aok = false;
}
if (aOK) *aOK = aok;
return;
}
// Hande the common case where a dest is specified. We first make
// sure the dest is valid, eventhough that will occur again, so we van
// generate a resonable error message.
//
XrdNetAddr specDest;
const char *eText = specDest.Set(dest);
if (eText)
{eDest->Emsg("NetMsg", "Default", dest, "is unreachable");
if (aOK) *aOK = false;
return;
}
// Obtain a file description for this socket and set the endpoint address
//
XrdNetPeer myPeer;
if (!myNet.Relay(myPeer, dest, XRDNET_SENDONLY))
{eDest->Emsg("NetMsg", "Unable to create UDP msg socket.");
if (aOK) *aOK = false;
return;
}
// Save the relevant information
//
dfltDest = strdup(myPeer.InetName ? myPeer.InetName : "Unknown!");
FD = myPeer.fd;
destOK = true;
// If address refresh wanted, register this socket for refresh. This should
// never fail and if it does we return non-success.
//
if (refr && !XrdNetRefresh::Register(myPeer)) aok = false;
// All done
//
if (aOK) *aOK = aok;
}
XRDNET_SENDONLY
#define XRDNET_SENDONLY
Definition XrdNetOpts.hh:43
XrdNetAddr::Set
const char * Set(const char *hSpec, int pNum=PortInSpec)
Definition XrdNetAddr.cc:216
XrdNetMsg::FD
int FD
Definition XrdNetMsg.hh:147
XrdNetMsg::eDest
XrdSysError * eDest
Definition XrdNetMsg.hh:145
XrdNetMsg::destOK
bool destOK
Definition XrdNetMsg.hh:148
XrdNetMsg::dfltDest
char * dfltDest
Definition XrdNetMsg.hh:146
XrdNetPeer::fd
int fd
Definition XrdNetPeer.hh:42
XrdNetPeer::InetName
char * InetName
Definition XrdNetPeer.hh:44
XrdNetRefresh::Register
static bool Register(XrdNetPeer &Peer)
Definition XrdNetRefresh.cc:120

References destOK, dfltDest, eDest, FD, XrdNetPeer::fd, XrdNetPeer::InetName, XrdNetRefresh::Register(), XrdNet::Relay(), XrdNetAddr::Set(), and XRDNET_SENDONLY.

Here is the call graph for this function:

## ~XrdNetMsg()

XrdNetMsg::~XrdNetMsg | ( |  | ) |

Destructor.

Definition at line 107 of file XrdNetMsg.cc.

{
// If we are registered,deregister
//
if (isRefr) XrdNetRefresh::UnRegister(FD);
// Close the socket
//
if (close(FD) < 0)
eDest->Emsg("NetMsg", errno, "close socket for", dfltDest);
// Free the poiinter to the default dest
//
free(dfltDest);
}
close
#define close(a)
Definition XrdPosix.hh:48
XrdNetMsg::isRefr
bool isRefr
Definition XrdNetMsg.hh:149
XrdNetRefresh::UnRegister
static void UnRegister(int fd)
Definition XrdNetRefresh.cc:199

References close, dfltDest, eDest, FD, isRefr, and XrdNetRefresh::UnRegister().

Here is the call graph for this function:

## Member Function Documentation

## OK2Send()

int XrdNetMsg::OK2Send | ( | int | timeout,
|  | const char * | dest )

protected

Definition at line 241 of file XrdNetMsg.cc.

{
struct pollfd polltab = {FD, POLLOUT|POLLWRNORM, 0};
int retc;
do {retc = poll(&polltab, 1, timeout);} while(retc < 0 && errno == EINTR);
if (retc == 0 || !(polltab.revents & (POLLOUT | POLLWRNORM)))
eDest->Emsg("NetMsg", "UDP link to", dest, "is blocked.");
else if (retc < 0)
eDest->Emsg("NetMsg",errno,"poll", dest);
else return 1;
return 0;
}

References eDest, and FD.

Referenced by Send(), Send(), and Send().

Here is the caller graph for this function:

## retErr() [1/2]

int XrdNetMsg::retErr | ( | int | ecode,
|  | const char * | theDest )

protected

Definition at line 260 of file XrdNetMsg.cc.

{
if (!theDest)
{if (!destOK)
{eDest->Emsg("NetMsg", "Destination not specified."); return -1;}
theDest = dfltDest;
}
eDest->Emsg("NetMsg", ecode, "send to", theDest);
return (EWOULDBLOCK == ecode || EAGAIN == ecode ? 1 : -1);
}

References destOK, dfltDest, and eDest.

Referenced by retErr(), Send(), Send(), and Send().

Here is the caller graph for this function:

## retErr() [2/2]

int XrdNetMsg::retErr | ( | int | ecode,
|  | XrdNetAddr & | theDest )

protected

Definition at line 271 of file XrdNetMsg.cc.

{
return retErr(ecode, theDest.Name("unknown"));
}
XrdNetAddrInfo::Name
const char * Name(const char *eName=0, const char **eText=0)
Definition XrdNetAddrInfo.cc:309
XrdNetMsg::retErr
int retErr(int ecode, const char *theDest)
Definition XrdNetMsg.cc:260

References XrdNetAddrInfo::Name(), and retErr().

Here is the call graph for this function:

## Send() [1/3]

int XrdNetMsg::Send | ( | const char * | buff,
|  | int | blen = 0,
|  | const char * | dest = 0,
|  | int | tmo = -1 )

Send a UDP message to an endpoint.

Parameters

  buff | The data to send.
  blen | Length of the data in buff. If not specified, the length is computed as strlen(buff).
  dest | The endpint name which can be host:port or a named socket. If dest is zero, uses dest specified in the constructor.
  tmo | maximum seconds to wait for a idle socket. When negative, the default, no time limit applies.

Returns
  <0 Message not sent due to error.
  =0 Message send (well as defined by UDP)
  >0 Message not sent, timeout occurred.

Definition at line 127 of file XrdNetMsg.cc.

{
int retc;
// Get the buffer length of not specified
//
if (!Blen && !(Blen = strlen(Buff))) return 0;
// Handle the case where we are sendingto he dest setup at construction. This
// is the most common case.
//
if (!dest)
{if (!destOK)
{eDest->Emsg("NetMsg", "Destination not specified."); return -1;}
if (tmo >= 0 && !OK2Send(tmo, dfltDest)) return 1;
do {retc = send(FD, (Sokdata_t)Buff, Blen, 0);
} while (retc < 0 && errno == EINTR);
return (retc < 0 ? retErr(errno, dfltDest) : 0);
}
// Caller want to send to a specific destination other than the default
//
XrdNetAddr specDest;
if (specDest.Set(dest))
{eDest->Emsg("NetMsg", dest, "is unreachable"); return -1;}
if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
do {retc = sendto(FD, (Sokdata_t)Buff, Blen, 0,
specDest.SockAddr(), specDest.SockSize());}
while (retc < 0 && errno == EINTR);
return (retc < 0 ? retErr(errno, specDest) : 0);
}
Sokdata_t
#define Sokdata_t
Definition XrdSysPlatform.hh:289
XrdNetAddrInfo::SockAddr
const sockaddr * SockAddr()
Definition XrdNetAddrInfo.hh:280
XrdNetAddrInfo::SockSize
SOCKLEN_t SockSize()
Definition XrdNetAddrInfo.hh:289
XrdNetMsg::OK2Send
int OK2Send(int timeout, const char *dest)
Definition XrdNetMsg.cc:241

References destOK, dfltDest, eDest, FD, OK2Send(), retErr(), XrdNetAddr::Set(), XrdNetAddrInfo::SockAddr(), XrdNetAddrInfo::SockSize(), and Sokdata_t.

Referenced by XrdFrcReqAgent::Ping().

Here is the call graph for this function:
Here is the caller graph for this function:

## Send() [2/3]

int XrdNetMsg::Send | ( | const char * | dest,
|  | const XrdNetSockAddr & | netSA,
|  | const char * | buff,
|  | int | blen = 0,
|  | int | tmo = -1 )

Send a UDP message to an endpoint.

Parameters

  buff | The data to send.
  blen | Length of the data in buff. If not specified, the length is computed as strlen(buff).
  dest | The endpoint in the form as in "host:port". This is strictly used for error messages.
  netSA | The endpoint address. This overrides the constructor. The family must be AF_INET or AF_INET6.
  tmo | maximum seconds to wait for a idle socket. When negative, the default, no time limit applies.

Returns
  <0 Message not sent due to error.
  =0 Message send (well as defined by UDP)
  >0 Message not sent, timeout occurred.

Definition at line 168 of file XrdNetMsg.cc.

{
int aSize, retc;
if (!Blen && !(Blen = strlen(Buff))) return 0;
if (netSA.Addr.sa_family == AF_INET) aSize = sizeof(netSA.v4);
else if (netSA.Addr.sa_family == AF_INET6) aSize = sizeof(netSA.v6);
else return retErr(EAFNOSUPPORT, (dest ? dest : "Unknown!"));
if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
do {retc = sendto(FD, (Sokdata_t)Buff, Blen, 0, &netSA.Addr, aSize);}
while (retc < 0 && errno == EINTR);
if (retc >= 0) return 0;
return retErr(errno, (dest ? dest : "Unknown!"));
}
XrdNetSockAddr::v6
struct sockaddr_in6 v6
Definition XrdNetSockAddr.hh:43
XrdNetSockAddr::Addr
struct sockaddr Addr
Definition XrdNetSockAddr.hh:45
XrdNetSockAddr::v4
struct sockaddr_in v4
Definition XrdNetSockAddr.hh:44

References XrdNetSockAddr::Addr, FD, OK2Send(), retErr(), Sokdata_t, XrdNetSockAddr::v4, and XrdNetSockAddr::v6.

Here is the call graph for this function:

## Send() [3/3]

int XrdNetMsg::Send | ( | const struct iovec | iov[],
|  | int | iovcnt,
|  | const char * | dest = 0,
|  | int | tmo = -1 )

Send a UDP message to an endpoint using an I/O vector.

Parameters

  iov | The vector of data to send. Total amount be <= 4096 bytes.
  iovcnt | The number of elements in the vector.
  dest | The endpint name which can be host:port or a named socket. If dest is zero, uses dest specified in the constructor.
  tmo | maximum seconds to wait for a idle socket. When negative, the default, no time limit applies.

Returns
  <0 Message not sent due to error.
  =0 Message send (well as defined by UDP)
  >0 Message not sent, timeout occurred.

Definition at line 190 of file XrdNetMsg.cc.

{
// Handle the common case of sendingto the cobbected address
//
if (!dest)
{if (!destOK)
{eDest->Emsg("NetMsg", "Destination not specified."); return -1;}
if (tmo >= 0 && !OK2Send(tmo, dfltDest)) return 1;
if (writev(FD, iov, iovcnt) >= 0) return 0;
return retErr(errno, dfltDest);
}
// Caller want to send to a specific destination other than the default
//
XrdNetAddr specDest;
int retc;
if (specDest.Set(dest))
{eDest->Emsg("NetMsg", dest, "is unreachable"); return -1;}
// Create the message via the msghdr
//
struct msghdr mHdr{};
mHdr.msg_name = (void*)specDest.SockAddr();
mHdr.msg_namelen = specDest.SockSize();
mHdr.msg_iov = const_cast<struct iovec*>(iov);
mHdr.msg_iovlen = iovcnt;
// Handle timeout if need be
//
if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
// Send the message
//
do {retc = sendmsg(FD, &mHdr, 0);} while (retc < 0 && errno == EINTR);
// All done
//
return (retc < 0 ? retErr(errno, specDest) : 0);
}
writev
#define writev(a, b, c)
Definition XrdPosix.hh:117

References destOK, dfltDest, eDest, FD, OK2Send(), retErr(), XrdNetAddr::Set(), XrdNetAddrInfo::SockAddr(), XrdNetAddrInfo::SockSize(), and writev.

Here is the call graph for this function:

## Member Data Documentation

## destOK

bool XrdNetMsg::destOK = false

protected

Definition at line 148 of file XrdNetMsg.hh.

Referenced by XrdNetMsg(), retErr(), Send(), and Send().

## dfltDest

char* XrdNetMsg::dfltDest

protected

Definition at line 146 of file XrdNetMsg.hh.

Referenced by XrdNetMsg(), ~XrdNetMsg(), retErr(), Send(), and Send().

## eDest

XrdSysError* XrdNetMsg::eDest

protected

Definition at line 145 of file XrdNetMsg.hh.

Referenced by XrdNetMsg(), ~XrdNetMsg(), OK2Send(), retErr(), Send(), and Send().

## FD

int XrdNetMsg::FD = -1

protected

Definition at line 147 of file XrdNetMsg.hh.

Referenced by XrdNetMsg(), ~XrdNetMsg(), OK2Send(), Send(), Send(), and Send().

## isRefr

bool XrdNetMsg::isRefr = false

protected

Definition at line 149 of file XrdNetMsg.hh.

Referenced by ~XrdNetMsg().

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

- XrdNetMsg.hh
- XrdNetMsg.cc