xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  XrdLinkXeq();
142  ~XrdLinkXeq() {} // Is never deleted!
143 
146 
147 protected:
148 
149 int RecvIOV(const struct iovec *iov, int iocnt);
150 void Reset();
151 int sendData(const char *Buff, int Blen);
152 int SendIOV(const struct iovec *iov, int iocnt, int bytes);
153 int SFError(int rc);
154 int TLS_Error(const char *act, XrdTls::RC rc);
155 bool TLS_Write(const char *Buff, int Blen);
156 
157 static const char *TraceID;
158 
159 // Statistical area (global and local)
160 //
161 static long long LinkBytesIn;
162 static long long LinkBytesOut;
163 static long long LinkConTime;
164 static long long LinkCountTot;
165 static int LinkCount;
166 static int LinkCountMax;
167 static int LinkTimeOuts;
168 static int LinkStalls;
169 static int LinkSfIntr;
170  long long BytesIn;
171  long long BytesInTot;
172  long long BytesOut;
173  long long BytesOutTot;
174  int stallCnt;
176  int tardyCnt;
178  int SfIntr;
180 
181 // Protocol section
182 //
183 XrdProtocol *Protocol; // -> Protocol tied to the link
184 XrdProtocol *ProtoAlt; // -> Alternate/stacked protocol
185 
186 // TLS section
187 //
189 
190 // Identification section
191 //
195 XrdSendQ *sendQ; // Protected by wrMutex && opMutex
196 int HNlen;
198 bool KeepFD;
199 char isIdle;
200 char Uname[24]; // Uname and Lname must be adjacent!
201 char Lname[256];
202 };
203 #endif
bool KeepFD
Definition: XrdLinkXeq.hh:198
static int LinkCountMax
Definition: XrdLinkXeq.hh:166
int TLS_Error(const char *act, XrdTls::RC rc)
bool setNB()
bool setTLS(bool enable, XrdTlsContext *ctx=0)
int TLS_RecvAll(char *Buff, int Blen, int timeout)
static int LinkTimeOuts
Definition: XrdLinkXeq.hh:167
XrdTlsSocket tlsIO
Definition: XrdLinkXeq.hh:188
int Peek(char *buff, int blen, int timeout=-1)
int stallCnt
Definition: XrdLinkXeq.hh:174
const char * Name() const
Definition: XrdLinkXeq.hh:85
void DoIt()
static int Stats(char *buff, int blen, bool do_sync=false)
char isIdle
Definition: XrdLinkXeq.hh:199
static const char * TraceID
Definition: XrdLinkXeq.hh:157
XrdSysMutex wrMutex
Definition: XrdLinkXeq.hh:194
Definition: XrdProtocol.hh:124
XrdNetAddr Addr
Definition: XrdLinkXeq.hh:192
int tardyCnt
Definition: XrdLinkXeq.hh:176
void syncStats(int *ctime=0)
Socket wrapper for TLS I/O.
Definition: XrdTlsSocket.hh:39
XrdSendQ * sendQ
Definition: XrdLinkXeq.hh:195
Definition: XrdPollInfo.hh:36
Definition: XrdNetAddr.hh:41
static long long LinkBytesIn
Definition: XrdLinkXeq.hh:161
int tardyCntTot
Definition: XrdLinkXeq.hh:177
int Recv(char *buff, int blen)
static XrdSysMutex statsMutex
Definition: XrdLinkXeq.hh:179
long long BytesOut
Definition: XrdLinkXeq.hh:172
static long long LinkBytesOut
Definition: XrdLinkXeq.hh:162
int SFError(int rc)
~XrdLinkXeq()
Definition: XrdLinkXeq.hh:142
Definition: XrdSysPthread.hh:164
int getIOStats(long long &inbytes, long long &outbytes, int &numstall, int &numtardy)
Definition: XrdLinkXeq.hh:68
int sendData(const char *Buff, int Blen)
Definition: XrdOucIOVec.hh:65
int HNlen
Definition: XrdLinkXeq.hh:196
static int LinkStalls
Definition: XrdLinkXeq.hh:168
RC
Definition: XrdTls.hh:40
long long BytesInTot
Definition: XrdLinkXeq.hh:171
static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0)
XrdNetAddrInfo * AddrInfo()
Definition: XrdLinkXeq.hh:57
char Lname[256]
Definition: XrdLinkXeq.hh:201
XrdPollInfo PollInfo
Definition: XrdLinkXeq.hh:145
Definition: XrdNetAddrInfo.hh:194
Definition: XrdSendQ.hh:42
XrdProtocol * setProtocol(XrdProtocol *pp, bool push)
int TLS_Send(const char *Buff, int Blen)
Definition: XrdLinkXeq.hh:52
bool TLS_Write(const char *Buff, int Blen)
Definition: XrdNetAddrInfo.hh:53
void Shutdown(bool getLock)
int Send(const char *buff, int blen)
XrdLinkInfo LinkInfo
Definition: XrdLinkXeq.hh:144
int RecvIOV(const struct iovec *iov, int iocnt)
XrdProtocol * ProtoAlt
Definition: XrdLinkXeq.hh:184
long long BytesIn
Definition: XrdLinkXeq.hh:170
const XrdNetAddr * NetAddr() const
Definition: XrdLinkXeq.hh:88
Definition: XrdTlsContext.hh:36
XrdProtocol * Protocol
Definition: XrdLinkXeq.hh:183
static int LinkCount
Definition: XrdLinkXeq.hh:165
char Uname[24]
Definition: XrdLinkXeq.hh:200
int TLS_Recv(char *Buff, int Blen)
void SetLocation(XrdNetAddrInfo::LocInfo &loc)
static long long LinkConTime
Definition: XrdLinkXeq.hh:163
const char * verTLS()
int TLS_Peek(char *Buff, int Blen, int timeout)
XrdTlsPeerCerts * getPeerCerts()
bool LockReads
Definition: XrdLinkXeq.hh:197
int SfIntr
Definition: XrdLinkXeq.hh:178
int Client(char *buff, int blen)
XrdSysMutex rdMutex
Definition: XrdLinkXeq.hh:193
Definition: XrdLinkMatch.hh:35
static int LinkSfIntr
Definition: XrdLinkXeq.hh:169
int stallCntTot
Definition: XrdLinkXeq.hh:175
XrdProtocol * getProtocol()
Definition: XrdLinkXeq.hh:82
int InUse
Definition: XrdLinkInfo.hh:47
void Reset()
void setID(const char *userid, int procid)
int RecvAll(char *buff, int blen, int timeout=-1)
bool Register(const char *hName)
int SendIOV(const struct iovec *iov, int iocnt, int bytes)
static long long LinkCountTot
Definition: XrdLinkXeq.hh:164
void setProtName(const char *name)
Definition: XrdLinkInfo.hh:38
int Backlog()
Definition: XrdTlsPeerCerts.hh:34
void setLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdLinkXeq.hh:107
int Close(bool defer=false)
long long BytesOutTot
Definition: XrdLinkXeq.hh:173