XrdClientPSock.hh

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //                                                                      //
00003 // XrdClientPSock                                                       //
00004 //                                                                      //
00005 // Author: Fabrizio Furano (INFN Padova, 2006)                          //
00006 //                                                                      //
00007 // Client Socket with multiple streams and timeout features             //
00008 //                                                                      //
00009 //////////////////////////////////////////////////////////////////////////
00010 
00011 //           $Id: XrdClientPSock.hh 24809 2008-07-14 11:59:17Z ganis $
00012 
00013 #ifndef XRC_PSOCK_H
00014 #define XRC_PSOCK_H
00015 
00016 #include "XrdClient/XrdClientSock.hh"
00017 #include "XrdClient/XrdClientVector.hh"
00018 #include "XrdOuc/XrdOucRash.hh"
00019 #include "XrdSys/XrdSysPthread.hh"
00020 
00021 
00022 
00023 struct fdinfo {
00024   fd_set fdset;
00025   int maxfd;
00026 };
00027 
00028 
00029 
00030 class XrdClientPSock: public XrdClientSock {
00031 
00032 friend class XrdClientPhyConnection;
00033 
00034 private:
00035 
00036 
00037     XrdSysRecMutex fMutex;
00038 
00039     // The set of interesting sock descriptors
00040     fdinfo globalfdinfo;
00041 
00042     Sockid lastsidhint;
00043 
00044     // To have a pool of the ids in use,
00045     // e.g. to select a random stream from the set of possible streams
00046     XrdClientVector<Sockid> fSocketIdRepo;
00047  
00048     // To translate from socket id to socket descriptor
00049     XrdOucRash<Sockid, Sockdescr> fSocketPool;
00050 
00051     // To keep track of the sockets which have to be 
00052     // temporarily ignored in the global fd
00053     // because they have not yet been handshaked
00054     XrdOucRash<Sockdescr, Sockid> fSocketNYHandshakedIdPool;
00055 
00056     Sockdescr GetSock(Sockid id) {
00057         XrdSysMutexHelper mtx(fMutex);
00058 
00059         Sockdescr *fd = fSocketPool.Find(id);
00060         if (fd) return *fd;
00061         else return -1;
00062     }
00063 
00064     Sockdescr GetMainSock() {
00065         return GetSock(0);
00066     }
00067 
00068     // To translate from socket descriptor to socket id
00069     XrdOucRash<Sockdescr, Sockid> fSocketIdPool;
00070 
00071     // From a socket descriptor, we get its id
00072     Sockid GetSockId(Sockdescr sock) {
00073         XrdSysMutexHelper mtx(fMutex);
00074 
00075         Sockid *id = fSocketIdPool.Find(sock);
00076         if (id) return *id;
00077         else return -1;
00078     }
00079 
00080 protected:
00081 
00082     virtual int    SaveSocket() {
00083         XrdSysMutexHelper mtx(fMutex);
00084 
00085         // this overwrites the main stream
00086         Sockdescr *fd = fSocketPool.Find(0);
00087 
00088         fSocketIdPool.Del(*fd);
00089         fSocketPool.Del(0);
00090 
00091         fConnected = 0;
00092         fRDInterrupt = 0;
00093         fWRInterrupt = 0;
00094 
00095         if (fd) return *fd;
00096         else return 0;
00097     }
00098 
00099 public:
00100     XrdClientPSock(XrdClientUrlInfo host, int windowsize = 0);
00101     virtual ~XrdClientPSock();
00102    
00103     void BanSockDescr(Sockdescr s, Sockid newid) { XrdSysMutexHelper mtx(fMutex); fSocketNYHandshakedIdPool.Rep(s, newid); }
00104     void UnBanSockDescr(Sockdescr s) { XrdSysMutexHelper mtx(fMutex); fSocketNYHandshakedIdPool.Del(s); }
00105 
00106     // Gets length bytes from the parsockid socket
00107     // If substreamid = -1 then
00108     //  gets length bytes from any par socket, and returns the usedsubstreamid
00109     //   where it got the bytes from
00110     virtual int    RecvRaw(void* buffer, int length, Sockid substreamid = -1,
00111                            Sockid *usedsubstreamid = 0);
00112 
00113     // Send the buffer to the specified substream
00114     // if substreamid == 0 then use the main socket
00115     virtual int    SendRaw(const void* buffer, int length, Sockid substreamid = 0);
00116 
00117     virtual void   TryConnect(bool isUnix = 0);
00118 
00119     virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid);
00120 
00121     virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid);
00122 
00123     virtual void   Disconnect();
00124 
00125     virtual int RemoveParallelSock(Sockid sockid);
00126 
00127     // Suggests a sockid to be used for a req
00128     virtual Sockid GetSockIdHint(int reqsperstream);
00129 
00130     // And this is the total stream count
00131     virtual int GetSockIdCount() { 
00132         XrdSysMutexHelper mtx(fMutex);
00133 
00134         return fSocketPool.Num();
00135     }
00136 
00137     virtual void PauseSelectOnSubstream(Sockid substreamid);
00138     virtual void RestartSelectOnSubstream(Sockid substreamid);
00139 
00140 };
00141 
00142 #endif

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