Index: trunk/AddOn/TAcq/racqueth.cc
===================================================================
--- trunk/AddOn/TAcq/racqueth.cc	(revision 3900)
+++ trunk/AddOn/TAcq/racqueth.cc	(revision 3901)
@@ -466,5 +466,10 @@
     bool fgok=true;
     while (fgok&&(totnpaqrd_<par_.MaxNbPaquets())) {
-      if (stop_) break;
+      if (stop_) { 
+        if (prtlev_>0)  
+	  cout << ">S>S>S> EthernetReader::run() / Stopping, through Stop() method" << endl;  
+        stopreason_="EthernetReader::run() / Stopping, through Stop() method";
+        break;
+      }
       if ( MoveToNextTarget() ) {
 	cout << "EthernetReader::run()/Error-A- MoveToNextTarget() returned true ->STOP 9" << endl;
@@ -485,4 +490,9 @@
 	       << totsamefc_ << " / NPaqFib0Read=" << totnpqrd_[0] 
 	       << " FracSameFC=" << 100*totsamefc_/totnpqrd_[0] << " %" <<  endl;
+      }
+      if (totnpaqrd_>=par_.MaxNbPaquets()) { 
+        if (prtlev_>0)  
+	  cout << ">S>S>S> EthernetReader::run() / Stopping, totnpaqrd_>=par_.MaxNbPaquets()" << endl;  
+        stopreason_="EthernetReader::run() / Stopping, totnpaqrd_>=par_.MaxNbPaquets()";
       }
     }
@@ -537,6 +547,148 @@
 bool EthernetReader::ReadNextAllFibers()
 {
-  if (SkipAndSyncLinks()>8)  return true;
- 
+  if (sfc_maxresync_>0) return ReadNextAllFibersWithSync();
+
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+    if (ReadNext(fib)) return true;  // probleme 
+  }
+  if (!rdsamefc_ || (memgr_.NbFibres()<2))  {
+    uint_8 cfc=curfc_[0];
+    bool fgsamefc=true;
+    for(size_t fib=1; fib<memgr_.NbFibres(); fib++) {
+      if (curfc_[fib]!=cfc)   fgsamefc=false;
+    }
+    if (fgsamefc)  totsamefc_++;  
+    return false;  // c'est OK 
+  }
+  //  On va essayer de lire jusqu'a avoir same_frame_counter 
+  uint_8 cfc=curfc_[0];
+  bool fgsamefc=true;
+  for(size_t fib=1; fib<memgr_.NbFibres(); fib++) {
+    if (curfc_[fib]!=cfc) {
+      fgsamefc=false;
+      if (curfc_[fib] > cfc)  cfc=curfc_[fib]; 
+    }
+  }
+  if (fgsamefc) { 
+    totsamefc_++;  return false;  // c'est OK  , same framecounter
+  }
+  else {  // else !fgsame
+    bool encorerd=true;
+    uint_4  ntrd=0;
+    while(encorerd) {
+      encorerd=false;
+      for(uint_4 fib=0; fib<memgr_.NbFibres(); fib++) {
+        if (curfc_[fib]>=cfc)  continue;
+	if (ReadNext(fib)) return true;  // probleme 	  
+	encorerd=true;         
+      }
+      ntrd++;
+      if (ntrd>sfc_maxdpc_) {
+        if (prtlev_>0)  
+	  cout << ">S>S>S> EthernetReader::ReadNextAllFibers(" << fib << ")/ Stopping, Nb_ReadNext="  
+               << ntrd << " > sfc_maxdpc_" << endl; 
+        stopreason_="ReadNextAllFibers() StopReason: failed to get SameFC Nb_ReadNext>sfc_maxdpc_";
+        return true; 
+      }
+    }
+  }   // fin de  else !fgsame 
+
+  return true; // probleme 
+}
+
+/* --Methode-- */
+bool EthernetReader::ReadNext(int fib)
+{
+  bool fggood=false;
+  while(!fggood) { 
+    ReceiveFromSocket(fib, (char *)vpaq_[fib].Begin(), packsize_);
+    if (vec_fgsokend_[fib])   {   // fin de reception sur le lien 
+      if (prtlev_>0)  
+	cout << ">S>S>S> EthernetReader::ReadNext(" << fib << ")/ Stopping, reason EndReceive fgsokend_=" 
+	     << vec_fgsokend_[fib] << endl; 
+      stopreason_="ReadNext() StopReason: EndReceive signaled on link";
+      return true; 
+    }
+    totnbytesrd_+=packsize_;
+    totnpqrd_[fib]++;
+    fggood = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
+  }
+  totnpqok_[fib]++;
+  return false;
+}
+
+/* --Methode-- */
+void EthernetReader::CleanUpAllSockets()
+{
+  bool fgallfinished=false;
+  while (!fgallfinished) {
+    fgallfinished=true;
+    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+      if (vec_fgsokend_[fib]>0) continue;
+      ReceiveFromSocket(fib,dummybuff_,packsize_);
+      fgallfinished=false;
+    }
+  }
+  return;
+}
+
+/* --Methode-- */
+size_t EthernetReader::ReceiveFromSocket(int fib, char* data, size_t len)
+{
+  size_t rc =0;
+  if (vec_fgsokend_[fib]) { // la lecture est finie 
+    memset(data, 0, len);
+    return 0;
+  }
+
+  if (vec_cntpaq_[fib]%memgr_.NbPaquets() == 0) { 
+    char msg[BRTCPMSGLEN2];
+    msg[0]='\0';
+    vsok_[fib].ReceiveAll(msg, BRTCPMSGLEN2);
+    //    if (strncmp(msg,"PCIEToEthernet-SendCnt",22) != 0) 
+    //      cout << " EthernetReader::ReceiveFromSocket/ BAD HandShake message : " << msg << endl;
+    bool fgbadhsm=true;
+    if (strncmp(msg,"PCIEToEthernet-Send",19)==0) {
+      if (strncmp(msg+19,"Cnt",3)==0) fgbadhsm=false;
+      else if (strncmp(msg+19,"-END",4)==0) {
+	fgbadhsm=false;
+	vec_fgsokend_[fib]=1;  gl_fgsokend=true;
+	//DBG	cout << "ReceiveFromSocket/DEBUG -END msg received  " << endl;
+	if (prtlev_>2)  
+	  cout << " EthernetReader::ReceiveFromSocket/ Receive on LinkNo" << fib << " Ended OK" << endl;
+      }
+    }
+    if (fgbadhsm) {
+      cout << " EthernetReader::ReceiveFromSocket/ BAD HandShake, LinkNo " <<  fib << " msg: " << msg << endl;
+      vec_fgsokend_[fib]=2; 
+    }
+  }
+
+  if (vec_fgsokend_[fib]>0) { // la lecture est finie 
+    memset(data, 0, len);
+    return 0;
+  }
+
+  rc += vsok_[fib].ReceiveAll(data, len);
+  vec_cntpaq_[fib]++;
+
+#ifdef BR_DO_HANDSHAKE
+  // Envoi de message de hand-shake 
+  if (vec_cntpaq_[fib]%memgr_.NbPaquets() == 0) {
+    char msg[BRTCPMSGLEN2];
+    sprintf(msg,"EthernetReader-RecvCnt %d",vec_cntpaq_[fib]);
+    vsok_[fib].SendAll(msg, BRTCPMSGLEN2);
+    //DBG    cout << " ReceiveFromSocket/DEBUG-B msg=" << msg << endl;
+  }
+#endif  
+  return rc;
+}
+
+/* --Methode-- */
+bool EthernetReader::ReadNextAllFibersWithSync()
+{
+  if (rdsamefc_&&(sfc_maxresync_>0)) {
+    if (SkipAndSyncLinks()>8)  return true;
+  }
   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
     if (ReadNext(fib)) return true;  // probleme 
@@ -557,7 +709,7 @@
     if (nbechec>sfc_maxresync_)  { 
       if (prtlev_>0)  
-	cout << ">S>S>S> EthernetReader::ReadNextAllFibers()/ Stopping, reason NbEchec>(NbMax_Resync=" 
+	cout << ">S>S>S> EthernetReader::ReadNextAllFibersWithSync()/ Stopping, reason NbEchec>(NbMax_Resync=" 
 	     << sfc_maxresync_ << ")" << endl; 
-      stopreason_="ReadNextAllFibers() , StopReason: NbEchec>NbMax_Resyn";
+      stopreason_="ReadNextAllFibersWithSync() , StopReason: NbEchec>NbMax_Resyn";
       return true;
     }
@@ -574,5 +726,4 @@
     }
     else {  // else !fgsame
-      if (nbechec>sfc_maxresync_)  return true;
       if (nbechec>0)   {
 	int rcres=SkipAndSyncLinks();
@@ -596,5 +747,5 @@
       
       if (prtlev_>5) 
-	cout << " EthernetReader::ReadNextAllFibers()/DEBUG NbEchec=" << nbechec  
+	cout << " EthernetReader::ReadNextAllFibersWithSync()/DEBUG NbEchec=" << nbechec  
 	     << " cfc=" << cfc << endl;
       
@@ -605,4 +756,5 @@
 	}
       }
+
       nbechec++;
     }   // fin de  else !fgsame 
@@ -610,92 +762,4 @@
 
   return true; // probleme 
-}
-
-/* --Methode-- */
-bool EthernetReader::ReadNext(int fib)
-{
-  bool fggood=false;
-  while(!fggood) { 
-    ReceiveFromSocket(fib, (char *)vpaq_[fib].Begin(), packsize_);
-    if (vec_fgsokend_[fib])   {   // fin de reception sur le lien 
-      if (prtlev_>0)  
-	cout << ">S>S>S> EthernetReader::ReadNext(" << fib << ")/ Stopping, reason EndReceive fgsokend_=" 
-	     << vec_fgsokend_[fib] << endl; 
-      stopreason_="ReadNext() StopReason: EndReceive signaled on link";
-      return true; 
-    }
-    totnbytesrd_+=packsize_;
-    totnpqrd_[fib]++;
-    fggood = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
-  }
-  totnpqok_[fib]++;
-  return false;
-}
-
-/* --Methode-- */
-void EthernetReader::CleanUpAllSockets()
-{
-  bool fgallfinished=false;
-  while (!fgallfinished) {
-    fgallfinished=true;
-    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
-      if (vec_fgsokend_[fib]>0) continue;
-      ReceiveFromSocket(fib,dummybuff_,packsize_);
-      fgallfinished=false;
-    }
-  }
-  return;
-}
-
-/* --Methode-- */
-size_t EthernetReader::ReceiveFromSocket(int fib, char* data, size_t len)
-{
-  size_t rc =0;
-  if (vec_fgsokend_[fib]) { // la lecture est finie 
-    memset(data, 0, len);
-    return 0;
-  }
-
-  if (vec_cntpaq_[fib]%memgr_.NbPaquets() == 0) { 
-    char msg[BRTCPMSGLEN2];
-    msg[0]='\0';
-    vsok_[fib].ReceiveAll(msg, BRTCPMSGLEN2);
-    //    if (strncmp(msg,"PCIEToEthernet-SendCnt",22) != 0) 
-    //      cout << " EthernetReader::ReceiveFromSocket/ BAD HandShake message : " << msg << endl;
-    bool fgbadhsm=true;
-    if (strncmp(msg,"PCIEToEthernet-Send",19)==0) {
-      if (strncmp(msg+19,"Cnt",3)==0) fgbadhsm=false;
-      else if (strncmp(msg+19,"-END",4)==0) {
-	fgbadhsm=false;
-	vec_fgsokend_[fib]=1;  gl_fgsokend=true;
-	//DBG	cout << "ReceiveFromSocket/DEBUG -END msg received  " << endl;
-	if (prtlev_>2)  
-	  cout << " EthernetReader::ReceiveFromSocket/ Receive on LinkNo" << fib << " Ended OK" << endl;
-      }
-    }
-    if (fgbadhsm) {
-      cout << " EthernetReader::ReceiveFromSocket/ BAD HandShake, LinkNo " <<  fib << " msg: " << msg << endl;
-      vec_fgsokend_[fib]=2; 
-    }
-  }
-
-  if (vec_fgsokend_[fib]>0) { // la lecture est finie 
-    memset(data, 0, len);
-    return 0;
-  }
-
-  rc += vsok_[fib].ReceiveAll(data, len);
-  vec_cntpaq_[fib]++;
-
-#ifdef BR_DO_HANDSHAKE
-  // Envoi de message de hand-shake 
-  if (vec_cntpaq_[fib]%memgr_.NbPaquets() == 0) {
-    char msg[BRTCPMSGLEN2];
-    sprintf(msg,"EthernetReader-RecvCnt %d",vec_cntpaq_[fib]);
-    vsok_[fib].SendAll(msg, BRTCPMSGLEN2);
-    //DBG    cout << " ReceiveFromSocket/DEBUG-B msg=" << msg << endl;
-  }
-#endif  
-  return rc;
 }
 
