Index: /trunk/Cosy/candrv/ethernet.cc
===================================================================
--- /trunk/Cosy/candrv/ethernet.cc	(revision 12587)
+++ /trunk/Cosy/candrv/ethernet.cc	(revision 12588)
@@ -76,6 +76,4 @@
 Bool_t Ethernet::ReadSocket(TSocket &rx)
 {
-    Int_t pos = -1;
-
     Message msg;
     msg.len = 0;
@@ -84,4 +82,52 @@
     msg.data[1] = 0;
 
+#ifdef FACT
+    const TString address = MTcpIpO::GetSocketAddress(rx);
+
+    // For details see TSocket::RecvRaw
+    // -1: // ERROR
+    // EINVAL, EWOULDBLOCK
+    // -5: // EPIPE || ECONNRESET = Pipe broken or connection reset by peer
+    //  0: Data received with zero length! (Connection lost/call interrupted)
+
+    const Int_t len1 = rx.RecvRaw(&msg.len, 1);
+    if (len1<=0)
+        return kFALSE;
+
+    if (len1!=1)
+    {
+        gLog << err << "ERROR - " << len1 << " bytes received from " << address << ", 1 byte expected!" << endl;
+        gLog << "        Connection will be closed." << endl;
+        return kFALSE;
+    }
+
+    if (msg.len>=MSGLEN-2)
+    {
+        gLog << err << "ERROR - " << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
+        gLog << "        Connection will be closed." << endl;
+        return kFALSE;
+    }
+
+    const Int_t len2 = rx.RecvRaw(msg.data+2, msg.len);
+    if (len2<=0)
+        return kFALSE;
+
+    if (len2!=msg.len)
+    {
+        gLog << err << "ERROR - " << len2 << " bytes received from " << address << ", " << msg.len << " byte expected!" << endl;
+        gLog << "        Connection will be closed." << endl;
+        return kFALSE;
+    }
+
+#ifdef DEBUG
+    cout << "*** RcvdCanFrame len=" << dec << msg.len << ": ";
+    for (int i=0; i<msg.len; i++)
+        cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " ";
+    cout << dec << endl;
+#endif
+
+    // String completed
+    HandleMessage(msg);
+#else
     const TString address = GetSocketAddress(rx);
 
@@ -140,85 +186,8 @@
         return kTRUE;
     }
+#endif
 
     return kTRUE;
 }
-
-/*
-void Ethernet::ReadSocket(TSocket &rx)
-{
-    Int_t pos = -1;
-
-    Message msg;
-    msg.cmd = M_BCAN_RX_ind;
-    msg.data[0] = 0;
-    msg.data[1] = 0;
-
-    const TString address = MTcpIpO::GetSocketAddress(rx);
-
-    while (!IsThreadCanceled())
-    {
-        //TThread::CancelPoint();
-
-        unsigned char c;
-        const Int_t len = rx.RecvRaw(&c, 1);
-
-        //TThread::CancelPoint();
-
-        // No data received (non-blocking mode)
-        if (len<0)
-        {
-            usleep(1);
-            continue;
-        }
-
-        // Data received with zero length!
-        if (len==0)
-        {
-            gLog << warn << "WARNING - Connection lost (received 0bytes) to " << address << endl;
-            //break; // This break is for TEST PURPOSE FIXME!!!
-            return;
-        }
-
-        // Data received
-        if (len>1)
-        {
-            gLog << err << "Data received from " << address << " is more than one byte!" << endl;
-            continue;
-        }
-
-        if (pos<0)
-        {
-            if (c>=MSGLEN)
-            {
-                cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
-                continue;
-            }
-
-            msg.len = c;
-            pos = 2;
-            continue;
-        }
-
-        //            if (pos==2 && c==0x0a)
-        //                continue;
-
-        msg.data[pos++] = c;
-        if (pos-2<msg.len)
-            continue;
-
-#ifdef DEBUG
-        cout << "*** RcvdCanFrame len=" << dec << msg.len << ": ";
-        for (int i=0; i<msg.len; i++)
-            cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " ";
-        cout << dec << endl;
-#endif
-
-        pos = -1;
-
-        // String completed
-        HandleMessage(msg);
-    }
-}
-*/
 
 // --------------------------------------------------------------------------
