Ignore:
Timestamp:
11/21/11 13:08:27 (13 years ago)
Author:
tbretz
Message:
Implemented a new class MTcpIpFact using a duplex communication for FACT
File:
1 edited

Legend:

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

    r10031 r12598  
    6262}
    6363
    64 MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout), MTcpIpO(addr, tx)
     64MTcpIpCC::MTcpIpCC(Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout)
    6565{
    6666    MTcpIpI::RunThread();
     67}
     68
     69MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpCC(rx, timeout), MTcpIpO(addr, tx)
     70{
    6771}
    6872
     
    277281}
    278282
    279 bool MTcpIpIO::InterpreteStr(TString str)
     283bool MTcpIpCC::InterpreteStr(TString str)
    280284{
    281285    cout << "Rx: " << str << flush;
     
    283287}
    284288
    285 Bool_t MTcpIpIO::ReadSocket(TSocket &rx)
     289Bool_t MTcpIpCC::ReadSocket(TSocket &rx)
    286290{
    287291    TString str;
     
    308312
    309313        // Data received (len==1)
    310         if (c!='\n')
     314        if (c!='\n' && c!=0)
    311315        {
    312316            str += c;
     
    331335    }
    332336
     337    fRxMutex.Lock();
     338
    333339    fConnectionEstablished = kTRUE;
     340    fRxSocket = &sock;
     341
     342    fRxMutex.UnLock();
    334343
    335344    MTimeout timeout(fTimeout);
     
    409418        gLog << all << MTime(-1) << " Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl;
    410419
    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();
    413428
    414429#ifdef DEBUG
     
    455470
    456471    return 0;
     472}
     473
     474bool 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;
    457491}
    458492
Note: See TracChangeset for help on using the changeset viewer.