xrootd
XrdClientSock.hh
Go to the documentation of this file.
00001 #ifndef XRC_SOCK_H
00002 #define XRC_SOCK_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                    X r d C l i e n t S o c k . h h                         */
00006 /*                                                                            */
00007 /* Author: Fabrizio Furano (INFN Padova, 2004)                                */
00008 /* Adapted from TXNetFile (root.cern.ch) originally done by                   */
00009 /*  Alvise Dorigo, Fabrizio Furano                                            */
00010 /*          INFN Padova, 2003                                                 */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00034 //                                                                      //
00035 // Client Socket with timeout features                                  //
00036 //                                                                      //
00037 // June 06 - Fabrizio Furano                                            //
00038 // The function prototypes allow specializations for multistream xfer   //
00039 //  purposes. In this class only monostream xfers are allowed.          //
00040 //                                                                      //
00042 
00043 #include <XrdClient/XrdClientUrlInfo.hh>
00044 
00045 struct XrdClientSockConnectParms {
00046     XrdClientUrlInfo TcpHost;
00047     int TcpWindowSize;
00048 };
00049 
00050 class XrdClientSock {
00051 public:
00052     typedef int       Sockid;
00053     typedef int       Sockdescr;
00054 
00055     friend class XrdClientPhyConnection;
00056 
00057 private:
00058 
00059     int fSocket;
00060 
00061 protected:
00062 
00063 
00064     int                       fRequestTimeout;
00065     XrdClientSockConnectParms fHost;
00066 
00067     bool                      fConnected;
00068     bool                      fRDInterrupt;
00069     bool                      fWRInterrupt;
00070 
00071     // Tells if we have to reinit the table of the fd selectors
00072     // after adding or removing one of them
00073     bool                      fReinit_fd;
00074 
00075     virtual int    SaveSocket() { int fd = fSocket; fSocket = -1;
00076         fConnected = 0; fRDInterrupt = 0; fWRInterrupt = 0; return fd; }
00077 
00078     void   SetInterrupt(int which = 0) { if (which == 0 || which == 1) fRDInterrupt = 1;
00079                                          if (which == 0 || which == 2) fWRInterrupt = 1; }
00080 
00081     // returns the socket descriptor or -1
00082     int   TryConnect_low(bool isUnix = 0, int altport = 0, int windowsz = 0);
00083 
00084     // Send the buffer to the specified socket
00085     virtual int    SendRaw_sock(const void* buffer, int length, Sockdescr sock);
00086 public:
00087 
00088     //--------------------------------------------------------------------------
00095     //--------------------------------------------------------------------------
00096     XrdClientSock(XrdClientUrlInfo host, int windowsize = 0, int fd = -1 );
00097     virtual ~XrdClientSock();
00098 
00099     virtual void BanSockDescr(Sockdescr, Sockid) {}
00100     virtual void UnBanSockDescr(Sockdescr) { }
00101 
00102     // Makes a pending recvraw to rebuild the list of interesting selectors
00103     void           ReinitFDTable() { fReinit_fd = true; }
00104 
00105     // Gets length bytes from the specified substreamid
00106     // If substreamid = 0 then use the main stream
00107     // If substreamid = -1 then
00108     //  use any stream which has something pending
00109     //  and return its id in usedsubstreamid
00110     // Note that in this base class only the multistream intf is provided
00111     //  but the implementation is monostream
00112     virtual int    RecvRaw(void* buffer, int length, Sockid substreamid = -1,
00113                            Sockid *usedsubstreamid = 0);
00114 
00115     // Send the buffer to the specified substream
00116     // if substreamid <= 0 then use the main one
00117     virtual int    SendRaw(const void* buffer, int length, Sockid substreamid = 0);
00118 
00119     void   SetRequestTimeout(int timeout = -1);
00120 
00121     // Performs a SOCKS4 handshake in a given stream
00122     // Returns the handshake result
00123     // If successful, we are connected through a socks4 proxy
00124     virtual int Socks4Handshake(Sockid sockid);
00125 
00126     virtual void   TryConnect(bool isUnix = 0);
00127 
00128     // Returns a temporary socket id or -1
00129     // The temporary given sock id is to be used to send the kxr_bind_request
00130     // If all this goes ok, then the caller must call EstablishParallelSock, otherwise the
00131     //  creation of parallel streams should be aborted (but the already created streams are OK)
00132     virtual Sockdescr TryConnectParallelSock(int /*port*/, int /*windowsz*/, Sockid &/*tmpid*/) { return -1; }
00133 
00134     // Attach the pending (and hidden) sock
00135     //  to the given substreamid
00136     // the given substreamid could be an integer suggested by the server
00137     virtual int EstablishParallelSock(Sockid /*tmpsockid*/, Sockid /*newsockid*/) { return -1; }
00138 
00139     virtual int RemoveParallelSock(Sockid /* sockid */) { return -1; };
00140 
00141     // Suggests a sockid to be used for a req
00142     virtual Sockid GetSockIdHint(int /* reqsperstream */ ) { return 0; }
00143 
00144     virtual void   Disconnect();
00145 
00146     bool   IsConnected() {return fConnected;}
00147     virtual int GetSockIdCount() { return 1; }
00148     virtual void PauseSelectOnSubstream(Sockid /* substreamid */) {  }
00149     virtual void RestartSelectOnSubstream(Sockid /*substreamid */) {  }
00150 };
00151 #endif