Changeset 12588 for trunk


Ignore:
Timestamp:
11/21/11 11:24:36 (13 years ago)
Author:
tbretz
Message:
Added new ReadSocket code for FACT SPS... should be used in MAGIC SPS, too.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosy/candrv/ethernet.cc

    r10031 r12588  
    7676Bool_t Ethernet::ReadSocket(TSocket &rx)
    7777{
    78     Int_t pos = -1;
    79 
    8078    Message msg;
    8179    msg.len = 0;
     
    8482    msg.data[1] = 0;
    8583
     84#ifdef FACT
     85    const TString address = MTcpIpO::GetSocketAddress(rx);
     86
     87    // For details see TSocket::RecvRaw
     88    // -1: // ERROR
     89    // EINVAL, EWOULDBLOCK
     90    // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer
     91    //  0: Data received with zero length! (Connection lost/call interrupted)
     92
     93    const Int_t len1 = rx.RecvRaw(&msg.len, 1);
     94    if (len1<=0)
     95        return kFALSE;
     96
     97    if (len1!=1)
     98    {
     99        gLog << err << "ERROR - " << len1 << " bytes received from " << address << ", 1 byte expected!" << endl;
     100        gLog << "        Connection will be closed." << endl;
     101        return kFALSE;
     102    }
     103
     104    if (msg.len>=MSGLEN-2)
     105    {
     106        gLog << err << "ERROR - " << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
     107        gLog << "        Connection will be closed." << endl;
     108        return kFALSE;
     109    }
     110
     111    const Int_t len2 = rx.RecvRaw(msg.data+2, msg.len);
     112    if (len2<=0)
     113        return kFALSE;
     114
     115    if (len2!=msg.len)
     116    {
     117        gLog << err << "ERROR - " << len2 << " bytes received from " << address << ", " << msg.len << " byte expected!" << endl;
     118        gLog << "        Connection will be closed." << endl;
     119        return kFALSE;
     120    }
     121
     122#ifdef DEBUG
     123    cout << "*** RcvdCanFrame len=" << dec << msg.len << ": ";
     124    for (int i=0; i<msg.len; i++)
     125        cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " ";
     126    cout << dec << endl;
     127#endif
     128
     129    // String completed
     130    HandleMessage(msg);
     131#else
    86132    const TString address = GetSocketAddress(rx);
    87133
     
    140186        return kTRUE;
    141187    }
     188#endif
    142189
    143190    return kTRUE;
    144191}
    145 
    146 /*
    147 void Ethernet::ReadSocket(TSocket &rx)
    148 {
    149     Int_t pos = -1;
    150 
    151     Message msg;
    152     msg.cmd = M_BCAN_RX_ind;
    153     msg.data[0] = 0;
    154     msg.data[1] = 0;
    155 
    156     const TString address = MTcpIpO::GetSocketAddress(rx);
    157 
    158     while (!IsThreadCanceled())
    159     {
    160         //TThread::CancelPoint();
    161 
    162         unsigned char c;
    163         const Int_t len = rx.RecvRaw(&c, 1);
    164 
    165         //TThread::CancelPoint();
    166 
    167         // No data received (non-blocking mode)
    168         if (len<0)
    169         {
    170             usleep(1);
    171             continue;
    172         }
    173 
    174         // Data received with zero length!
    175         if (len==0)
    176         {
    177             gLog << warn << "WARNING - Connection lost (received 0bytes) to " << address << endl;
    178             //break; // This break is for TEST PURPOSE FIXME!!!
    179             return;
    180         }
    181 
    182         // Data received
    183         if (len>1)
    184         {
    185             gLog << err << "Data received from " << address << " is more than one byte!" << endl;
    186             continue;
    187         }
    188 
    189         if (pos<0)
    190         {
    191             if (c>=MSGLEN)
    192             {
    193                 cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
    194                 continue;
    195             }
    196 
    197             msg.len = c;
    198             pos = 2;
    199             continue;
    200         }
    201 
    202         //            if (pos==2 && c==0x0a)
    203         //                continue;
    204 
    205         msg.data[pos++] = c;
    206         if (pos-2<msg.len)
    207             continue;
    208 
    209 #ifdef DEBUG
    210         cout << "*** RcvdCanFrame len=" << dec << msg.len << ": ";
    211         for (int i=0; i<msg.len; i++)
    212             cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " ";
    213         cout << dec << endl;
    214 #endif
    215 
    216         pos = -1;
    217 
    218         // String completed
    219         HandleMessage(msg);
    220     }
    221 }
    222 */
    223192
    224193// --------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.