00001 #ifndef __XRD_LINK_H__ 00002 #define __XRD_LINK_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d L i n k . h h */ 00006 /* */ 00007 /* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <sys/types.h> 00033 00034 #include "XrdNet/XrdNetAddr.hh" 00035 #include "XrdOuc/XrdOucSFVec.hh" 00036 #include "XrdSys/XrdSysPthread.hh" 00037 00038 #include "Xrd/XrdJob.hh" 00039 00040 /******************************************************************************/ 00041 /* C l a s s D e f i n i t i o n */ 00042 /******************************************************************************/ 00043 00044 class XrdLinkMatch; 00045 class XrdLinkXeq; 00046 class XrdPollInfo; 00047 class XrdProtocol; 00048 class XrdTlsPeerCerts; 00049 class XrdTlsContext; 00050 00051 class XrdLink : public XrdJob 00052 { 00053 public: 00054 00055 //----------------------------------------------------------------------------- 00059 //----------------------------------------------------------------------------- 00060 00061 bool Activate(); 00062 00063 //----------------------------------------------------------------------------- 00068 //----------------------------------------------------------------------------- 00069 00070 XrdNetAddrInfo *AddrInfo(); 00071 00072 //----------------------------------------------------------------------------- 00076 //----------------------------------------------------------------------------- 00077 00078 int Backlog(); 00079 00080 //----------------------------------------------------------------------------- 00088 //----------------------------------------------------------------------------- 00089 00090 int Client(char *buff, int blen); 00091 00092 //----------------------------------------------------------------------------- 00100 //----------------------------------------------------------------------------- 00101 00102 int Close(bool defer=false); 00103 00104 //----------------------------------------------------------------------------- 00106 //----------------------------------------------------------------------------- 00107 00108 void Enable(); 00109 00110 //----------------------------------------------------------------------------- 00114 //----------------------------------------------------------------------------- 00115 00116 int FDnum(); 00117 00118 //----------------------------------------------------------------------------- 00132 //----------------------------------------------------------------------------- 00133 00134 static XrdLink *Find(int &curr, XrdLinkMatch *who=0); 00135 00136 //----------------------------------------------------------------------------- 00148 //----------------------------------------------------------------------------- 00149 00150 int getIOStats(long long &inbytes, long long &outbytes, 00151 int &numstall, int &numtardy); 00152 00153 //----------------------------------------------------------------------------- 00167 //----------------------------------------------------------------------------- 00168 00169 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0); 00170 00171 //----------------------------------------------------------------------------- 00178 //----------------------------------------------------------------------------- 00179 00180 XrdTlsPeerCerts *getPeerCerts(); 00181 00182 //----------------------------------------------------------------------------- 00184 //----------------------------------------------------------------------------- 00185 00186 XrdProtocol *getProtocol(); 00187 00188 //----------------------------------------------------------------------------- 00193 //----------------------------------------------------------------------------- 00194 00195 void Hold(bool lk); 00196 00197 //----------------------------------------------------------------------------- 00202 //----------------------------------------------------------------------------- 00203 00204 const char *Host() const {return (const char *)HostName;} 00205 00206 //----------------------------------------------------------------------------- 00208 //----------------------------------------------------------------------------- 00209 00210 char *ID; // This is referenced a lot (should have been const). 00211 00212 //----------------------------------------------------------------------------- 00216 //----------------------------------------------------------------------------- 00217 00218 unsigned int Inst() const {return Instance;} 00219 00220 //----------------------------------------------------------------------------- 00225 //----------------------------------------------------------------------------- 00226 00227 bool isFlawed() const; 00228 00229 //----------------------------------------------------------------------------- 00237 //----------------------------------------------------------------------------- 00238 00239 bool isInstance(unsigned int inst) const; 00240 00241 //----------------------------------------------------------------------------- 00246 //----------------------------------------------------------------------------- 00247 00248 const char *Name() const; 00249 00250 //----------------------------------------------------------------------------- 00255 //----------------------------------------------------------------------------- 00256 const 00257 XrdNetAddr *NetAddr() const; 00258 00259 //----------------------------------------------------------------------------- 00269 //----------------------------------------------------------------------------- 00270 00271 int Peek(char *buff, int blen, int timeout=-1); 00272 00273 //----------------------------------------------------------------------------- 00282 //----------------------------------------------------------------------------- 00283 00284 int Recv(char *buff, int blen); 00285 00286 //----------------------------------------------------------------------------- 00299 //----------------------------------------------------------------------------- 00300 00301 int Recv(char *buff, int blen, int timeout); 00302 00303 //----------------------------------------------------------------------------- 00315 //----------------------------------------------------------------------------- 00316 00317 int RecvAll(char *buff, int blen, int timeout=-1); 00318 00319 //------------------------------------------------------------------------------ 00328 //------------------------------------------------------------------------------ 00329 00330 bool Register(const char *hName); 00331 00332 //----------------------------------------------------------------------------- 00341 //----------------------------------------------------------------------------- 00342 00343 int Send(const char *buff, int blen); 00344 00345 //----------------------------------------------------------------------------- 00355 //----------------------------------------------------------------------------- 00356 00357 int Send(const struct iovec *iov, int iocnt, int bytes=0); 00358 00359 //----------------------------------------------------------------------------- 00368 //----------------------------------------------------------------------------- 00369 00370 static bool sfOK; // True if Send(sfVec) enabled 00371 00372 typedef XrdOucSFVec sfVec; 00373 00374 int Send(const sfVec *sdP, int sdn); // Iff sfOK is true 00375 00376 //----------------------------------------------------------------------------- 00378 //----------------------------------------------------------------------------- 00379 00380 void Serialize(); 00381 00382 //----------------------------------------------------------------------------- 00389 //----------------------------------------------------------------------------- 00390 00391 int setEtext(const char *text); 00392 00393 //----------------------------------------------------------------------------- 00398 //----------------------------------------------------------------------------- 00399 00400 void setID(const char *userid, int procid); 00401 00402 //----------------------------------------------------------------------------- 00406 //----------------------------------------------------------------------------- 00407 00408 void setLocation(XrdNetAddrInfo::LocInfo &loc); 00409 00410 //----------------------------------------------------------------------------- 00415 //----------------------------------------------------------------------------- 00416 00417 bool setNB(); 00418 00419 //----------------------------------------------------------------------------- 00427 //----------------------------------------------------------------------------- 00428 00429 XrdProtocol *setProtocol(XrdProtocol *pp, bool runit=false, bool push=false); 00430 00431 //----------------------------------------------------------------------------- 00436 //----------------------------------------------------------------------------- 00437 00438 void setProtName(const char *name); 00439 00440 //----------------------------------------------------------------------------- 00444 //----------------------------------------------------------------------------- 00445 00446 void setRef(int cnt); 00447 00448 //----------------------------------------------------------------------------- 00450 // 00458 //----------------------------------------------------------------------------- 00459 00460 bool setTLS(bool enable, XrdTlsContext *ctx=0); 00461 00462 //----------------------------------------------------------------------------- 00466 //----------------------------------------------------------------------------- 00467 00468 void Shutdown(bool getLock); 00469 00470 //----------------------------------------------------------------------------- 00479 //----------------------------------------------------------------------------- 00480 00481 static int Stats(char *buff, int blen, bool do_sync=0); 00482 00483 //----------------------------------------------------------------------------- 00487 //----------------------------------------------------------------------------- 00488 00489 void syncStats(int *ctime=0); 00490 00491 //----------------------------------------------------------------------------- 00507 //----------------------------------------------------------------------------- 00508 00509 int Terminate(const char *owner, int fdnum, unsigned int inst); 00510 00511 //----------------------------------------------------------------------------- 00513 //----------------------------------------------------------------------------- 00514 00515 time_t timeCon() const; 00516 00517 //----------------------------------------------------------------------------- 00519 //----------------------------------------------------------------------------- 00520 00521 int UseCnt() const; 00522 00523 //----------------------------------------------------------------------------- 00525 //----------------------------------------------------------------------------- 00526 00527 void armBridge(); 00528 00529 //----------------------------------------------------------------------------- 00534 //----------------------------------------------------------------------------- 00535 00536 bool hasBridge() const {return isBridged;} 00537 00538 //----------------------------------------------------------------------------- 00546 //----------------------------------------------------------------------------- 00547 00548 bool hasTLS() const {return isTLS;} 00549 00550 //----------------------------------------------------------------------------- 00555 //----------------------------------------------------------------------------- 00556 00557 const char *verTLS(); 00558 00559 //----------------------------------------------------------------------------- 00563 //----------------------------------------------------------------------------- 00564 00565 XrdLink(XrdLinkXeq &lxq); 00566 00567 protected: 00568 ~XrdLink() {} // Is never deleted! 00569 00570 void DoIt(); // This is an override of XrdJob::DoIt. 00571 void ResetLink(); 00572 int Wait4Data(int timeout); 00573 00574 void *rsvd1[3]; // Reserved for future use 00575 XrdLinkXeq &linkXQ; // The implementation 00576 char *HostName; // Pointer to the hostname 00577 unsigned int Instance; // Instance number of this object 00578 bool isBridged; // If true, this link is an in-memory bridge 00579 bool isTLS; // If true, this link uses TLS for all I/O 00580 char rsvd2[2]; 00581 }; 00582 #endif