Changeset 12598 for trunk/Cosy
- Timestamp:
- 11/21/11 13:08:27 (13 years ago)
- Location:
- trunk/Cosy/tcpip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosy/tcpip/MTcpIpIO.cc
r10031 r12598 62 62 } 63 63 64 MTcpIp IO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout), MTcpIpO(addr, tx)64 MTcpIpCC::MTcpIpCC(Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout) 65 65 { 66 66 MTcpIpI::RunThread(); 67 } 68 69 MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpCC(rx, timeout), MTcpIpO(addr, tx) 70 { 67 71 } 68 72 … … 277 281 } 278 282 279 bool MTcpIp IO::InterpreteStr(TString str)283 bool MTcpIpCC::InterpreteStr(TString str) 280 284 { 281 285 cout << "Rx: " << str << flush; … … 283 287 } 284 288 285 Bool_t MTcpIp IO::ReadSocket(TSocket &rx)289 Bool_t MTcpIpCC::ReadSocket(TSocket &rx) 286 290 { 287 291 TString str; … … 308 312 309 313 // Data received (len==1) 310 if (c!='\n' )314 if (c!='\n' && c!=0) 311 315 { 312 316 str += c; … … 331 335 } 332 336 337 fRxMutex.Lock(); 338 333 339 fConnectionEstablished = kTRUE; 340 fRxSocket = &sock; 341 342 fRxMutex.UnLock(); 334 343 335 344 MTimeout timeout(fTimeout); … … 409 418 gLog << all << MTime(-1) << " Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl; 410 419 411 if (!WaitForData(*socket)) 412 fConnectionEstablished = kFALSE; 420 WaitForData(*socket); 421 422 fRxMutex.Lock(); 423 424 fRxSocket = 0; 425 fConnectionEstablished = kFALSE; 426 427 fRxMutex.UnLock(); 413 428 414 429 #ifdef DEBUG … … 455 470 456 471 return 0; 472 } 473 474 bool MTcpIpFact::Send(const char *msg, int len) 475 { 476 const Int_t mtx = fRxMutex.TryLock(); 477 if (mtx==13) 478 gLog << warn << "MTcpIpO::Send - mutex is already locked by this thread." << endl; 479 480 // If Mutex cannot be locked, i.e. we are currently reopening 481 // the send socket we cannot wait, because we would block the 482 // executing threrad. 483 if (mtx) 484 return false; 485 486 const bool rc = fRxSocket ? MTcpIpO::SendFrame(*fRxSocket, msg, len) : false; 487 488 fRxMutex.UnLock(); 489 490 return rc; 457 491 } 458 492 -
trunk/Cosy/tcpip/MTcpIpIO.h
r10031 r12598 20 20 class MTcpIpI : public MThread 21 21 { 22 protected: 23 TSocket *fRxSocket; 24 TMutex fRxMutex; 25 22 26 private: 23 27 Int_t fPortRx; // Port on which to listen for connections … … 36 40 37 41 public: 38 MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), f PortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ }42 MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fRxSocket(0), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ } 39 43 ~MTcpIpI() { CancelThread(); } 40 44 … … 65 69 }; 66 70 67 // This class es espcially meant to receive and send ascii messages 68 class MTcpIpIO : public MTcpIpI, public MTcpIpO 71 class MTcpIpCC : public MTcpIpI 69 72 { 70 73 private: … … 72 75 73 76 public: 74 MTcpIp IO(const char *addr, Int_t tx,Int_t rx, UInt_t timeout=5000);77 MTcpIpCC(Int_t rx, UInt_t timeout=5000); 75 78 76 79 virtual bool InterpreteStr(TString str); 80 }; 81 82 // This class es espcially meant to receive and send ascii messages 83 class MTcpIpIO : public MTcpIpCC, public MTcpIpO 84 { 85 86 public: 87 MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000); 77 88 }; 78 89 … … 91 102 }; 92 103 104 class MTcpIpFact : public MTcpIpCC 105 { 106 private: 107 108 public: 109 MTcpIpFact(const char *dumm1, Int_t dummy2, Int_t rx, UInt_t timeout) : MTcpIpCC(rx, timeout) 110 { 111 } 112 113 bool Send(const char *msg, int len); 114 }; 115 116 93 117 #endif
Note:
See TracChangeset
for help on using the changeset viewer.