Changeset 10031 for trunk/Cosy/tcpip
- Timestamp:
- 10/21/10 16:16:52 (14 years ago)
- Location:
- trunk/Cosy/tcpip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosy/tcpip/MTcpIpIO.cc
r9582 r10031 67 67 } 68 68 69 MTcpIpIO::~MTcpIpIO()70 {71 }72 73 69 TString MTcpIpO::GetSocketAddress(const TSocket &s) 74 70 { … … 192 188 193 189 MThread::Sleep(wait); // Wait a ms 194 if (wait<30000000) // 30s 190 if (wait<3000000) // 3s 191 wait *= 2; 192 } 193 194 return 1; 195 } 196 197 Int_t MTcpIpOI::Thread() 198 { 199 fConnectionEstablished = kFALSE; 200 201 const TInetAddress &a = fTxSocket->GetInetAddress(); 202 if (!a.IsValid()) 203 { 204 gLog << err << "- MTcpIpOI::Thread - ERROR: Send socket address invalid." << endl; 205 return 0; 206 } 207 208 gLog << inf << "- MTcpIpOI::Thread created connecting to " << a.GetHostAddress() << ":" << fPortTx << endl; 209 210 Int_t wait = 1000; /// Wait a ms 211 212 MTimeout timeout(fTimeout); 213 214 while (!IsThreadCanceled()) 215 { 216 if (fTxSocket->IsValid()) 217 { 218 fConnectionEstablished = kTRUE; 219 fTimeout = 1000; 220 221 // Get connection on port fPortRx and redirected 222 // Check for pending data (every ms) 223 switch (fTxSocket->Select(TSocket::kRead, 1)) 224 { 225 case kTRUE: // Data pending... go on reading 226 if (!ReadSocket(*fTxSocket)) 227 { 228 gLog << warn << MTime(-1) << " WARNING - Connection lost to " << MTcpIpO::GetSocketAddress(*fTxSocket) << endl; 229 fTxSocket->Close(); 230 continue; 231 } 232 timeout.Start(fTimeout); 233 continue; 234 235 case kFALSE: // Time out, no data yet, go on waiting 236 if (timeout.HasTimedOut()) 237 { 238 gLog << warn << MTime(-1) << " WARNING - Connection to " << MTcpIpO::GetSocketAddress(*fTxSocket) << " timed out after " << fTimeout << "ms." << endl; 239 fTxSocket->Close(); 240 continue; 241 } 242 continue; 243 244 default: // Error occurance 245 gLog << err << "TSocket::Select returned an error: " << strerror(errno) << endl; 246 fTxSocket->Close(); 247 continue; 248 } 249 } 250 251 fConnectionEstablished = kFALSE; 252 253 #ifdef DEBUG 254 cout << "- Reopen send socket to " << a.GetHostAddress() << ":" << fPortTx << endl; 255 #endif 256 257 fMutex.Lock(); 258 259 delete fTxSocket; 260 261 fTxSocket = new TSocket(a.GetHostAddress(), fPortTx); 262 fTxSocket->SetOption(kNoBlock, 1); 263 264 fMutex.UnLock(); 265 266 timeout.Start(fTimeout); 267 268 if (fTxSocket->IsValid()) 269 continue; 270 271 MThread::Sleep(wait); // Wait a ms 272 if (wait<3000000) // 3s 195 273 wait *= 2; 196 274 } -
trunk/Cosy/tcpip/MTcpIpIO.h
r9582 r10031 46 46 class MTcpIpO : public MThread 47 47 { 48 pr ivate:48 protected: 49 49 TSocket *fTxSocket; 50 50 TMutex fMutex; … … 73 73 public: 74 74 MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000); 75 ~MTcpIpIO();76 75 77 76 virtual bool InterpreteStr(TString str); 78 77 }; 79 78 79 class MTcpIpOI : public MTcpIpO 80 { 81 private: 82 Int_t Thread(); 83 virtual Bool_t ReadSocket(TSocket &rx) = 0; 84 85 Bool_t fConnectionEstablished; 86 Int_t fTimeout; // [ms] Timeout to listen for data to be received 87 public: 88 MTcpIpOI(const char *addr, Int_t tx, UInt_t timeout=5000) : MTcpIpO(addr, tx), fConnectionEstablished(kFALSE), fTimeout(timeout) { } 89 90 Bool_t IsConnectionEstablished() const { return fConnectionEstablished; } 91 }; 92 80 93 #endif
Note:
See TracChangeset
for help on using the changeset viewer.