Changeset 8865 for trunk/MagicSoft/Cosy/tcpip
- Timestamp:
- 02/20/08 19:39:13 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy/tcpip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r8864 r8865 12 12 13 13 #include "MString.h" 14 #include "MTimeout.h" 14 15 15 16 #undef DEBUG … … 84 85 } 85 86 86 const Int_t l = tx.SendRaw(msg, len);87 if (l<0)88 {89 gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;90 return false;91 }92 93 if (l!=len)94 {95 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;96 return false;97 }98 99 87 #ifdef DEBUG 100 88 cout << "Tx: " << msg << flush; 101 89 #endif 90 91 const Int_t l = tx.SendRaw(msg, len); 92 if (l<0) 93 { 94 gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl; 95 return false; 96 } 97 98 if (l!=len) 99 { 100 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl; 101 return false; 102 } 102 103 103 104 return true; … … 164 165 const Int_t len = rx.RecvRaw(&c, 1); 165 166 166 // No data received (non-blocking mode) 167 if (len<0) 168 { 169 usleep(1); 170 continue; 171 } 172 173 // Data received with zero length! (Connection lost) 174 if (len==0) 175 return kFALSE; // This break is for TEST PURPOSE FIXME!!! 167 // For details see TSocket::RecvRaw 168 // -1: // ERROR 169 // EINVAL, EWOULDBLOCK 170 // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer 171 // 0: Data received with zero length! (Connection lost/call interrupted) 172 if (len<=0) 173 return kFALSE; 176 174 177 175 // Data received … … 208 206 fConnectionEstablished = kTRUE; 209 207 208 MTimeout timeout; 209 210 210 // Get connection on port fPortRx and redirected 211 211 while (!IsThreadCanceled()) … … 220 220 return kFALSE; 221 221 } 222 223 // *FALLTHROUGH* 222 timeout.Start(fTimeout); 223 224 // Go on waiting for new data 225 continue; 226 224 227 case kFALSE: // Time out, no data yet, go on waiting 228 if (timeout.HasTimedOut()) 229 { 230 gLog << warn << "WARNING - Connection to " << MTcpIpO::GetSocketAddress(sock) << " timed out." << endl; 231 return kFALSE; 232 } 225 233 226 234 // Go on waiting for new data … … 248 256 while (!IsThreadCanceled()) 249 257 { 258 // Wait for a new connection on RX port 250 259 socket = server.Accept(); 251 260 … … 271 280 if ((Long_t)socket<=0) 272 281 return; 282 283 gLog << all << "Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl; 273 284 274 285 if (!WaitForData(*socket)) -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r8864 r8865 18 18 { 19 19 private: 20 Int_t fPortRx; 20 Int_t fPortRx; // Port on which to listen for connections 21 Int_t fTimeout; // [ms] Timeout to listen for data to be received 22 21 23 Bool_t fConnectionEstablished; 22 24 … … 29 31 30 32 public: 31 MTcpIpI(Int_t rx ) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fConnectionEstablished(kFALSE) { /*RunThread();*/ }33 MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ } 32 34 ~MTcpIpI() { CancelThread(); } 33 35
Note:
See TracChangeset
for help on using the changeset viewer.