XRootD
XrdLink.hh
Go to the documentation of this file.
1 #ifndef __XRD_LINK_H__
2 #define __XRD_LINK_H__
3 /******************************************************************************/
4 /* */
5 /* X r d L i n k . h h */
6 /* */
7 /* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <sys/types.h>
33 
34 #include "XrdNet/XrdNetAddr.hh"
35 #include "XrdOuc/XrdOucSFVec.hh"
36 #include "XrdSys/XrdSysPthread.hh"
37 
38 #include "Xrd/XrdJob.hh"
39 
40 /******************************************************************************/
41 /* C l a s s D e f i n i t i o n */
42 /******************************************************************************/
43 
44 class XrdLinkMatch;
45 class XrdLinkXeq;
46 class XrdPollInfo;
47 class XrdProtocol;
48 class XrdTlsPeerCerts;
49 class XrdTlsContext;
50 
51 class XrdLink : public XrdJob
52 {
53 public:
54 
55 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 
61 bool Activate();
62 
63 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
69 
71 
72 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
77 
78 int Backlog();
79 
80 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
89 
90 int Client(char *buff, int blen);
91 
92 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
101 
102 int Close(bool defer=false);
103 
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 
108 void Enable();
109 
110 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 
116 int FDnum();
117 
118 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 
134 static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
135 
136 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
149 
150  int getIOStats(long long &inbytes, long long &outbytes,
151  int &numstall, int &numtardy);
152 
153 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
168 
169 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
170 
171 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
179 
181 
182 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
185 
187 
188 //-----------------------------------------------------------------------------
193 //-----------------------------------------------------------------------------
194 
195 void Hold(bool lk);
196 
197 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
203 
204 const char *Host() const {return (const char *)HostName;}
205 
206 //-----------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
209 
210 char *ID; // This is referenced a lot (should have been const).
211 
212 //-----------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------
217 
218 unsigned int Inst() const {return Instance;}
219 
220 //-----------------------------------------------------------------------------
225 //-----------------------------------------------------------------------------
226 
227 bool isFlawed() const;
228 
229 //-----------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------
238 
239 bool isInstance(unsigned int inst) const;
240 
241 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
247 
248 const char *Name() const;
249 
250 //-----------------------------------------------------------------------------
255 //-----------------------------------------------------------------------------
256 const
257 XrdNetAddr *NetAddr() const;
258 
259 //-----------------------------------------------------------------------------
269 //-----------------------------------------------------------------------------
270 
271 int Peek(char *buff, int blen, int timeout=-1);
272 
273 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
283 
284 int Recv(char *buff, int blen);
285 
286 //-----------------------------------------------------------------------------
299 //-----------------------------------------------------------------------------
300 
301 int Recv(char *buff, int blen, int timeout);
302 
303 //-----------------------------------------------------------------------------
316 //-----------------------------------------------------------------------------
317 
318 int Recv(const struct iovec *iov, int iocnt, int timeout);
319 
320 //-----------------------------------------------------------------------------
333 //-----------------------------------------------------------------------------
334 
335 int RecvAll(char *buff, int blen, int timeout=-1);
336 
337 //------------------------------------------------------------------------------
346 //------------------------------------------------------------------------------
347 
348 bool Register(const char *hName);
349 
350 //-----------------------------------------------------------------------------
359 //-----------------------------------------------------------------------------
360 
361 int Send(const char *buff, int blen);
362 
363 //-----------------------------------------------------------------------------
373 //-----------------------------------------------------------------------------
374 
375 int Send(const struct iovec *iov, int iocnt, int bytes=0);
376 
377 //-----------------------------------------------------------------------------
386 //-----------------------------------------------------------------------------
387 
388 static bool sfOK; // True if Send(sfVec) enabled
389 
391 
392 int Send(const sfVec *sdP, int sdn); // Iff sfOK is true
393 
394 //-----------------------------------------------------------------------------
396 //-----------------------------------------------------------------------------
397 
398 void Serialize();
399 
400 //-----------------------------------------------------------------------------
407 //-----------------------------------------------------------------------------
408 
409 int setEtext(const char *text);
410 
411 //-----------------------------------------------------------------------------
416 //-----------------------------------------------------------------------------
417 
418 void setID(const char *userid, int procid);
419 
420 //-----------------------------------------------------------------------------
424 //-----------------------------------------------------------------------------
425 
427 
428 //-----------------------------------------------------------------------------
433 //-----------------------------------------------------------------------------
434 
435 bool setNB();
436 
437 //-----------------------------------------------------------------------------
445 //-----------------------------------------------------------------------------
446 
447 XrdProtocol *setProtocol(XrdProtocol *pp, bool runit=false, bool push=false);
448 
449 //-----------------------------------------------------------------------------
454 //-----------------------------------------------------------------------------
455 
456 void setProtName(const char *name);
457 
458 //-----------------------------------------------------------------------------
462 //-----------------------------------------------------------------------------
463 
464 void setRef(int cnt);
465 
466 //-----------------------------------------------------------------------------
468 //
476 //-----------------------------------------------------------------------------
477 
478 bool setTLS(bool enable, XrdTlsContext *ctx=0);
479 
480 //-----------------------------------------------------------------------------
484 //-----------------------------------------------------------------------------
485 
486 void Shutdown(bool getLock);
487 
488 //-----------------------------------------------------------------------------
497 //-----------------------------------------------------------------------------
498 
499 static int Stats(char *buff, int blen, bool do_sync=0);
500 
501 //-----------------------------------------------------------------------------
505 //-----------------------------------------------------------------------------
506 
507 void syncStats(int *ctime=0);
508 
509 //-----------------------------------------------------------------------------
525 //-----------------------------------------------------------------------------
526 
527 int Terminate(const char *owner, int fdnum, unsigned int inst);
528 
529 //-----------------------------------------------------------------------------
531 //-----------------------------------------------------------------------------
532 
533 time_t timeCon() const;
534 
535 //-----------------------------------------------------------------------------
537 //-----------------------------------------------------------------------------
538 
539 int UseCnt() const;
540 
541 //-----------------------------------------------------------------------------
543 //-----------------------------------------------------------------------------
544 
545 void armBridge();
546 
547 //-----------------------------------------------------------------------------
552 //-----------------------------------------------------------------------------
553 
554 bool hasBridge() const {return isBridged;}
555 
556 //-----------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------
562 
563 bool hasTLS() const {return isTLS;}
564 
565 //-----------------------------------------------------------------------------
570 //-----------------------------------------------------------------------------
571 
572 const char *verTLS();
573 
574 //-----------------------------------------------------------------------------
578 //-----------------------------------------------------------------------------
579 
580  XrdLink(XrdLinkXeq &lxq);
581 
582 protected:
583  ~XrdLink() {} // Is never deleted!
584 
585 void DoIt(); // This is an override of XrdJob::DoIt.
586 void ResetLink();
587 int Wait4Data(int timeout);
588 
589 void *rsvd1[3]; // Reserved for future use
590 XrdLinkXeq &linkXQ; // The implementation
591 char *HostName; // Pointer to the hostname
592 unsigned int Instance; // Instance number of this object
593 bool isBridged; // If true, this link is an in-memory bridge
594 bool isTLS; // If true, this link uses TLS for all I/O
595 char rsvd2[2];
596 };
597 #endif
Definition: XrdJob.hh:43