Ignore:
Timestamp:
02/20/08 19:39:13 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/tcpip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r8864 r8865  
    1212
    1313#include "MString.h"
     14#include "MTimeout.h"
    1415
    1516#undef DEBUG
     
    8485    }
    8586
    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 
    9987#ifdef DEBUG
    10088    cout << "Tx: " << msg << flush;
    10189#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    }
    102103
    103104    return true;
     
    164165        const Int_t len = rx.RecvRaw(&c, 1);
    165166
    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;
    176174
    177175        // Data received
     
    208206    fConnectionEstablished = kTRUE;
    209207
     208    MTimeout timeout;
     209
    210210    // Get connection on port fPortRx and redirected
    211211    while (!IsThreadCanceled())
     
    220220                return kFALSE;
    221221            }
    222 
    223             // *FALLTHROUGH*
     222            timeout.Start(fTimeout);
     223
     224            // Go on waiting for new data
     225            continue;
     226
    224227        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            }
    225233
    226234            // Go on waiting for new data
     
    248256        while (!IsThreadCanceled())
    249257        {
     258            // Wait for a new connection on RX port
    250259            socket = server.Accept();
    251260
     
    271280        if ((Long_t)socket<=0)
    272281            return;
     282
     283        gLog << all << "Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl;
    273284
    274285        if (!WaitForData(*socket))
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r8864 r8865  
    1818{
    1919private:
    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
    2123    Bool_t fConnectionEstablished;
    2224
     
    2931
    3032public:
    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();*/ }
    3234    ~MTcpIpI() { CancelThread(); }
    3335
Note: See TracChangeset for help on using the changeset viewer.