00001 #ifndef XRC_PSOCK_H
00002 #define XRC_PSOCK_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032
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
00056 fdinfo globalfdinfo;
00057
00058 Sockid lastsidhint;
00059
00060
00061
00062 XrdClientVector<Sockid> fSocketIdRepo;
00063
00064
00065 XrdOucRash<Sockid, Sockdescr> fSocketPool;
00066
00067
00068
00069
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
00085 XrdOucRash<Sockdescr, Sockid> fSocketIdPool;
00086
00087
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
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
00123
00124
00125
00126 virtual int RecvRaw(void* buffer, int length, Sockid substreamid = -1,
00127 Sockid *usedsubstreamid = 0);
00128
00129
00130
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
00144 virtual Sockid GetSockIdHint(int reqsperstream);
00145
00146
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