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"
40
41struct fdinfo {
42 fd_set fdset;
43 int maxfd;
44};
45
47
49
50private:
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
96protected:
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
115public:
116 XrdClientPSock(XrdClientUrlInfo host, int windowsize = 0);
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
Definition: XrdClientPSock.hh:46
virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid)
fdinfo globalfdinfo
Definition: XrdClientPSock.hh:56
virtual ~XrdClientPSock()
virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid)
XrdClientPSock(XrdClientUrlInfo host, int windowsize=0)
virtual int SaveSocket()
Definition: XrdClientPSock.hh:98
void BanSockDescr(Sockdescr s, Sockid newid)
Definition: XrdClientPSock.hh:119
virtual void RestartSelectOnSubstream(Sockid substreamid)
Sockdescr GetMainSock()
Definition: XrdClientPSock.hh:80
virtual void Disconnect()
virtual Sockid GetSockIdHint(int reqsperstream)
XrdClientVector< Sockid > fSocketIdRepo
Definition: XrdClientPSock.hh:62
void UnBanSockDescr(Sockdescr s)
Definition: XrdClientPSock.hh:120
Sockid GetSockId(Sockdescr sock)
Definition: XrdClientPSock.hh:88
virtual int SendRaw(const void *buffer, int length, Sockid substreamid=0)
XrdOucRash< Sockdescr, Sockid > fSocketIdPool
Definition: XrdClientPSock.hh:85
virtual int RecvRaw(void *buffer, int length, Sockid substreamid=-1, Sockid *usedsubstreamid=0)
XrdSysRecMutex fMutex
Definition: XrdClientPSock.hh:53
virtual int RemoveParallelSock(Sockid sockid)
Sockdescr GetSock(Sockid id)
Definition: XrdClientPSock.hh:72
virtual int GetSockIdCount()
Definition: XrdClientPSock.hh:147
virtual void TryConnect(bool isUnix=0)
virtual void PauseSelectOnSubstream(Sockid substreamid)
Sockid lastsidhint
Definition: XrdClientPSock.hh:58
XrdOucRash< Sockid, Sockdescr > fSocketPool
Definition: XrdClientPSock.hh:65
XrdOucRash< Sockdescr, Sockid > fSocketNYHandshakedIdPool
Definition: XrdClientPSock.hh:70
Definition: XrdClientPhyConnection.hh:69
Definition: XrdClientSock.hh:50
bool fConnected
Definition: XrdClientSock.hh:67
int Sockdescr
Definition: XrdClientSock.hh:53
bool fWRInterrupt
Definition: XrdClientSock.hh:69
bool fRDInterrupt
Definition: XrdClientSock.hh:68
int Sockid
Definition: XrdClientSock.hh:52
Definition: XrdClientUrlInfo.hh:50
int Del(K KeyVal)
V * Find(K KeyVal, time_t *KeyTime=0)
V * Rep(K KeyVal, V &KeyData, const int LifeTime=0, XrdOucRash_Options opt=Rash_default)
Definition: XrdOucRash.hh:150
int Num()
Definition: XrdOucRash.hh:142
Definition: XrdSysPthread.hh:261
Definition: XrdSysPthread.hh:240
Definition: XrdClientPSock.hh:41
int maxfd
Definition: XrdClientPSock.hh:43
fd_set fdset
Definition: XrdClientPSock.hh:42