xrootd
XrdClientPSock.hh
Go to the documentation of this file.
1 
2 // //
3 // XrdClientPSock //
4 // //
5 // Author: Fabrizio Furano (INFN Padova, 2006) //
6 // //
7 // Client Socket with multiple streams and timeout features //
8 // //
10 
11 // $Id$
12 
13 #ifndef XRC_PSOCK_H
14 #define XRC_PSOCK_H
15 
18 #include "XrdOuc/XrdOucRash.hh"
19 #include "XrdSys/XrdSysPthread.hh"
20 
21 
22 
23 struct fdinfo {
24  fd_set fdset;
25  int maxfd;
26 };
27 
28 
29 
31 
33 
34 private:
35 
36 
38 
39  // The set of interesting sock descriptors
41 
43 
44  // To have a pool of the ids in use,
45  // e.g. to select a random stream from the set of possible streams
47 
48  // To translate from socket id to socket descriptor
50 
51  // To keep track of the sockets which have to be
52  // temporarily ignored in the global fd
53  // because they have not yet been handshaked
55 
58 
59  Sockdescr *fd = fSocketPool.Find(id);
60  if (fd) return *fd;
61  else return -1;
62  }
63 
65  return GetSock(0);
66  }
67 
68  // To translate from socket descriptor to socket id
70 
71  // From a socket descriptor, we get its id
74 
75  Sockid *id = fSocketIdPool.Find(sock);
76  if (id) return *id;
77  else return -1;
78  }
79 
80 protected:
81 
82  virtual int SaveSocket() {
84 
85  // this overwrites the main stream
86  Sockdescr *fd = fSocketPool.Find(0);
87 
88  fSocketIdPool.Del(*fd);
89  fSocketPool.Del(0);
90 
91  fConnected = 0;
92  fRDInterrupt = 0;
93  fWRInterrupt = 0;
94 
95  if (fd) return *fd;
96  else return 0;
97  }
98 
99 public:
100  XrdClientPSock(XrdClientUrlInfo host, int windowsize = 0);
101  virtual ~XrdClientPSock();
102 
105 
106  // Gets length bytes from the parsockid socket
107  // If substreamid = -1 then
108  // gets length bytes from any par socket, and returns the usedsubstreamid
109  // where it got the bytes from
110  virtual int RecvRaw(void* buffer, int length, Sockid substreamid = -1,
111  Sockid *usedsubstreamid = 0);
112 
113  // Send the buffer to the specified substream
114  // if substreamid == 0 then use the main socket
115  virtual int SendRaw(const void* buffer, int length, Sockid substreamid = 0);
116 
117  virtual void TryConnect(bool isUnix = 0);
118 
119  virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid);
120 
121  virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid);
122 
123  virtual void Disconnect();
124 
125  virtual int RemoveParallelSock(Sockid sockid);
126 
127  // Suggests a sockid to be used for a req
128  virtual Sockid GetSockIdHint(int reqsperstream);
129 
130  // And this is the total stream count
131  virtual int GetSockIdCount() {
133 
134  return fSocketPool.Num();
135  }
136 
137  virtual void PauseSelectOnSubstream(Sockid substreamid);
138  virtual void RestartSelectOnSubstream(Sockid substreamid);
139 
140 };
141 
142 #endif