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  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
static const char * TraceID
Definition: XrdLinkXeq.hh:157
int TLS_Send(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1314
long long BytesOut
Definition: XrdLinkXeq.hh:172
int TLS_Error(const char *act, XrdTls::RC rc)
Definition: XrdLinkXeq.cc:1147
int TLS_Peek(char *Buff, int Blen, int timeout)
Definition: XrdLinkXeq.cc:1161
int stallCntTot
Definition: XrdLinkXeq.hh:175
int Client(char *buff, int blen)
Definition: XrdLinkXeq.cc:152
char Uname[24]
Definition: XrdLinkXeq.hh:200
XrdTlsPeerCerts * getPeerCerts()
Definition: XrdLinkXeq.cc:321
static int LinkCountMax
Definition: XrdLinkXeq.hh:166
XrdLinkInfo LinkInfo
Definition: XrdLinkXeq.hh:144
const char * Name() const
Definition: XrdLinkXeq.hh:85
XrdProtocol * ProtoAlt
Definition: XrdLinkXeq.hh:184
int Close(bool defer=false)
Definition: XrdLinkXeq.cc:172
XrdNetAddr Addr
Definition: XrdLinkXeq.hh:192
int TLS_Recv(char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1193
int sendData(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:810
long long BytesInTot
Definition: XrdLinkXeq.hh:171
bool TLS_Write(const char *Buff, int Blen)
Definition: XrdLinkXeq.cc:1421
int SendIOV(const struct iovec *iov, int iocnt, int bytes)
Definition: XrdLinkXeq.cc:833
XrdProtocol * setProtocol(XrdProtocol *pp, bool push)
Definition: XrdLinkXeq.cc:927
static long long LinkCountTot
Definition: XrdLinkXeq.hh:164
long long BytesOutTot
Definition: XrdLinkXeq.hh:173
void Shutdown(bool getLock)
Definition: XrdLinkXeq.cc:1022
int Peek(char *buff, int blen, int timeout=-1)
Definition: XrdLinkXeq.cc:330
static int LinkCount
Definition: XrdLinkXeq.hh:165
void Reset()
Definition: XrdLinkXeq.cc:113
int Backlog()
Definition: XrdLinkXeq.cc:139
static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0)
XrdSysMutex wrMutex
Definition: XrdLinkXeq.hh:194
static int Stats(char *buff, int blen, bool do_sync=false)
Definition: XrdLinkXeq.cc:1054
XrdSendQ * sendQ
Definition: XrdLinkXeq.hh:195
XrdPollInfo PollInfo
Definition: XrdLinkXeq.hh:145
void setID(const char *userid, int procid)
Definition: XrdLinkXeq.cc:874
bool LockReads
Definition: XrdLinkXeq.hh:197
XrdNetAddrInfo * AddrInfo()
Definition: XrdLinkXeq.hh:57
int Recv(char *buff, int blen)
Definition: XrdLinkXeq.cc:373
static long long LinkBytesIn
Definition: XrdLinkXeq.hh:161
int TLS_RecvAll(char *Buff, int Blen, int timeout)
Definition: XrdLinkXeq.cc:1292
int SFError(int rc)
Definition: XrdLinkXeq.cc:1012
long long BytesIn
Definition: XrdLinkXeq.hh:170
int tardyCntTot
Definition: XrdLinkXeq.hh:177
const XrdNetAddr * NetAddr() const
Definition: XrdLinkXeq.hh:88
int Send(const char *buff, int blen)
Definition: XrdLinkXeq.cc:588
XrdSysMutex rdMutex
Definition: XrdLinkXeq.hh:193
const char * verTLS()
Definition: XrdLinkXeq.cc:1446
bool setNB()
Definition: XrdLinkXeq.cc:898
int RecvIOV(const struct iovec *iov, int iocnt)
Definition: XrdLinkXeq.cc:551
char Lname[256]
Definition: XrdLinkXeq.hh:201
static long long LinkConTime
Definition: XrdLinkXeq.hh:163
static int LinkSfIntr
Definition: XrdLinkXeq.hh:169
XrdTlsSocket tlsIO
Definition: XrdLinkXeq.hh:188
void DoIt()
Definition: XrdLinkXeq.cc:292
void setLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdLinkXeq.hh:107
int RecvAll(char *buff, int blen, int timeout=-1)
Definition: XrdLinkXeq.cc:509
XrdProtocol * Protocol
Definition: XrdLinkXeq.hh:183
bool Register(const char *hName)
Definition: XrdLinkXeq.cc:573
static XrdSysMutex statsMutex
Definition: XrdLinkXeq.hh:179
void setProtName(const char *name)
Definition: XrdLinkXeq.cc:944
static int LinkStalls
Definition: XrdLinkXeq.hh:168
static long long LinkBytesOut
Definition: XrdLinkXeq.hh:162
void syncStats(int *ctime=0)
Definition: XrdLinkXeq.cc:1090
XrdProtocol * getProtocol()
Definition: XrdLinkXeq.hh:82
bool setTLS(bool enable, XrdTlsContext *ctx=0)
Definition: XrdLinkXeq.cc:958
int getIOStats(long long &inbytes, long long &outbytes, int &numstall, int &numtardy)
Definition: XrdLinkXeq.hh:68
static int LinkTimeOuts
Definition: XrdLinkXeq.hh:167
void SetLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdNetAddr.cc:579
Socket wrapper for TLS I/O.
Definition: XrdTlsSocket.hh:40