Logo ROOT   6.08/07
Reference Guide
XrdClientSock.hh
Go to the documentation of this file.
1 #ifndef XRC_SOCK_H
2 #define XRC_SOCK_H
3 /******************************************************************************/
4 /* */
5 /* X r d C l i e n t S o c k . h h */
6 /* */
7 /* Author: Fabrizio Furano (INFN Padova, 2004) */
8 /* Adapted from TXNetFile (root.cern.ch) originally done by */
9 /* Alvise Dorigo, Fabrizio Furano */
10 /* INFN Padova, 2003 */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 //////////////////////////////////////////////////////////////////////////
34 // //
35 // Client Socket with timeout features //
36 // //
37 // June 06 - Fabrizio Furano //
38 // The function prototypes allow specializations for multistream xfer //
39 // purposes. In this class only monostream xfers are allowed. //
40 // //
41 //////////////////////////////////////////////////////////////////////////
42 
44 
48 };
49 
51 public:
52  typedef int Sockid;
53  typedef int Sockdescr;
54 
55  friend class XrdClientPhyConnection;
56 
57 private:
58 
59  int fSocket;
60 
61 protected:
62 
63 
66 
67  bool fConnected;
70 
71  // Tells if we have to reinit the table of the fd selectors
72  // after adding or removing one of them
73  bool fReinit_fd;
74 
75  virtual int SaveSocket() { int fd = fSocket; fSocket = -1;
76  fConnected = 0; fRDInterrupt = 0; fWRInterrupt = 0; return fd; }
77 
78  void SetInterrupt(int which = 0) { if (which == 0 || which == 1) fRDInterrupt = 1;
79  if (which == 0 || which == 2) fWRInterrupt = 1; }
80 
81  // returns the socket descriptor or -1
82  int TryConnect_low(bool isUnix = 0, int altport = 0, int windowsz = 0);
83 
84  // Send the buffer to the specified socket
85  virtual int SendRaw_sock(const void* buffer, int length, Sockdescr sock);
86 public:
87 
88  //--------------------------------------------------------------------------
89  //! Construct a socket helper
90  //!
91  //! @param host Remote location to connect to
92  //! @param windowSize TCP window size: 0 for OS defaults or the ENV setting
93  //! @param fd A descriptor pointing to an already connected socket,
94  //! -1 if not available
95  //--------------------------------------------------------------------------
96  XrdClientSock(XrdClientUrlInfo host, int windowsize = 0, int fd = -1 );
97  virtual ~XrdClientSock();
98 
99  virtual void BanSockDescr(Sockdescr, Sockid) {}
100  virtual void UnBanSockDescr(Sockdescr) { }
101 
102  // Makes a pending recvraw to rebuild the list of interesting selectors
103  void ReinitFDTable() { fReinit_fd = true; }
104 
105  // Gets length bytes from the specified substreamid
106  // If substreamid = 0 then use the main stream
107  // If substreamid = -1 then
108  // use any stream which has something pending
109  // and return its id in usedsubstreamid
110  // Note that in this base class only the multistream intf is provided
111  // but the implementation is monostream
112  virtual int RecvRaw(void* buffer, int length, Sockid substreamid = -1,
113  Sockid *usedsubstreamid = 0);
114 
115  // Send the buffer to the specified substream
116  // if substreamid <= 0 then use the main one
117  virtual int SendRaw(const void* buffer, int length, Sockid substreamid = 0);
118 
119  void SetRequestTimeout(int timeout = -1);
120 
121  // Performs a SOCKS4 handshake in a given stream
122  // Returns the handshake result
123  // If successful, we are connected through a socks4 proxy
124  virtual int Socks4Handshake(Sockid sockid);
125 
126  virtual void TryConnect(bool isUnix = 0);
127 
128  // Returns a temporary socket id or -1
129  // The temporary given sock id is to be used to send the kxr_bind_request
130  // If all this goes ok, then the caller must call EstablishParallelSock, otherwise the
131  // creation of parallel streams should be aborted (but the already created streams are OK)
132  virtual Sockdescr TryConnectParallelSock(int /*port*/, int /*windowsz*/, Sockid &/*tmpid*/) { return -1; }
133 
134  // Attach the pending (and hidden) sock
135  // to the given substreamid
136  // the given substreamid could be an integer suggested by the server
137  virtual int EstablishParallelSock(Sockid /*tmpsockid*/, Sockid /*newsockid*/) { return -1; }
138 
139  virtual int RemoveParallelSock(Sockid /* sockid */) { return -1; };
140 
141  // Suggests a sockid to be used for a req
142  virtual Sockid GetSockIdHint(int /* reqsperstream */ ) { return 0; }
143 
144  virtual void Disconnect();
145 
146  bool IsConnected() {return fConnected;}
147  virtual int GetSockIdCount() { return 1; }
148  virtual void PauseSelectOnSubstream(Sockid /* substreamid */) { }
149  virtual void RestartSelectOnSubstream(Sockid /*substreamid */) { }
150 };
151 #endif
virtual void RestartSelectOnSubstream(Sockid)
virtual void PauseSelectOnSubstream(Sockid)
virtual void UnBanSockDescr(Sockdescr)
virtual Sockid GetSockIdHint(int)
virtual int RemoveParallelSock(Sockid)
virtual int GetSockIdCount()
virtual int SaveSocket()
void ReinitFDTable()
virtual int EstablishParallelSock(Sockid, Sockid)
void SetInterrupt(int which=0)
XrdClientUrlInfo TcpHost
virtual Sockdescr TryConnectParallelSock(int, int, Sockid &)
XrdClientSockConnectParms fHost
virtual void BanSockDescr(Sockdescr, Sockid)