xrootd
XrdClientPSock.hh
Go to the documentation of this file.
1 #ifndef XRC_PSOCK_H
2 #define XRC_PSOCK_H
3 /******************************************************************************/
4 /* */
5 /* X r d C l i e n t P S o c k . h h */
6 /* */
7 /* Author: Fabrizio Furano (INFN Padova, 2006) */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
31 // //
32 // Client Socket with multiple streams and timeout features //
33 // //
35 
38 #include "XrdOuc/XrdOucRash.hh"
39 #include "XrdSys/XrdSysPthread.hh"
40 
41 struct fdinfo {
42  fd_set fdset;
43  int maxfd;
44 };
45 
47 
49 
50 private:
51 
52 
54 
55  // The set of interesting sock descriptors
57 
59 
60  // To have a pool of the ids in use,
61  // e.g. to select a random stream from the set of possible streams
63 
64  // To translate from socket id to socket descriptor
66 
67  // To keep track of the sockets which have to be
68  // temporarily ignored in the global fd
69  // because they have not yet been handshaked
71 
74 
75  Sockdescr *fd = fSocketPool.Find(id);
76  if (fd) return *fd;
77  else return -1;
78  }
79 
81  return GetSock(0);
82  }
83 
84  // To translate from socket descriptor to socket id
86 
87  // From a socket descriptor, we get its id
90 
91  Sockid *id = fSocketIdPool.Find(sock);
92  if (id) return *id;
93  else return -1;
94  }
95 
96 protected:
97 
98  virtual int SaveSocket() {
100 
101  // this overwrites the main stream
102  Sockdescr *fd = fSocketPool.Find(0);
103 
104  fSocketIdPool.Del(*fd);
105  fSocketPool.Del(0);
106 
107  fConnected = 0;
108  fRDInterrupt = 0;
109  fWRInterrupt = 0;
110 
111  if (fd) return *fd;
112  else return 0;
113  }
114 
115 public:
116  XrdClientPSock(XrdClientUrlInfo host, int windowsize = 0);
117  virtual ~XrdClientPSock();
118 
121 
122  // Gets length bytes from the parsockid socket
123  // If substreamid = -1 then
124  // gets length bytes from any par socket, and returns the usedsubstreamid
125  // where it got the bytes from
126  virtual int RecvRaw(void* buffer, int length, Sockid substreamid = -1,
127  Sockid *usedsubstreamid = 0);
128 
129  // Send the buffer to the specified substream
130  // if substreamid == 0 then use the main socket
131  virtual int SendRaw(const void* buffer, int length, Sockid substreamid = 0);
132 
133  virtual void TryConnect(bool isUnix = 0);
134 
135  virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid);
136 
137  virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid);
138 
139  virtual void Disconnect();
140 
141  virtual int RemoveParallelSock(Sockid sockid);
142 
143  // Suggests a sockid to be used for a req
144  virtual Sockid GetSockIdHint(int reqsperstream);
145 
146  // And this is the total stream count
147  virtual int GetSockIdCount() {
149 
150  return fSocketPool.Num();
151  }
152 
153  virtual void PauseSelectOnSubstream(Sockid substreamid);
154  virtual void RestartSelectOnSubstream(Sockid substreamid);
155 
156 };
157 #endif
XrdClientPSock::GetSock
Sockdescr GetSock(Sockid id)
Definition: XrdClientPSock.hh:72
XrdOucRash.hh
XrdClientSock
Definition: XrdClientSock.hh:50
XrdClientPSock::BanSockDescr
void BanSockDescr(Sockdescr s, Sockid newid)
Definition: XrdClientPSock.hh:119
XrdClientSock::Sockdescr
int Sockdescr
Definition: XrdClientSock.hh:53
XrdClientSock::fConnected
bool fConnected
Definition: XrdClientSock.hh:67
XrdSysPthread.hh
XrdClientPSock::fSocketIdPool
XrdOucRash< Sockdescr, Sockid > fSocketIdPool
Definition: XrdClientPSock.hh:85
XrdClientPSock::globalfdinfo
fdinfo globalfdinfo
Definition: XrdClientPSock.hh:56
XrdClientPSock::fSocketIdRepo
XrdClientVector< Sockid > fSocketIdRepo
Definition: XrdClientPSock.hh:62
XrdClientPSock::EstablishParallelSock
virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid)
XrdOucRash::Del
int Del(K KeyVal)
XrdClientPSock::TryConnectParallelSock
virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid)
XrdClientPSock::fMutex
XrdSysRecMutex fMutex
Definition: XrdClientPSock.hh:53
XrdOucRash::Num
int Num()
Definition: XrdOucRash.hh:142
XrdClientPSock::SendRaw
virtual int SendRaw(const void *buffer, int length, Sockid substreamid=0)
XrdClientPSock::SaveSocket
virtual int SaveSocket()
Definition: XrdClientPSock.hh:98
XrdClientSock::fWRInterrupt
bool fWRInterrupt
Definition: XrdClientSock.hh:69
XrdClientPSock::GetMainSock
Sockdescr GetMainSock()
Definition: XrdClientPSock.hh:80
XrdClientPSock::fSocketNYHandshakedIdPool
XrdOucRash< Sockdescr, Sockid > fSocketNYHandshakedIdPool
Definition: XrdClientPSock.hh:70
XrdClientPSock::GetSockId
Sockid GetSockId(Sockdescr sock)
Definition: XrdClientPSock.hh:88
XrdClientPSock::RemoveParallelSock
virtual int RemoveParallelSock(Sockid sockid)
fdinfo::fdset
fd_set fdset
Definition: XrdClientPSock.hh:42
XrdClientPSock::GetSockIdCount
virtual int GetSockIdCount()
Definition: XrdClientPSock.hh:147
XrdClientPSock::Disconnect
virtual void Disconnect()
XrdOucRash< Sockid, Sockdescr >
XrdClientPSock::TryConnect
virtual void TryConnect(bool isUnix=0)
XrdOucRash::Find
V * Find(K KeyVal, time_t *KeyTime=0)
XrdClientPSock::PauseSelectOnSubstream
virtual void PauseSelectOnSubstream(Sockid substreamid)
XrdClientSock::fRDInterrupt
bool fRDInterrupt
Definition: XrdClientSock.hh:68
XrdClientVector< Sockid >
XrdSysRecMutex
Definition: XrdSysPthread.hh:240
XrdOucRash::Rep
V * Rep(K KeyVal, V &KeyData, const int LifeTime=0, XrdOucRash_Options opt=Rash_default)
Definition: XrdOucRash.hh:150
XrdClientPSock::RestartSelectOnSubstream
virtual void RestartSelectOnSubstream(Sockid substreamid)
XrdClientPSock::UnBanSockDescr
void UnBanSockDescr(Sockdescr s)
Definition: XrdClientPSock.hh:120
XrdClientPSock::lastsidhint
Sockid lastsidhint
Definition: XrdClientPSock.hh:58
XrdClientSock.hh
XrdClientUrlInfo
Definition: XrdClientUrlInfo.hh:50
XrdClientPSock
Definition: XrdClientPSock.hh:46
fdinfo
Definition: XrdClientPSock.hh:41
XrdClientVector.hh
XrdSysMutexHelper
Definition: XrdSysPthread.hh:261
XrdClientPhyConnection
Definition: XrdClientPhyConnection.hh:69
XrdClientPSock::XrdClientPSock
XrdClientPSock(XrdClientUrlInfo host, int windowsize=0)
XrdClientPSock::GetSockIdHint
virtual Sockid GetSockIdHint(int reqsperstream)
XrdClientPSock::RecvRaw
virtual int RecvRaw(void *buffer, int length, Sockid substreamid=-1, Sockid *usedsubstreamid=0)
XrdClientPSock::fSocketPool
XrdOucRash< Sockid, Sockdescr > fSocketPool
Definition: XrdClientPSock.hh:65
XrdClientSock::Sockid
int Sockid
Definition: XrdClientSock.hh:52
fdinfo::maxfd
int maxfd
Definition: XrdClientPSock.hh:43
XrdClientPSock::~XrdClientPSock
virtual ~XrdClientPSock()