XRootD
XrdLinkXeq.hh
Go to the documentation of this file.
1 #ifndef __XRD_LINKXEQ_H__
2 #define __XRD_LINKXEQ_H__
3 /******************************************************************************/
4 /* */
5 /* X r d L i n k X e q . 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 #include <fcntl.h>
34 #include <ctime>
35 
36 #include "Xrd/XrdLink.hh"
37 #include "Xrd/XrdLinkInfo.hh"
38 #include "Xrd/XrdPollInfo.hh"
39 #include "Xrd/XrdProtocol.hh"
40 
41 #include "XrdNet/XrdNetAddr.hh"
42 
43 #include "XrdTls/XrdTls.hh"
44 #include "XrdTls/XrdTlsSocket.hh"
45 
46 /******************************************************************************/
47 /* C l a s s D e f i n i t i o n */
48 /******************************************************************************/
49 
50 class XrdSendQ;
51 
52 class XrdLinkXeq : protected XrdLink
53 {
54 public:
55 
56 inline
58 
59 int Backlog();
60 
61 int Client(char *buff, int blen);
62 
63 int Close(bool defer=false);
64 
65 void DoIt(); // Override
66 
67 
68  int getIOStats(long long &inbytes, long long &outbytes,
69  int &numstall, int &numtardy)
70  { inbytes = BytesIn + BytesInTot;
71  outbytes = BytesOut+BytesOutTot;
72  numstall = stallCnt + stallCntTot;
73  numtardy = tardyCnt + tardyCntTot;
74  return LinkInfo.InUse;
75  }
76 
78 
79 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
80 
81 inline
83 
84 inline
85 const char *Name() const {return (const char *)Lname;}
86 
87 inline const
88 XrdNetAddr *NetAddr() const {return &Addr;}
89 
90 int Peek(char *buff, int blen, int timeout=-1);
91 
92 int Recv(char *buff, int blen);
93 int Recv(char *buff, int blen, int timeout);
94 int Recv(const struct iovec *iov, int iocnt, int timeout);
95 
96 int RecvAll(char *buff, int blen, int timeout=-1);
97 
98 bool Register(const char *hName);
99 
100 int Send(const char *buff, int blen);
101 int Send(const struct iovec *iov, int iocnt, int bytes=0);
102 
103 int Send(const sfVec *sdP, int sdn); // Iff sfOK > 0
104 
105 void setID(const char *userid, int procid);
106 
108 
109 bool setNB();
110 
111 XrdProtocol *setProtocol(XrdProtocol *pp, bool push);
112 
113 void setProtName(const char *name);
114 
115 bool setTLS(bool enable, XrdTlsContext *ctx=0);
116 
117  void Shutdown(bool getLock);
118 
119 static int Stats(char *buff, int blen, bool do_sync=false);
120 
121  void syncStats(int *ctime=0);
122 
123 int TLS_Peek(char *Buff, int Blen, int timeout);
124 
125 int TLS_Recv(char *Buff, int Blen);
126 
127 int TLS_Recv(char *Buff, int Blen, int timeout, bool havelock=false);
128 
129 int TLS_Recv(const struct iovec *iov, int iocnt, int timeout);
130 
131 int TLS_RecvAll(char *Buff, int Blen, int timeout);
132 
133 int TLS_Send(const char *Buff, int Blen);
134 
135 int TLS_Send(const struct iovec *iov, int iocnt, int bytes);
136 
137 int TLS_Send(const sfVec *sfP, int sfN);
138 
139 const char *verTLS();
140 
141 bool RegisterCloseRequestCb(XrdProtocol *pp, bool (*cb)(void*),
142  void* cbarg);
143 
144  XrdLinkXeq();
145  ~XrdLinkXeq() {} // Is never deleted!
146 
149 
150 protected:
151 
152 int RecvIOV(const struct iovec *iov, int iocnt);
153 void Reset();
154 int sendData(const char *Buff, int Blen);
155 int SendIOV(const struct iovec *iov, int iocnt, int bytes);
156 int SFError(int rc);
157 int TLS_Error(const char *act, XrdTls::RC rc);
158 bool TLS_Write(const char *Buff, int Blen);
159 
160 static const char *TraceID;
161 
162 // Statistical area (global and local)
163 //
164 static long long LinkBytesIn;
165 static long long LinkBytesOut;
166 static long long LinkConTime;
167 static long long LinkCountTot;
168 static int LinkCount;
169 static int LinkCountMax;
170 static int LinkTimeOuts;
171 static int LinkStalls;
172 static int LinkSfIntr;
173  long long BytesIn;
174  long long BytesInTot;
175  long long BytesOut;
176  long long BytesOutTot;
177  int stallCnt;
179  int tardyCnt;
181  int SfIntr;
183 
184 // Protocol section
185 //
186 XrdProtocol *Protocol; // -> Protocol tied to the link
187 XrdProtocol *ProtoAlt; // -> Alternate/stacked protocol
188 bool (*CloseRequestCb)(void*);
190 
191 // TLS section
192 //
194 
195 // Identification section
196 //
200 XrdSendQ *sendQ; // Protected by wrMutex && opMutex
201 int HNlen;
203 bool KeepFD;
204 char isIdle;
205 char Uname[24]; // Uname and Lname must be adjacent!
206 char Lname[256];
207 };
208 #endif
static const char * TraceID
Definition: XrdLinkXeq.hh:160
bool(* CloseRequestCb)(void *)
Definition: XrdLinkXeq.hh:188
int TLS_Send(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1328
long long BytesOut
Definition: XrdLinkXeq.hh:175
int TLS_Error(const char *act, XrdTls::RC rc)
Definition: XrdLinkXeq.cc:1161
int TLS_Peek(char *Buff, int Blen, int timeout)
Definition: XrdLinkXeq.cc:1175
int stallCntTot
Definition: XrdLinkXeq.hh:178
int Client(char *buff, int blen)
Definition: XrdLinkXeq.cc:153
char Uname[24]
Definition: XrdLinkXeq.hh:205
XrdTlsPeerCerts * getPeerCerts()
Definition: XrdLinkXeq.cc:331
static int LinkCountMax
Definition: XrdLinkXeq.hh:169
XrdLinkInfo LinkInfo
Definition: XrdLinkXeq.hh:147
const char * Name() const
Definition: XrdLinkXeq.hh:85
XrdProtocol * ProtoAlt
Definition: XrdLinkXeq.hh:187
int Close(bool defer=false)
Definition: XrdLinkXeq.cc:173
XrdNetAddr Addr
Definition: XrdLinkXeq.hh:197
int TLS_Recv(char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1207
int sendData(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:824
long long BytesInTot
Definition: XrdLinkXeq.hh:174
bool TLS_Write(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1435
int SendIOV(const struct iovec *iov, int iocnt, int bytes)
Definition: XrdLinkXeq.cc:847
XrdProtocol * setProtocol(XrdProtocol *pp, bool push)
Definition: XrdLinkXeq.cc:941
static long long LinkCountTot
Definition: XrdLinkXeq.hh:167
long long BytesOutTot
Definition: XrdLinkXeq.hh:176
void Shutdown(bool getLock)
Definition: XrdLinkXeq.cc:1036
int Peek(char *buff, int blen, int timeout=-1)
Definition: XrdLinkXeq.cc:340
static int LinkCount
Definition: XrdLinkXeq.hh:168
void Reset()
Definition: XrdLinkXeq.cc:113
int Backlog()
Definition: XrdLinkXeq.cc:140
static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0)
XrdSysMutex wrMutex
Definition: XrdLinkXeq.hh:199
static int Stats(char *buff, int blen, bool do_sync=false)
Definition: XrdLinkXeq.cc:1068
XrdSendQ * sendQ
Definition: XrdLinkXeq.hh:200
XrdPollInfo PollInfo
Definition: XrdLinkXeq.hh:148
void setID(const char *userid, int procid)
Definition: XrdLinkXeq.cc:888
bool LockReads
Definition: XrdLinkXeq.hh:202
XrdNetAddrInfo * AddrInfo()
Definition: XrdLinkXeq.hh:57
int Recv(char *buff, int blen)
Definition: XrdLinkXeq.cc:383
static long long LinkBytesIn
Definition: XrdLinkXeq.hh:164
void * CloseRequestCbArg
Definition: XrdLinkXeq.hh:189
int TLS_RecvAll(char *Buff, int Blen, int timeout)
Definition: XrdLinkXeq.cc:1306
int SFError(int rc)
Definition: XrdLinkXeq.cc:1026
long long BytesIn
Definition: XrdLinkXeq.hh:173
int tardyCntTot
Definition: XrdLinkXeq.hh:180
const XrdNetAddr * NetAddr() const
Definition: XrdLinkXeq.hh:88
int Send(const char *buff, int blen)
Definition: XrdLinkXeq.cc:602
XrdSysMutex rdMutex
Definition: XrdLinkXeq.hh:198
const char * verTLS()
Definition: XrdLinkXeq.cc:1460
bool setNB()
Definition: XrdLinkXeq.cc:912
int RecvIOV(const struct iovec *iov, int iocnt)
Definition: XrdLinkXeq.cc:561
char Lname[256]
Definition: XrdLinkXeq.hh:206
static long long LinkConTime
Definition: XrdLinkXeq.hh:166
static int LinkSfIntr
Definition: XrdLinkXeq.hh:172
XrdTlsSocket tlsIO
Definition: XrdLinkXeq.hh:193
void DoIt()
Definition: XrdLinkXeq.cc:293
void setLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdLinkXeq.hh:107
int RecvAll(char *buff, int blen, int timeout=-1)
Definition: XrdLinkXeq.cc:519
XrdProtocol * Protocol
Definition: XrdLinkXeq.hh:186
bool Register(const char *hName)
Definition: XrdLinkXeq.cc:583
static XrdSysMutex statsMutex
Definition: XrdLinkXeq.hh:182
void setProtName(const char *name)
Definition: XrdLinkXeq.cc:958
static int LinkStalls
Definition: XrdLinkXeq.hh:171
static long long LinkBytesOut
Definition: XrdLinkXeq.hh:165
void syncStats(int *ctime=0)
Definition: XrdLinkXeq.cc:1104
XrdProtocol * getProtocol()
Definition: XrdLinkXeq.hh:82
bool setTLS(bool enable, XrdTlsContext *ctx=0)
Definition: XrdLinkXeq.cc:972
int getIOStats(long long &inbytes, long long &outbytes, int &numstall, int &numtardy)
Definition: XrdLinkXeq.hh:68
static int LinkTimeOuts
Definition: XrdLinkXeq.hh:170
bool RegisterCloseRequestCb(XrdProtocol *pp, bool(*cb)(void *), void *cbarg)
Definition: XrdLinkXeq.cc:1469
void SetLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdNetAddr.cc:579
Socket wrapper for TLS I/O.
Definition: XrdTlsSocket.hh:40