HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hrevbuffer.cc
Go to the documentation of this file.
1 //_HADES_CLASS_DESCRIPTION
2 //////////////////////////////////////////////////////////////////////
3 // Copyright:
4 // GSI, Gesellschaft fuer Schwerionenforschung mbH
5 // Planckstr. 1
6 // D-64291 Darmstadt
7 // Germany
8 //////////////////////////////////////////////////////////////////////
9 // HRevBuffer.cc
10 // ROOT client package for multithreaded Hades remote event server
11 // created 14. 5.1999 by Horst Goeringer
12 //////////////////////////////////////////////////////////////////////
13 //
14 // Imported into Hydra as hrevbuffer.cc and hrevbuffer.h by
15 // Simon Lang, 08.12.05
16 //
17 //////////////////////////////////////////////////////////////////////
18 
19 #include <signal.h>
20 #include <unistd.h>
21 #include <time.h>
22 #include <netinet/in.h>
23 #include <sys/socket.h>
24 #include <sys/select.h>
25 
26 using namespace std;
27 
28 #include "hrevbuffer.h" // class definition
29 
31 
32 Int_t iTimeOut; // needed in exitCli to handle CTL C
33 Int_t imySig = 0; // needed in exitCli to handle CTL C
34 Int_t iOutMode = 0; // needed in exitCli to handle CTL C
35 
36 /* client requests events from server */
37 typedef struct
38 {
39  Int_t iSize; /* size of comm. buffer without this element (bytes) */
40  Int_t iMode; /* must be 1: client requests data */
41  Int_t iIdent;/* =1: NOT IN NET REPR. to identify client endian type */
42  Int_t iBufRequ; /* number of buffers requested */
43 } srevComm;
44 
45 /* server sends info to client */
46 typedef struct
47 {
48  Int_t iSize; /* size of info buffer without this element (bytes) */
49  Int_t iMode; /* must be 1: server sends info */
50  /* else: client tries swap */
51  Int_t iHeadPar; /* no. of header parms in buffer */
52  Int_t iTimeOut; /* wait time client after CTL C */
53 } srevInfo;
54 
55 /* server sends dummy buffer to client, if no DAQ events available */
56 typedef struct
57 {
58  Int_t iSize; /* size of data following */
59  Int_t iBufNo; /* current buffer number */
60  Int_t iEvtNo; /* no. of events in buffer (= 0) */
61 } sptrevDummy;
62 
63 
64 static void exitCli(Int_t signal) /* handles Ctl C */
65 {
66  Int_t iSleep; /* sleep time here */
67  Int_t iSocket;
68 
69  iSocket = imySig;
70  imySig = -1;
71  iSleep = iTimeOut;
72 
73  printf("\n-I- user specified CTL C: ");
74  if (iSocket > 0)
75  {
76  if (iOutMode)
77  printf("close connection (socket %d), hold client for %d s\n",
78  iSocket, iSleep);
79  else printf("close connection\n");
80 
81  if (iSleep) sleep(iSleep);
82  }
83  else printf("\n");
84 }
85 
86 
87 static Int_t rclose(Int_t *piSocket, Int_t iMode)
88 {
89  Int_t iSocket;
90  Int_t iRC;
91  Int_t iDebug = 0;
92  Int_t iError = 0;
93  Int_t iClose = 1;
94  Char_t cModule[32] = "rclose";
95  Char_t cMsg[128] = "";
96 
97  if (iMode < 0)
98  {
99  iMode = -iMode;
100  iClose = 0; /* no shutdown, only close */
101  }
102  if ( (iMode < 0) || (iMode > 3) )
103  {
104  if (iClose == 0) iMode = -iMode;
105  printf("-E- %s: invalid shutdown mode: %d\n", cModule, iMode);
106  iError = 2;
107  }
108 
109  iSocket = *piSocket;
110  if (iSocket > 0)
111  {
112  if (iMode < 3)
113  {
114  iRC = shutdown(iSocket, iMode);
115  if (iRC)
116  {
117  sprintf(cMsg, "-E- %s: shutdown(%d) rc = %d",
118  cModule, iMode, iRC);
119  perror(cMsg);
120  iError = -1;
121  }
122  else if (iDebug)
123  printf(" %s: shutdown(%d) successfull\n",
124  cModule, iMode);
125  }
126 
127  if (iClose)
128  {
129  iRC = close(iSocket);
130  if (iRC)
131  {
132  sprintf(cMsg, "-E- %s: close rc = %d", cModule, iRC);
133  perror(cMsg);
134  iError = -2;
135  }
136  else if (iDebug)
137  printf(" %s: connection closed\n", cModule);
138 
139  } /* (iClose) */
140 
141  } /* (iSocket > 0) */
142  else
143  {
144  printf("-E- %s: invalid socket: %d\n", cModule, iSocket);
145  iError = 1;
146  }
147 
148  *piSocket = 0;
149  return(iError);
150 }
151 
152 
153 
154 static Long_t swaplw(Long_t *pp_source, Long_t l_len, Long_t* pp_dest)
155 {
156  UChar_t *p_source, *p_dest, *p_s, *p_d;
157  ULong_t lu_save;
158 
159  /* +++ action +++ */
160  p_source = (UChar_t *) pp_source;
161  p_dest = (UChar_t *) pp_dest;
162 
163  if ( !p_dest)
164  {
165  /* source == destination */
166  for (p_d = (UChar_t *) p_source,
167  p_s = (UChar_t *) &lu_save;
168  p_d < p_source + (l_len * 4);
169  )
170  {
171  lu_save = *( (Long_t *) p_d);
172  p_s += 4; /* increment source */
173  *(p_d++) = *(--p_s);
174  *(p_d++) = *(--p_s);
175  *(p_d++) = *(--p_s);
176  *(p_d++) = *(--p_s);
177  }
178  } else{
179  /* source != destination */
180  for (p_s = (UChar_t *) p_source,
181  p_d = (UChar_t *) p_dest;
182  p_s < p_source + (l_len * 4);
183  p_s += 4)
184  {
185  p_s += 4; /* increment source */
186  *(p_d++) = *(--p_s);
187  *(p_d++) = *(--p_s);
188  *(p_d++) = *(--p_s);
189  *(p_d++) = *(--p_s);
190  }
191 
192  }
193 
194  return(1);
195 }
196 
197 
198 
200 {
201  iSwap = 0;
202  iSocket = 0;
203  iEvtPar = 0;
204  iBufSize = 0;
205 
206  signal(SIGINT, &exitCli); // from now catch Ctl C
207 
208  iDebug = iMode;
209  iOutMode = iMode;
210  if (iDebug == 1)
211  cout << "-I- client runs in debug mode (1)" << endl;
212  else if (iDebug == 2)
213  cout << "-I- client shows buffer numbers and select/receive (mode 2)"
214  << endl;
215  else if (iDebug == 3)
216  cout << "-I- client shows buffer numbers (mode 3)" << endl;
217 
218  iBufSizeAlloc = 32768;
219  piBuf = new Int_t [iBufSizeAlloc/sizeof(int)]; // 32k buffer
220 
221  // cout << " HRevBuffer() executed" << endl;
222 
223 } // constructor
224 
225 
226 
228 {
229  // cout << " ~HRevBuffer() ..." << endl;
230  delete [] piBuf;
231  piNextEvt = 0;
232  // cout << " ~HRevBuffer() executed" << endl;
233 
234 } // destructor
235 
236 
237 
238 TSocket *HRevBuffer::RevOpen (const Char_t *pNode, Int_t iPort, Int_t iEvent)
239 {
240  if (iEvent < 0)
241  {
242  cout << "-E- number of requested events (" << iEvent
243  << ") invalid" << endl;
244  return(0);
245  }
246  iEvtMax = iEvent;
247  iEvtNo = 0;
248  iBufNo = 0;
249  iBufNo1 = 0;
250  iBufNo2 = 0;
251 
252  if (!iSocket)
253  {
254  iEvtNo = -1; // initialization (info buffer) required
255  if (iPort == 0) iPort = 7031; // default for Hades
256  cout << "-I- open connection to server " << pNode
257  << ":" << iPort << endl;
258 
259  pTSocket = new TSocket(pNode, iPort);
260  if ( !pTSocket->IsValid() )
261  {
262  cout << "-E- open connection to server " << pNode
263  << " failed" << endl;
264  return(0);
265  }
266  cout << " connection to server " << pNode
267  << ":" << iPort << " okay" << endl;
268 
269  iSocket = pTSocket->GetDescriptor();
270  imySig = iSocket;
271  if (iDebug == 1)
272  cout << " new socket " << iSocket << endl;
273  }
274  else if (iDebug == 1)
275  cout << "-D- still socket " << iSocket << endl;
276 
277  return(pTSocket);
278 
279 } // RevOpen
280 
281 
282 
283 UInt_t *HRevBuffer::RevGet(TSocket *pSocket, Int_t iFlush)
284 {
285  Int_t iint = sizeof(int);
286  Int_t ibyte, ilen, inew = 0;
287  Int_t imaxSE = 20;
288  Int_t indSize[20]; // index imaxSE
289  Int_t ioff=0, irem, ind, ii, jj;
290 
291  Char_t cMsg[128] = "";
292  Char_t *pcBuf;
293  Int_t iSize, iRC;
294 
295  Int_t iError = 0;
296  Int_t iRetry;
297  Int_t iRetryMax = 1000;
298  Int_t iRetryFirst;
299  Int_t iRetryRecv = 0; // count retries of recv call
300  Int_t iRetryRecvLim = 1; // max. no. of succeeding retries
301 
302  Int_t *piComm;
303  srevComm sComm;
304  Int_t iCommSize = sizeof(sComm); // size comm. buffer (byte)
305 
306  Int_t *piInfo;
307  srevInfo sInfo;
308  Int_t iInfoSize = sizeof(sInfo); // size info buffer (byte)
309  Int_t iBufNoServ; // buffer no., from server
310 
311  if (iEvtNo >= iEvtMax) goto gEndGet;
312 
313  piComm = &(sComm.iSize); // communication buffer
314  sComm.iSize = htonl(iCommSize-iint); // size of data following
315  sComm.iMode = htonl(1); // required: get events
316  sComm.iIdent = 1; // required: tell endian type
317  sComm.iBufRequ = htonl(1); // send one buffer
318 
319  // initialize communication with server
320  if (iEvtNo == -1)
321  {
322  if (iDebug == 1)
323  cout << "-D- commbuf (data size " << ntohl(sComm.iSize)
324  << " byte): mode(1) " << ntohl(sComm.iMode)
325  << ", request " << ntohl(sComm.iBufRequ)
326  << " event buffer(s)" << endl;
327 
328  // request event buffer from server
329  ilen = pSocket->SendRaw(piComm, iCommSize, kDefault);
330  if (ilen < 0)
331  {
332  cout << "-E- sending request for events to server, rc = "
333  << ilen << endl;
334  iError = 1;
335  goto gEndGet;
336  }
337 
338  if (iDebug == 1)
339  cout << " communication buffer sent (request info buffer) "
340  << endl;
341 
342  // receive info buffer from server
343  piInfo = &(sInfo.iSize);
344  ilen = pSocket->RecvRaw(piInfo, iInfoSize, kDefault);
345  if (ilen < 0)
346  {
347  cout << "-E- receiving info buffer from server, rc = "
348  << ilen << endl;
349  iError = 1;
350  goto gEndGet;
351  }
352 
353  iHeadPar = ntohl(sInfo.iHeadPar);
354  iTimeOut = ntohl(sInfo.iTimeOut);
355  if (iDebug == 1)
356  {
357  cout << "-D- info buffer received:" << endl;
358  cout << " size data " << ntohl(sInfo.iSize)
359  << ", mode (1) " << ntohl(sInfo.iMode)
360  << ", header parms " << iHeadPar
361  << ", timeout " << iTimeOut << endl;
362  }
363 
364  if ( (ntohl(sInfo.iMode) != 1) ||
365  ( (int) ntohl(sInfo.iSize) != iInfoSize-iint) )
366  {
367  cout << "-E- invalid info buffer received: " << endl;
368  cout << " size data ( " << iInfoSize-iint
369  << ") " << ntohl(sInfo.iSize)
370  << ", mode (1) " << ntohl(sInfo.iMode)
371  << ", header parms " << iHeadPar
372  << ", timeout " << iTimeOut << endl;
373  iError = 1;
374  goto gEndGet;
375  }
376 
377  iEvtNo = 0; // initilization done
378  inew = 1; // request new buffer
379 
380  } // (iEvtNo == -1)
381  else
382  {
383  if (iFlush)
384  {
385  inew = 1; // request new buffer
386  if (iDebug == 1)
387  cout << "-D- skip current buffer" << endl;
388  }
389  else
390  {
391  if (iEvtNo >= 0)
392  {
393  // check if new buffer needed
394  if (iEvtRel >= iEvtBuf)
395  {
396  if (iDebug == 1)
397  cout << " request new buffer" << endl;
398  inew = 1;
399  }
400  else inew = 0;
401 
402  } // (iEvtNo > 0)
403  } // (!iFlush)
404  } // (iEvtNo != -1)
405 
406  // request new buffer
407  if (inew)
408  {
409 gRetryBuf:
410  iEvtRel = 0;
411  iRetry = 0;
412  iRetryFirst = 1;
413  if (imySig == -1)
414  sComm.iBufRequ = htonl(0); // signal finish to server
415 
416  // request next buffer or finish
417  ilen = pSocket->SendRaw(piComm, iCommSize, kDefault);
418  if (ilen < 0)
419  {
420  cout << "-E- sending request for buffer " << iBufNo+1
421  << " to server, rc = " << ilen << endl;
422  iError = 1;
423  goto gEndGet;
424  }
425 
426  if (imySig == -1) goto gEndGet;
427 
428  if (iDebug == 1)
429  cout << "-D- communication buffer sent (request next buffer) "
430  << endl;
431 
432 gRetryLen:
433  // get size of data following
434  piBuf[0] = -1; // enables receive check
435  iSize = iint;
436  pcBuf = (Char_t *) piBuf;
437  while(iSize > 0)
438  {
439  if ( (imySig == -1) && (iDebug) )
440  cout << " CTL C detected (before recv len)" << endl;
441 gNextRecvL:
442  iRC = recv(iSocket, pcBuf, iSize, 0);
443  if (iRC < 0)
444  {
445  if (imySig == -1)
446  {
447  if (iDebug)
448  {
449  sprintf(cMsg, "\n-E- receiving data length from server");
450  perror(cMsg);
451  cout << " CTL C detected (during recv len)" << endl;
452  }
453  goto gNextRecvL;
454  }
455  else
456  {
457  sprintf(cMsg, "\n-E- receiving data length from server");
458  perror(cMsg);
459  if (iDebug) cout << " retry" << endl;
460 
461  iRetryRecv++; // count no. of retries to limit them
462  if (iRetryRecv > iRetryRecvLim) // avoid infinite loop
463  {
464  iError = 1;
465  goto gEndGet;
466  }
467  else goto gNextRecvL;
468  }
469  }
470  if ( iRC == 0 )
471  {
472  if ( (iDebug == 2) || (iDebug == 3) )
473  cout << endl;
474  cout << "-E- receiving data length: connection closed by server"
475  << endl;
476  iError = 1;
477  goto gEndGet;
478  }
479 
480  iRetryRecv = 0;
481  iSize -= iRC;
482  pcBuf += iRC;
483 
484  } /* while(iSize > 0) */
485 
486  if (iDebug == 2)
487  {
488  printf("Rl:");
489  fflush(stdout);
490  }
491 
492  if ( (imySig == -1) && (iDebug) )
493  cout << " CTL C detected (after recv len)" << endl;
494 
495  iBufSize = ntohl(piBuf[0]);
496  if (iDebug == 1)
497  cout << " data size received: " << iBufSize << endl;
498 
499  if (iBufSize <= 0)
500  {
501  if (iBufSize == 0)
502  {
503  if (iDebug)
504  cout << endl;
505  cout << "-W- server closed connection" << endl;
506  cout << " " << iEvtNo << " of " << iEvtMax
507  << " events received" << endl;
508  iError = 1;
509  goto gEndGet;
510  }
511 
512  if (iBufSize == -1)
513  {
514  if (iRetryFirst)
515  {
516  cout << endl << "-E- no data length received: ";
517  iRetryFirst = 0;
518  }
519  iRetry++;
520  if (iRetry > iRetryMax)
521  {
522  cout << iRetryMax << "times" << endl;
523  iError = 1;
524  goto gEndGet;
525  }
526  goto gRetryLen;
527  }
528  else
529  {
530  cout << endl << "-E- invalid data length received: "
531  << iBufSize << endl;
532  iError = 1;
533  }
534 
535  goto gEndGet;
536  }
537  if (iRetry)
538  cout << iRetry << "times" << endl;
539 
540  // increase data buffer, if necessary
541  if (iBufSize+iint > iBufSizeAlloc)
542  {
543  delete [] piBuf;
544  iBufSizeAlloc = iBufSize+iint;
545  // new total buffer size (including length field)
546  piBuf = new Int_t [iBufSizeAlloc/iint];
547  piBuf[0] = iBufSize;
548  // keep sent buffer size (without length field)
549  if (iDebug == 1)
550  cout << "-I- total buffer increased to "
551  << iBufSizeAlloc << " bytes" << endl;
552  }
553 
554  // get event buffer without length field
555  piBuf[1] = -1; // enables receive check
556  iSize = iBufSize;
557  pcBuf = (Char_t *) &(piBuf[1]);
558  while(iSize > 0)
559  {
560  if ( (imySig == -1) && (iDebug) )
561  cout << " CTL C detected (before recv data)" << endl;
562 gNextRecvD:
563  iRC = recv(iSocket, pcBuf, iSize, 0);
564  if (iRC < 0)
565  {
566  if (imySig == -1)
567  {
568  if (iDebug)
569  {
570  sprintf(cMsg, "\n-E- receiving data from server");
571  perror(cMsg);
572  cout << " CTL C detected (during recv data)" << endl;
573  }
574  goto gNextRecvD;
575  }
576  else
577  {
578  sprintf(cMsg, "\n-E- receiving data from server");
579  perror(cMsg);
580 
581  iRetryRecv++; // count no. of retries to limit them
582  if (iRetryRecv > iRetryRecvLim) // avoid infinite loop
583  {
584  iError = 1;
585  goto gEndGet;
586  }
587  else goto gNextRecvD;
588  }
589  }
590  if ( iRC == 0 )
591  {
592  if ( (iDebug == 2) || (iDebug == 3) )
593  cout << endl;
594  cout << "-E- receiving data: connection closed by server"
595  << endl;
596  iError = 1;
597  goto gEndGet;
598  }
599 
600  iRetryRecv = 0;
601  iSize -= iRC;
602  pcBuf += iRC;
603 
604  } /* while(iSize > 0) */
605 
606  if (iDebug == 2)
607  {
608  printf("Rd:");
609  fflush(stdout);
610  }
611 
612  if (imySig == -1)
613  {
614  if (iDebug)
615  cout << " CTL C detected (after recv data)" << endl;
616  goto gEndGet;
617  }
618 
619  iBufNoServ = ntohl(piBuf[1]);
620  iEvtBuf = ntohl(piBuf[2]);
621  if (iEvtBuf == 0)
622  {
623  if (iDebug == 1)
624  printf(" dummy buffer no. %d, %d events\n",
625  iBufNoServ, iEvtBuf);
626  printf("*** connection to remote event server okay, but currently no DAQ events (%d)\n",
627  iBufNoServ);
628  goto gRetryBuf;
629  }
630 
631  if (!iSwap)
632  {
633  if ( (piBuf[3] < 1) || (piBuf[3] >= iBufSize) )
634  iSwap = 1; // DDD dirty fix! check piBuf[4] !
635  }
636 
637  // swap events in buffer (behind buffer header)
638  if (iSwap)
639  {
640  /*
641  * Hint: There are a lot of basically unnecessary type casts in
642  * this version of swaplw. One should clean it up.
643  */
644  swaplw( (Long_t*)(&piBuf[1+iHeadPar]), (iBufSize/iint)-iHeadPar, 0);
645  if ( (iBufNo == 0) && (iDebug) )
646  cout << " Event data swapped" << endl;
647  }
648 
649  iBufNo++;
650  if (iEvtNo == 0)
651  {
652  iBufNo = 1; // restart counting
653  iBufNo1 = iBufNoServ; // keep first buffer no.
654  }
655  iBufNo2 = iBufNoServ; // keep last buffer no.
656 
657  if (iDebug >= 2)
658  {
659  printf("%d:", iBufNoServ);
660  fflush(stdout);
661  }
662 
663  if (iDebug == 1)
664  {
665  cout << endl << "buffer " << iBufNo
666  << " (" << iBufNoServ << "): "
667  << " size "
668  << iBufSize << " byte" << endl;
669  }
670 
671  iEvtRel = 1; // first event in buffer
672  piNextEvt = piBuf + iHeadPar+1; // ptr first element in buffer
673 
674  } // new buffer
675  else
676  {
677  iEvtRel++;
678  piNextEvt += iEvtPar; // skip previous event
679  //printf("DDD new event length: %d\n", *piNextEvt);
680 
681  // first event after reopen existing connection, no new buffer
682  if (iEvtNo == 0)
683  {
684  iBufNo = 1; // restart counting
685  iBufNoServ = ntohl(piBuf[1]);
686  iBufNo1 = iBufNoServ;
687 
688  } // (iEvtNo == 0)
689  } // continue with current buffer
690 
691  iEvtNo++; // total event no.
692  ibyte = (piNextEvt[0]/8)*8;
693  if ( ibyte < piNextEvt[0] ) ibyte += 8;
694  iEvtPar = ibyte/iint; // no. of parameters with padding
695 
696  if (iDebug == 1)
697  {
698  cout << " event no. " << iEvtNo << " (" << piNextEvt[3]
699  << "): id " << piNextEvt[2] << ", size " << piNextEvt[0]
700  << endl;
701 
702  ii = 0;
703  indSize[ii] = 0; // index event length
704 
705  irem = piNextEvt[0] - 32; // remaining bytes for subevents
706  while ( (irem > 0) && (ii < imaxSE) )
707  {
708  ii++; // count subevents
709  if (ii == 1) ioff = 8; // skip event header
710  else ioff += ibyte/iint;
711  indSize[ii] = ioff; // buffer index of length current subevent
712 
713  ibyte = (piNextEvt[ioff]/8)*8;
714  if ( ibyte < piNextEvt[ioff] )
715  ibyte += 8; // padded subevent size
716 
717  if (irem <= piNextEvt[ioff]) // last subevent
718  irem -= piNextEvt[ioff];
719  else irem -= ibyte;
720 
721  cout << " subevent " << ii << ": size "
722  << piNextEvt[ioff];
723  if (irem <= 0) cout << endl;
724  else cout << ", padded " << ibyte
725  << ", remainder " << irem << endl;
726 
727  if (ii == imaxSE-1)
728  cout << "-W- only " << ii << " subevents tested" << endl;
729 
730  } // while (irem)
731 
732  if (iDebug == 2) for (jj=1; jj<=ii; jj++)
733  {
734  ind = indSize[jj];
735  cout << " subevent " << jj << ": size " << piNextEvt[ind]
736  << " (index " << ind << ")" << endl;
737  }
738  } // (iDebug == 1)
739 
740  if (imySig == -1)
741  {
742  cout << endl << "-D- CTL C specified";
743  if (iDebug) cout << " (at end RevGet)" << endl;
744  else cout << endl;
745  goto gEndGet;
746  }
747 
748  if (iEvtNo == iEvtMax)
749  {
750  cout << endl << "-I- all required events ("
751  << iEvtMax << ") received: " << iBufNo << " buffers ("
752  << iBufNo1 << " - " << iBufNo2 << ")" << endl;
753  }
754 
755  return( (UInt_t *) piNextEvt);
756 
757 gEndGet:
758  if ( (iError) || (imySig == -1) )
759  {
760  if (iDebug)
761  cout << " RevGet: closing connection to server";
762  iRC = rclose(&iSocket, 2);
763  if ( (iDebug) && (iRC == 0) )
764  cout << " - done" << endl;
765  imySig = 0; // notify CTL C handler
766  }
767  else if (iDebug)
768  cout << " RevGet: keeping connection to server" << endl;
769 
770  return 0 ;
771 
772 } // RevGet
773 
774 
775 
777 {
778  return iBufSize;
779 } // RevBufsize
780 
781 
782 
783 void HRevBuffer::RevBufWait( Int_t iWait )
784 {
785  if (iWait > 0) sleep(iWait);
786 } // RevBufWait
787 
788 
789 
790 void HRevBuffer::RevClose( TSocket *pSocket )
791 {
792  Int_t iRC;
793  Int_t *piComm;
794  srevComm sComm;
795  Int_t iCommSize = sizeof(sComm); // size comm. buffer (byte)
796 
797  if (imySig < 0) return; // CTL Y: connection closed elsewhere
798  if (iSocket == 0) return;
799 
800  // tell server that no more events needed
801  piComm = &(sComm.iSize); // communication buffer
802  sComm.iSize = htonl(iCommSize-sizeof(int));// size of data following
803  sComm.iMode = htonl(1); // required
804  sComm.iIdent = 1; // required: tell endian type
805  sComm.iBufRequ = htonl(0); // no more event buffers
806 
807  if (iDebug == 1)
808  cout << "-D- send communication buffer (close request, size data "
809  << ntohl(sComm.iSize) << " byte): "
810  << ntohl(sComm.iMode) << ", "
811  << ntohl(sComm.iBufRequ) << endl;
812 
813  iRC = pSocket->SendRaw(piComm, iCommSize, kDefault);
814  if (iRC < 0)
815  cout << "-E- sending close request to server, rc = "
816  << iRC << endl;
817  else if (iDebug == 1)
818  cout << " close request sent" << endl;
819 
820  if (iDebug)
821  cout << " RevClose: closing connection to server";
822  iRC = rclose(&iSocket, 2);
823  if ( (iDebug) && (iRC == 0) )
824  cout << " - done" << endl;
825 
826  imySig = 0; // notify CTL C handler
827  cout << "-I- connection to server closed" << endl;
828 
829 } // RevClose
Int_t iMode
Definition: hrevbuffer.cc:49
Int_t iOutMode
Definition: hrevbuffer.cc:34
TSocket * RevOpen(const Char_t *pNode, Int_t iPort, Int_t iEvent)
Definition: hrevbuffer.cc:238
Int_t imySig
Definition: hrevbuffer.cc:33
Int_t iEvtNo
Definition: hrevbuffer.cc:60
Int_t iIdent
Definition: hrevbuffer.cc:41
Int_t iSize
Definition: hrevbuffer.cc:39
static Int_t rclose(Int_t *piSocket, Int_t iMode)
Definition: hrevbuffer.cc:87
Int_t iMode
Definition: hrevbuffer.cc:40
Int_t RevBufsize()
Definition: hrevbuffer.cc:776
Int_t iHeadPar
Definition: hrevbuffer.cc:51
void RevClose(TSocket *pSocket)
Definition: hrevbuffer.cc:790
HRevBuffer(Int_t iMode)
Definition: hrevbuffer.cc:199
Int_t iTimeOut
Definition: hrevbuffer.cc:52
ClassImp(HRevBuffer) Int_t iTimeOut
static Long_t swaplw(Long_t *pp_source, Long_t l_len, Long_t *pp_dest)
Definition: hrevbuffer.cc:154
void RevBufWait(Int_t iWait)
Definition: hrevbuffer.cc:783
Int_t iBufRequ
Definition: hrevbuffer.cc:42
static void exitCli(Int_t signal)
Definition: hrevbuffer.cc:64
UInt_t * RevGet(TSocket *pSocket, Int_t iFlush)
Definition: hrevbuffer.cc:283
Int_t iBufNo
Definition: hrevbuffer.cc:59
Int_t iSize
Definition: hrevbuffer.cc:48
Int_t iSize
Definition: hrevbuffer.cc:58