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