|
xrootd
|
00001 #ifndef XRC_PSOCK_H 00002 #define XRC_PSOCK_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C l i e n t P S o c k . h h */ 00006 /* */ 00007 /* Author: Fabrizio Furano (INFN Padova, 2006) */ 00008 /* */ 00009 /* This file is part of the XRootD software suite. */ 00010 /* */ 00011 /* XRootD is free software: you can redistribute it and/or modify it under */ 00012 /* the terms of the GNU Lesser General Public License as published by the */ 00013 /* Free Software Foundation, either version 3 of the License, or (at your */ 00014 /* option) any later version. */ 00015 /* */ 00016 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00017 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00018 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00019 /* License for more details. */ 00020 /* */ 00021 /* You should have received a copy of the GNU Lesser General Public License */ 00022 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00023 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00024 /* */ 00025 /* The copyright holder's institutional names and contributor's names may not */ 00026 /* be used to endorse or promote products derived from this software without */ 00027 /* specific prior written permission of the institution or contributor. */ 00028 /******************************************************************************/ 00029 00031 // // 00032 // Client Socket with multiple streams and timeout features // 00033 // // 00035 00036 #include "XrdClient/XrdClientSock.hh" 00037 #include "XrdClient/XrdClientVector.hh" 00038 #include "XrdOuc/XrdOucRash.hh" 00039 #include "XrdSys/XrdSysPthread.hh" 00040 00041 struct fdinfo { 00042 fd_set fdset; 00043 int maxfd; 00044 }; 00045 00046 class XrdClientPSock: public XrdClientSock { 00047 00048 friend class XrdClientPhyConnection; 00049 00050 private: 00051 00052 00053 XrdSysRecMutex fMutex; 00054 00055 // The set of interesting sock descriptors 00056 fdinfo globalfdinfo; 00057 00058 Sockid lastsidhint; 00059 00060 // To have a pool of the ids in use, 00061 // e.g. to select a random stream from the set of possible streams 00062 XrdClientVector<Sockid> fSocketIdRepo; 00063 00064 // To translate from socket id to socket descriptor 00065 XrdOucRash<Sockid, Sockdescr> fSocketPool; 00066 00067 // To keep track of the sockets which have to be 00068 // temporarily ignored in the global fd 00069 // because they have not yet been handshaked 00070 XrdOucRash<Sockdescr, Sockid> fSocketNYHandshakedIdPool; 00071 00072 Sockdescr GetSock(Sockid id) { 00073 XrdSysMutexHelper mtx(fMutex); 00074 00075 Sockdescr *fd = fSocketPool.Find(id); 00076 if (fd) return *fd; 00077 else return -1; 00078 } 00079 00080 Sockdescr GetMainSock() { 00081 return GetSock(0); 00082 } 00083 00084 // To translate from socket descriptor to socket id 00085 XrdOucRash<Sockdescr, Sockid> fSocketIdPool; 00086 00087 // From a socket descriptor, we get its id 00088 Sockid GetSockId(Sockdescr sock) { 00089 XrdSysMutexHelper mtx(fMutex); 00090 00091 Sockid *id = fSocketIdPool.Find(sock); 00092 if (id) return *id; 00093 else return -1; 00094 } 00095 00096 protected: 00097 00098 virtual int SaveSocket() { 00099 XrdSysMutexHelper mtx(fMutex); 00100 00101 // this overwrites the main stream 00102 Sockdescr *fd = fSocketPool.Find(0); 00103 00104 fSocketIdPool.Del(*fd); 00105 fSocketPool.Del(0); 00106 00107 fConnected = 0; 00108 fRDInterrupt = 0; 00109 fWRInterrupt = 0; 00110 00111 if (fd) return *fd; 00112 else return 0; 00113 } 00114 00115 public: 00116 XrdClientPSock(XrdClientUrlInfo host, int windowsize = 0); 00117 virtual ~XrdClientPSock(); 00118 00119 void BanSockDescr(Sockdescr s, Sockid newid) { XrdSysMutexHelper mtx(fMutex); fSocketNYHandshakedIdPool.Rep(s, newid); } 00120 void UnBanSockDescr(Sockdescr s) { XrdSysMutexHelper mtx(fMutex); fSocketNYHandshakedIdPool.Del(s); } 00121 00122 // Gets length bytes from the parsockid socket 00123 // If substreamid = -1 then 00124 // gets length bytes from any par socket, and returns the usedsubstreamid 00125 // where it got the bytes from 00126 virtual int RecvRaw(void* buffer, int length, Sockid substreamid = -1, 00127 Sockid *usedsubstreamid = 0); 00128 00129 // Send the buffer to the specified substream 00130 // if substreamid == 0 then use the main socket 00131 virtual int SendRaw(const void* buffer, int length, Sockid substreamid = 0); 00132 00133 virtual void TryConnect(bool isUnix = 0); 00134 00135 virtual Sockdescr TryConnectParallelSock(int port, int windowsz, Sockid &tmpid); 00136 00137 virtual int EstablishParallelSock(Sockid tmpsockid, Sockid newsockid); 00138 00139 virtual void Disconnect(); 00140 00141 virtual int RemoveParallelSock(Sockid sockid); 00142 00143 // Suggests a sockid to be used for a req 00144 virtual Sockid GetSockIdHint(int reqsperstream); 00145 00146 // And this is the total stream count 00147 virtual int GetSockIdCount() { 00148 XrdSysMutexHelper mtx(fMutex); 00149 00150 return fSocketPool.Num(); 00151 } 00152 00153 virtual void PauseSelectOnSubstream(Sockid substreamid); 00154 virtual void RestartSelectOnSubstream(Sockid substreamid); 00155 00156 }; 00157 #endif
1.7.6.1