XRootD
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)
 
 ~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

int destOK
 
XrdNetAddr dfltDest
 
XrdSysErroreDest
 
int FD
 
XrdNetAddr specDest
 

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 )

Constructor

Parameters
erpThe error message object for routing error messages.
aOKIf supplied, set to true upon success; false otherwise.
destThe 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.

Definition at line 44 of file XrdNetMsg.cc.

45{
46 XrdNet myNet(erp);
47 bool aok = true;
48
49 eDest = erp; FD = -1; destOK = 0;
50 if (dest)
51 {const char *eText = dfltDest.Set(dest);
52 if (!eText) destOK = 1;
53 else {eDest->Emsg("Msg", "Default", dest, "is unreachable");
54 aok = false;
55 }
56 }
57
58 if ((FD = myNet.Relay(dest)) < 0)
59 {eDest->Emsg("Msg", "Unable to create UDP msg socket.");
60 aok = false;
61 }
62
63 if (aOK) *aOK = aok;
64}
const char * Set(const char *hSpec, int pNum=PortInSpec)
XrdNetAddr dfltDest
Definition XrdNetMsg.hh:138
XrdSysError * eDest
Definition XrdNetMsg.hh:137
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References destOK, dfltDest, eDest, XrdSysError::Emsg(), FD, XrdNet::Relay(), and XrdNetAddr::Set().

+ Here is the call graph for this function:

◆ ~XrdNetMsg()

XrdNetMsg::~XrdNetMsg ( )
inline

Destructor.

Definition at line 130 of file XrdNetMsg.hh.

130{if (FD >= 0) close(FD);}
#define close(a)
Definition XrdPosix.hh:43

References close, and FD.

Member Function Documentation

◆ OK2Send()

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

Definition at line 144 of file XrdNetMsg.cc.

145{
146 struct pollfd polltab = {FD, POLLOUT|POLLWRNORM, 0};
147 int retc;
148
149 do {retc = poll(&polltab, 1, timeout);} while(retc < 0 && errno == EINTR);
150
151 if (retc == 0 || !(polltab.revents & (POLLOUT | POLLWRNORM)))
152 eDest->Emsg("Msg", "UDP link to", dest, "is blocked.");
153 else if (retc < 0)
154 eDest->Emsg("Msg",errno,"poll", dest);
155 else return 1;
156 return 0;
157}

References eDest, XrdSysError::Emsg(), and FD.

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

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

◆ retErr() [1/2]

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

Definition at line 163 of file XrdNetMsg.cc.

164{
165 if (!theDest)
166 {if (!destOK)
167 {eDest->Emsg("Msg", "Destination not specified."); return -1;}
168 theDest = dfltDest.Name("unknown");
169 }
170 eDest->Emsg("Msg", ecode, "send to", theDest);
171 return (EWOULDBLOCK == ecode || EAGAIN == ecode ? 1 : -1);
172}
const char * Name(const char *eName=0, const char **eText=0)

References destOK, dfltDest, eDest, XrdSysError::Emsg(), and XrdNetAddrInfo::Name().

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

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

◆ retErr() [2/2]

int XrdNetMsg::retErr ( int ecode,
XrdNetAddr * theDest )
protected

Definition at line 174 of file XrdNetMsg.cc.

175{
176 return retErr(ecode, theDest->Name("unknown"));
177}
int retErr(int ecode, const char *theDest)
Definition XrdNetMsg.cc:163

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
buffThe data to send.
blenLength of the data in buff. If not specified, the length is computed as strlen(buff).
destThe endpint name which can be host:port or a named socket. If dest is zero, uses dest specified in the constructor.
tmomaximum 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 70 of file XrdNetMsg.cc.

71{
72 XrdNetAddr *theDest;
73 int retc;
74
75 if (!Blen && !(Blen = strlen(Buff))) return 0;
76
77 if (!dest)
78 {if (!destOK)
79 {eDest->Emsg("Msg", "Destination not specified."); return -1;}
80 theDest = &dfltDest;
81 }
82 else if (specDest.Set(dest))
83 {eDest->Emsg("Msg", dest, "is unreachable"); return -1;}
84 else theDest = &specDest;
85
86 if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
87
88 do {retc = sendto(FD, (Sokdata_t)Buff, Blen, 0,
89 theDest->SockAddr(), theDest->SockSize());}
90 while (retc < 0 && errno == EINTR);
91
92 return (retc < 0 ? retErr(errno, theDest) : 0);
93}
#define Sokdata_t
const sockaddr * SockAddr()
SOCKLEN_t SockSize()
XrdNetAddr specDest
Definition XrdNetMsg.hh:139
int OK2Send(int timeout, const char *dest)
Definition XrdNetMsg.cc:144

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

Referenced by XrdXrootdGSReal::GetDictID(), XrdXrootdGSReal::Ident(), XrdCmsPrepare::Inform(), XrdFrcReqAgent::Ping(), XrdStats::Report(), Send(), and XrdXrootdMonitor::Send().

+ 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
buffThe data to send.
blenLength of the data in buff. If not specified, the length is computed as strlen(buff).
destThe endpoint in the form as in "host:port".
netSAThe endpoint address. This overrides the constructor.
tmomaximum 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 97 of file XrdNetMsg.cc.

99{
100 int aSize, retc;
101
102 if (!Blen && !(Blen = strlen(Buff))) return 0;
103
104 if (netSA.Addr.sa_family == AF_INET) aSize = sizeof(netSA.v4);
105 else if (netSA.Addr.sa_family == AF_INET6) aSize = sizeof(netSA.v6);
106 else return -1;
107
108 if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
109
110 do {retc = sendto(FD, (Sokdata_t)Buff, Blen, 0, &netSA.Addr, aSize);}
111 while (retc < 0 && errno == EINTR);
112
113 if (retc >= 0) return 1;
114 return (EWOULDBLOCK == errno || EAGAIN == errno ? 1 : -1);
115}
struct sockaddr_in6 v6
struct sockaddr Addr
struct sockaddr_in v4

References XrdNetSockAddr::Addr, FD, OK2Send(), 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
iovThe vector of data to send. Total amount be <= 4096 bytes.
iovcntThe number of elements in the vector.
destThe endpint name which can be host:port or a named socket. If dest is zero, uses dest specified in the constructor.
tmomaximum 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 119 of file XrdNetMsg.cc.

121{
122 char buff[4096], *bp = buff;
123 int i, dsz = sizeof(buff);
124
125 if (tmo >= 0 && !OK2Send(tmo, dest)) return 1;
126
127 for (i = 0; i < iovcnt; i++)
128 {dsz -= iov[i].iov_len;
129 if (dsz < 0) return retErr(EMSGSIZE, dest);
130 memcpy((void *)bp,(const void *)iov[i].iov_base,iov[i].iov_len);
131 bp += iov[i].iov_len;
132 }
133
134 return Send(buff, (int)(bp-buff), dest, -1);
135}
int Send(const char *buff, int blen=0, const char *dest=0, int tmo=-1)
Definition XrdNetMsg.cc:70

References OK2Send(), retErr(), and Send().

+ Here is the call graph for this function:

Member Data Documentation

◆ destOK

int XrdNetMsg::destOK
protected

Definition at line 140 of file XrdNetMsg.hh.

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

◆ dfltDest

XrdNetAddr XrdNetMsg::dfltDest
protected

Definition at line 138 of file XrdNetMsg.hh.

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

◆ eDest

XrdSysError* XrdNetMsg::eDest
protected

Definition at line 137 of file XrdNetMsg.hh.

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

◆ FD

int XrdNetMsg::FD
protected

Definition at line 141 of file XrdNetMsg.hh.

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

◆ specDest

XrdNetAddr XrdNetMsg::specDest
protected

Definition at line 139 of file XrdNetMsg.hh.

Referenced by Send().


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