Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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 //                                                                      //
00017 
00018 //           $Id$
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     //--------------------------------------------------------------------------
00075     //--------------------------------------------------------------------------
00076     XrdClientSock(XrdClientUrlInfo host, int windowsize = 0, int fd = -1 );
00077     virtual ~XrdClientSock();
00078 
00079     virtual void BanSockDescr(Sockdescr, Sockid) {}
00080     virtual void UnBanSockDescr(Sockdescr) { }
00081 
00082     // Makes a pending recvraw to rebuild the list of interesting selectors
00083     void           ReinitFDTable() { fReinit_fd = true; }
00084 
00085     // Gets length bytes from the specified substreamid
00086     // If substreamid = 0 then use the main stream
00087     // If substreamid = -1 then
00088     //  use any stream which has something pending
00089     //  and return its id in usedsubstreamid
00090     // Note that in this base class only the multistream intf is provided
00091     //  but the implementation is monostream
00092     virtual int    RecvRaw(void* buffer, int length, Sockid substreamid = -1,
00093                            Sockid *usedsubstreamid = 0);
00094 
00095     // Send the buffer to the specified substream
00096     // if substreamid <= 0 then use the main one
00097     virtual int    SendRaw(const void* buffer, int length, Sockid substreamid = 0);
00098 
00099     void   SetRequestTimeout(int timeout = -1);
00100 
00101     // Performs a SOCKS4 handshake in a given stream
00102     // Returns the handshake result
00103     // If successful, we are connected through a socks4 proxy
00104     virtual int Socks4Handshake(Sockid sockid);
00105 
00106     virtual void   TryConnect(bool isUnix = 0);
00107 
00108     // Returns a temporary socket id or -1
00109     // The temporary given sock id is to be used to send the kxr_bind_request
00110     // If all this goes ok, then the caller must call EstablishParallelSock, otherwise the
00111     //  creation of parallel streams should be aborted (but the already created streams are OK)
00112     virtual Sockdescr TryConnectParallelSock(int /*port*/, int /*windowsz*/, Sockid &/*tmpid*/) { return -1; }
00113 
00114     // Attach the pending (and hidden) sock
00115     //  to the given substreamid
00116     // the given substreamid could be an integer suggested by the server
00117     virtual int EstablishParallelSock(Sockid /*tmpsockid*/, Sockid /*newsockid*/) { return -1; }
00118 
00119     virtual int RemoveParallelSock(Sockid /* sockid */) { return -1; };
00120 
00121     // Suggests a sockid to be used for a req
00122     virtual Sockid GetSockIdHint(int /* reqsperstream */ ) { return 0; }
00123 
00124     virtual void   Disconnect();
00125 
00126     bool   IsConnected() {return fConnected;}
00127     virtual int GetSockIdCount() { return 1; }
00128     virtual void PauseSelectOnSubstream(Sockid /* substreamid */) {  }
00129     virtual void RestartSelectOnSubstream(Sockid /*substreamid */) {  }
00130 };
00131 
00132 #endif

Generated on Sun Nov 6 13:39:22 2011 for xrootd by  doxygen 1.3.9.1