#include <iostream.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <signal.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <errno.h>
extern int errno;
#include "TFndGebSpy.h"
ClassImp(TFndGebSpy);
//////////////////////////////////////////////////////////////////////
TFndGebSpy::TFndGebSpy() {
struct sockaddr_in MyAdd;
bzero((char*)&MyAdd,sizeof(MyAdd));
MyAdd.sin_family = AF_INET;
MyAdd.sin_addr.s_addr = INADDR_ANY;
MyAdd.sin_port = 0;
fUdpSd = socket(AF_INET, SOCK_DGRAM, 0);
bind(fUdpSd, (struct sockaddr *) &MyAdd, sizeof(MyAdd));
Int_t one=1;
ioctl(fUdpSd,FIONBIO,&one);
}
TFndGebSpy::~TFndGebSpy() {
Int_t iok = shutdown(fUdpSd,2);
// cout << "iok " << iok << endl;
}
//////////////////////////////////////////////////////////////////////
Int_t *TFndGebSpy::Get(Int_t p) {
struct sockaddr_in GebAdd;
bzero((char*)&GebAdd,sizeof(GebAdd));
GebAdd.sin_family = AF_INET;
GebAdd.sin_addr.s_addr = htonl(GEBIP);
GebAdd.sin_port = htons(p);
Int_t m = 0;
struct sockaddr *Add = (struct sockaddr *) &GebAdd;
UInt_t k = sizeof(GebAdd);
// cout << "send request to geb" << endl;
sendto(fUdpSd,(char*)&m ,sizeof(m) ,0 ,Add ,k);
Int_t i = -1;
for(Int_t j=0; j<1000;j++) {
// while(i == -1) {
// gSystem->Exec("usleep 200");
usleep(2000);
i = recvfrom(fUdpSd ,(char*)fEvent ,sizeof(fEvent) ,0 ,Add , &k);
if((i == -1) && (errno != 11))
cout << "errno = " << errno << endl;
if(i != -1) {
cout << "end of for cycle: j: " << j;
break;
}
}
cout << " i: " << i << endl;
if(i == -1) return NULL;
fEvent[0] = htonl(fEvent[0]);
for (Int_t n=1;n<fEvent[0];n++) fEvent[n] = htonl(fEvent[n]);
Int_t len = fEvent[0];
if(len > 1 && p>=2001 && p<=2006) {
// for(Int_t i=0; i<fEvent[0]; i++) cout << "fEvent[" << i << "] = " << fEvent[i] << endl;
while(len) {
len--;
fEvent[len+16] = fEvent[len];
}
fEvent[0] += 16;
BuildHeader(p);
//for(Int_t i=0; i<fEvent[0]; i++) cout << "fEvent[" << i << "] = " << fEvent[i] << endl;
}
return fEvent;
}
//////////////////////////////////////////////////////////////////////
void TFndGebSpy::BuildHeader(Int_t p) {
for(Int_t i=1; i<16; i++) fEvent[i] = 0;
fEvent[p-1994] = 16;
}
//////////////////////////////////////////////////////////////////////
void TFndGebSpy::Dump() {
Int_t *p = fEvent;
Int_t np = p[0];
for (Int_t k=0; k<np/4; k++,p+=4) {
Int_t j;
for (j=0;j<4;j++) printf("%8X ",p[j]);
for (j=0;j<4;j++) {
printf(" ");
for (Int_t i=3;i>=0;i--) {
UChar_t c = (p[j]>>(i<<3)) & 0xFF;
printf("%1c",(c>=0x20 && c<0x70)? c:'.');
}
}
printf("n");
}
if (np%4 >= 1) { printf("%8X ",p[1]);
if (np%4 >= 2) { printf("%8X ",p[2]);
if (np%4 >= 3) printf("%8X ",p[3]);
else printf(" ");
} else printf(" ");
} else printf(" ");
printf("n");
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.