XrdClientSock.hh

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //                                                                      //
00003 // XrdClientSock                                                        //
00004 //                                                                      //
00005 // Author: Fabrizio Furano (INFN Padova, 2004)                          //
00006 // Adapted from TXNetFile (root.cern.ch) originally done by             //
00007 //  Alvise Dorigo, Fabrizio Furano                                      //
00008 //          INFN Padova, 2003                                           //
00009 //                                                                      //
00010 // Client Socket with timeout features                                  //
00011 //                                                                      //
00012 // June 06 - Fabrizio Furano                                            //
00013 // The function prototypes allow specializations for multistream xfer   //
00014 //  purposes. In this class only monostream xfers are allowed.          //
00015 //                                                                      //
00016 //////////////////////////////////////////////////////////////////////////
00017 
00018 //           $Id: XrdClientSock.hh 24809 2008-07-14 11:59:17Z ganis $
00019 
00020 #ifndef XRC_SOCK_H
00021 #define XRC_SOCK_H
00022 
00023 #include <XrdClient/XrdClientUrlInfo.hh>
00024 
00025 struct XrdClientSockConnectParms {
00026     XrdClientUrlInfo TcpHost;
00027     int TcpWindowSize;
00028 };
00029 
00030 class XrdClientSock {
00031 public:
00032     typedef int       Sockid;
00033     typedef int       Sockdescr;
00034 
00035     friend class XrdClientPhyConnection;
00036 
00037 private:
00038 
00039     int fSocket;
00040 
00041 protected:
00042 
00043 
00044     int                       fRequestTimeout;
00045     XrdClientSockConnectParms fHost;
00046 
00047     bool                      fConnected;
00048     bool                      fRDInterrupt;
00049     bool                      fWRInterrupt;
00050 
00051     // Tells if we have to reinit the table of the fd selectors
00052     // after adding or removing one of them
00053     bool                      fReinit_fd;
00054 
00055     virtual int    SaveSocket() { int fd = fSocket; fSocket = -1;
00056         fConnected = 0; fRDInterrupt = 0; fWRInterrupt = 0; return fd; }
00057 
00058     void   SetInterrupt(int which = 0) { if (which == 0 || which == 1) fRDInterrupt = 1;
00059                                          if (which == 0 || which == 2) fWRInterrupt = 1; }
00060 
00061     // returns the socket descriptor or -1
00062     int   TryConnect_low(bool isUnix = 0, int altport = 0, int windowsz = 0);
00063 
00064     // Send the buffer to the specified socket
00065     virtual int    SendRaw_sock(const void* buffer, int length, Sockdescr sock);
00066 public:
00067 
00068     XrdClientSock(XrdClientUrlInfo host, int windowsize = 0);
00069     virtual ~XrdClientSock();
00070 
00071     virtual void BanSockDescr(Sockdescr, Sockid) {}
00072     virtual void UnBanSockDescr(Sockdescr) { }
00073 
00074     // Makes a pending recvraw to rebuild the list of interesting selectors
00075     void           ReinitFDTable() { fReinit_fd = true; }
00076 
00077     // Gets length bytes from the specified substreamid
00078     // If substreamid = 0 then use the main stream
00079     // If substreamid = -1 then
00080     //  use any stream which has something pending
00081     //  and return its id in usedsubstreamid
00082     // Note that in this base class only the multistream intf is provided
00083     //  but the implementation is monostream
00084     virtual int    RecvRaw(void* buffer, int length, Sockid substreamid = -1,
00085                            Sockid *usedsubstreamid = 0);
00086 
00087     // Send the buffer to the specified substream
00088     // if substreamid <= 0 then use the main one
00089     virtual int    SendRaw(const void* buffer, int length, Sockid substreamid = 0);
00090 
00091     void   SetRequestTimeout(int timeout = -1);
00092 
00093     // Performs a SOCKS4 handshake in a given stream
00094     // Returns the handshake result
00095     // If successful, we are connected through a socks4 proxy
00096     virtual int Socks4Handshake(Sockid sockid);
00097 
00098     virtual void   TryConnect(bool isUnix = 0);
00099 
00100     // Returns a temporary socket id or -1
00101     // The temporary given sock id is to be used to send the kxr_bind_request
00102     // If all this goes ok, then the caller must call EstablishParallelSock, otherwise the
00103     //  creation of parallel streams should be aborted (but the already created streams are OK)
00104     virtual Sockdescr TryConnectParallelSock(int /*port*/, int /*windowsz*/, Sockid &/*tmpid*/) { return -1; }
00105 
00106     // Attach the pending (and hidden) sock
00107     //  to the given substreamid
00108     // the given substreamid could be an integer suggested by the server
00109     virtual int EstablishParallelSock(Sockid /*tmpsockid*/, Sockid /*newsockid*/) { return -1; }
00110 
00111     virtual int RemoveParallelSock(Sockid /* sockid */) { return -1; };
00112 
00113     // Suggests a sockid to be used for a req
00114     virtual Sockid GetSockIdHint(int /* reqsperstream */ ) { return 0; }
00115 
00116     virtual void   Disconnect();
00117 
00118     bool   IsConnected() {return fConnected;}
00119     virtual int GetSockIdCount() { return 1; }
00120     virtual void PauseSelectOnSubstream(Sockid /* substreamid */) {  }
00121     virtual void RestartSelectOnSubstream(Sockid /*substreamid */) {  }
00122 };
00123 
00124 #endif

Generated on Tue Jul 5 14:46:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1