XRootD
XrdNetRefresh Class Reference

#include <XrdNetRefresh.hh>

+ Inheritance diagram for XrdNetRefresh:
+ Collaboration diagram for XrdNetRefresh:

Public Member Functions

 XrdNetRefresh ()
 
virtual ~XrdNetRefresh ()
 
virtual void DoIt () override
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Static Public Member Functions

static bool Register (XrdNetPeer &Peer)
 
static void Start (XrdSysLogger *logP, XrdScheduler *sP)
 
static void UnRegister (int fd)
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 39 of file XrdNetRefresh.hh.

Constructor & Destructor Documentation

◆ XrdNetRefresh()

XrdNetRefresh::XrdNetRefresh ( )
inline

Definition at line 51 of file XrdNetRefresh.hh.

51 : XrdJob("NetRefresh") {}
XrdJob(const char *desc="")
Definition: XrdJob.hh:51

◆ ~XrdNetRefresh()

virtual XrdNetRefresh::~XrdNetRefresh ( )
inlinevirtual

Definition at line 52 of file XrdNetRefresh.hh.

52 {}

Member Function Documentation

◆ DoIt()

void XrdNetRefresh::DoIt ( )
overridevirtual

Implements XrdJob.

Definition at line 94 of file XrdNetRefresh.cc.

95 {
96 
97 // Run the address updater
98 //
99  Update();
100 
101 // Reschedule ourselves
102 //
103  schedP->Schedule(this, time(0)+udpRefr);
104 }
void Schedule(XrdJob *jp)
XrdScheduler * schedP

References XrdOfsPrepGPIReal::schedP, XrdScheduler::Schedule(), and XrdNetSocketCFG::udpRefr.

+ Here is the call graph for this function:

◆ Register()

bool XrdNetRefresh::Register ( XrdNetPeer Peer)
static

Definition at line 120 of file XrdNetRefresh.cc.

121 {
122  static unsigned int INum = 0;
123 
124 // Make sure we have a valid hostname
125 //
126  if (!Peer.InetName) return RegFail("hostname missing");
127 
128  if (index(Peer.InetName, '!')) return RegFail("invalid hostname");
129 
130 // Make sure file discriptor is not negative
131 //
132  if (Peer.fd < 0) return RegFail("invalid socket descriptor");
133 
134 // Make sure the file descriptor is a UDP socket
135 //
136  struct stat Stat;
137  fstat(Peer.fd, &Stat);
138  if (!S_ISSOCK(Stat.st_mode)) return RegFail("not a socket");
139 
140  int sockType;
141  socklen_t stLen = sizeof(sockType);
142 
143  if (getsockopt(Peer.fd, SOL_SOCKET, SO_TYPE, (void*)&sockType, &stLen)
144  || sockType != SOCK_DGRAM) return RegFail("not a UDP socket");
145 
146 // Constrcut a new info structure to insert into the map
147 //
148  RefInfo newRef(Peer.InetName, INum++);
149 
150 // Add port number to the registration name (v4 and v6 ports are the same)
151 //
152  newRef.destHN.append(":");
153  newRef.destHN.append(std::to_string(ntohs(Peer.Inet.v4.sin_port)));
154 
155 // Lock the map
156 //
157  XrdSysMutexHelper mHelp(refMTX);
158 
159 // Attempt to insert the element, verify that it happened
160 //
161  auto ret = fd2Info.insert(std::pair<int, RefInfo>(Peer.fd, newRef));
162  if (ret.second==false)
163  {char buff[32];
164  snprintf(buff, sizeof(buff), "(%d)", Peer.fd);
165  eDest.Emsg("Refresh", "Peer cannot be registered"
166  "duplicate socket descriptor", buff);
167  return false;
168  }
169 
170 // All done, it went well
171 //
172  return true;
173 }
struct stat Stat
Definition: XrdCks.cc:49
static XrdSysError eDest(0,"crypto_")
struct sockaddr_in v4
#define fstat(a, b)
Definition: XrdPosix.hh:62
#define stat(a, b)
Definition: XrdPosix.hh:101
XrdNetSockAddr Inet
Definition: XrdNetPeer.hh:43
char * InetName
Definition: XrdNetPeer.hh:44
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References eDest, XrdSysError::Emsg(), XrdNetPeer::fd, fstat, XrdNetPeer::Inet, XrdNetPeer::InetName, Stat, stat, and XrdNetSockAddr::v4.

Referenced by XrdNetMsg::XrdNetMsg().

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

◆ Start()

void XrdNetRefresh::Start ( XrdSysLogger logP,
XrdScheduler sP 
)
static

Definition at line 179 of file XrdNetRefresh.cc.

180 {
181 // Set pointers we will need
182 //
183  eDest.logger(logP);
184  schedP = sP;
185 
186 // We allocate an instance of this object so that we can schedule it.
187 //
188  NetRefresh = new XrdNetRefresh();
189 
190 // Now schedule it to refresh UDP destinations
191 //
192  schedP->Schedule(NetRefresh, time(0)+udpRefr);
193 }
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
XrdNetRefresh * NetRefresh

References eDest, XrdSysError::logger(), XrdNetSocketCFG::NetRefresh, XrdOfsPrepGPIReal::schedP, XrdScheduler::Schedule(), and XrdNetSocketCFG::udpRefr.

Referenced by XrdConfig::Configure().

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

◆ UnRegister()

void XrdNetRefresh::UnRegister ( int  fd)
static

Definition at line 199 of file XrdNetRefresh.cc.

200 {
201  XrdSysMutexHelper mHelp(refMTX);
202 
203 // Attempt to delete the fd from out set
204 //
205  if (!fd2Info.erase(fd))
206  {char buff[32];
207  snprintf(buff, sizeof(buff), "%d)", fd);
208  eDest.Emsg("Refresh", "Atempt to unregisted non-existent fd:",buff);
209  }
210 }

References eDest, and XrdSysError::Emsg().

Referenced by XrdNetMsg::~XrdNetMsg().

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

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