Index: trunk/FACT++/src/EventBuilder.c
===================================================================
--- trunk/FACT++/src/EventBuilder.c	(revision 11893)
+++ trunk/FACT++/src/EventBuilder.c	(revision 11895)
@@ -1,4 +1,7 @@
 
 // // // #define EVTDEBUG
+
+#define NUMSOCK   1          //set to 7 for old configuration
+#define MAXREAD  65536       //64kB wiznet buffer
 
 #include <stdlib.h>
@@ -18,5 +21,5 @@
 #include <netinet/tcp.h>
 #include <pthread.h>
-#include <sched.h>
+#include <sched.h>                              
 
 #include "EventBuilder.h"
@@ -147,4 +150,5 @@
    int32_t bufPos;              //next byte to read to the buffer next
    int32_t bufLen;              //number of bytes left to read
+// size_t bufLen;               //number of bytes left to read size_t might be better
    int32_t skip;                //number of bytes skipped before start of event
 
@@ -441,9 +445,9 @@
    for (k = 0; k < MAX_RUN; k++) {
       if (runCtrl[k].runId == runID) {
-         if (runCtrl[k].procId > 0) {   //run is closed -> reject
-            snprintf (str, MXSTR, "skip event since run %d finished", runID);
-            factOut (kInfo, 931, str);
-            return -21;
-         }
+//         if (runCtrl[k].procId > 0) {   //run is closed -> reject
+//            snprintf (str, MXSTR, "skip event since run %d finished", runID);
+//            factOut (kInfo, 931, str);
+//            return -21;
+//         }
 
          if (runCtrl[k].roi0 != nRoi[0]
@@ -490,5 +494,5 @@
       runCtrl[evFree].firstTime = runCtrl[evFree].lastTime = tsec;
       runCtrl[evFree].closeTime = tsec + 3600 * 24;     //max time allowed
-      runCtrl[evFree].lastTime = 0;
+//    runCtrl[evFree].lastTime = 0;
 
       runTail[evFree].nEventsOk =
@@ -768,4 +772,6 @@
    numok = numok2 = 0;
 
+   int cntsock = 8 - NUMSOCK ;
+
    if (gi_resetS > 0) {
       //make sure all sockets are preallocated as 'not exist'
@@ -796,5 +802,5 @@
          gj.evtSkip = gj.evtWrite = gj.evtErr = 0;
 
-      int b;
+      int b,p;
       for (b = 0; b < NBOARDS; b++)
          gj.badRoi[b] = 0;
@@ -861,5 +867,10 @@
 
       for (i = 0; i < MAX_SOCK; i++) {  //check all sockets if something to read
-         b = i / 7;
+         b = i / 7 ;
+         p = i % 7 ;
+
+//if ( b==32 && p>0) {  ; }
+if ( p >= NUMSOCK) { ; }
+else {
          if (sockDef[b] > 0)
             s0 = +1;
@@ -881,5 +892,7 @@
                rd[i].bufPos = 0;        //  no byte read so far
                rd[i].skip = 0;  //  start empty
-               gi_NumConnect[b]++;
+//             gi_NumConnect[b]++;
+               gi_NumConnect[b] += cntsock ;
+
                gi.numConn[b]++;
                gj.numConn[b]++;
@@ -892,7 +905,11 @@
             if (rd[i].bufLen > 0) {     //might be nothing to read [buffer full]
                numok++;
+               size_t maxread = rd[i].bufLen ;
+               if (maxread > MAXREAD ) maxread=MAXREAD ;
+
                jrd =
                   recv (rd[i].socket, &rd[i].rBuf->B[rd[i].bufPos],
-                        rd[i].bufLen, MSG_DONTWAIT);
+                        maxread, MSG_DONTWAIT);
+//                      rd[i].bufLen, MSG_DONTWAIT);
 
                if (jrd > 0) {
@@ -914,5 +931,6 @@
                   GenSock (s0, i, 0, NULL, &rd[i]);
                   gi.gotErr[b]++;
-                  gi_NumConnect[b]--;
+//                gi_NumConnect[b]--;
+                  gi_NumConnect[b]-= cntsock ;
                   gi.numConn[b]--;
                   gj.numConn[b]--;
@@ -1220,4 +1238,5 @@
 
             }                   //end interpreting last read
+}
          }                      //end of successful read anything
       }                         //finished trying to read all sockets
@@ -1352,5 +1371,6 @@
             GenSock (-1, i, 0, NULL, &rd[i]);   //close and destroy open socket   
             if (i % 7 == 0) {
-               gi_NumConnect[i / 7]--;
+//             gi_NumConnect[i / 7]--;
+               gi_NumConnect[i / 7]-= cntsock ;
                gi.numConn[i / 7]--;
                gj.numConn[i / 7]--;
@@ -1644,5 +1664,5 @@
                      runCtrl[j].fileId = 91;
                      runCtrl[j].procId = 91;
-                  } else {
+                  } else {                                                 
                      snprintf (str, MXSTR, "P opened new run_file %d evt %d",
                                irun, ievt);
@@ -1670,10 +1690,10 @@
                             "P skip event %d because no active run %d", ievt,
                             irun);
-                  factOut (kInfo, 502, str);
+                  factOut (kDebug, 502, str);
                   evtCtrl.evtStat[k0] = 9091;
                } else {
 //--------
 //--------
-                  int id = evtCtrl.evtBuf[k0];
+                      id = evtCtrl.evtBuf[k0];
                   int itevt = mBuffer[id].trgNum;
                   int itrg = mBuffer[id].trgTyp;
@@ -2080,5 +2100,5 @@
 
          if (runCtrl[j].procId == 0) {
-            runFinish (runCtrl[j].runId);
+            runFinish1 (runCtrl[j].runId);
             runCtrl[j].procId = 92;
          }
