3 #define coutfl cout << __FILE__<< " " << __LINE__ << " "
4 #define cerrfl cerr << __FILE__<< " " << __LINE__ << " "
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <arpa/inet.h>
14 #include <netinet/in.h>
38 #define RCDAQEVENTITERATOR 1
39 #define FILEEVENTITERATOR 2
40 #define TESTEVENTITERATOR 3
41 #define ONCSEVENTITERATOR 4
45 cout <<
"** usage: gl1_server -nifTrOvh datastream" << std::endl;
46 cout <<
" type gl1_server -h for more help" << std::endl;
54 cout <<
" gl1_server serves events from a given datastream" << std::endl;
56 cout <<
" List of options: " << std::endl;
57 cout <<
" -d <number> depth of buffer" << std::endl;
58 cout <<
" -f (stream is a file)" << std::endl;
59 cout <<
" -T (stream is a test stream)" << std::endl;
60 cout <<
" -r (stream is a rcdaq monitoring stream)" << std::endl;
61 cout <<
" -O (stream is a legacy ONCS format file)" << std::endl;
62 cout <<
" -h this message" << std::endl;
64 cout <<
" debug options" << endl;
65 cout <<
" -s <number> sleep so many ticks (in units of usleep)" << std::endl;
66 cout <<
" -i <print event identity>" << std::endl;
67 cout <<
" -v verbose" << std::endl;
99 pthread_mutex_lock( &
MapSem);
100 map<int, Event*>::iterator
it =
EventMap.begin();
116 map<int, Event*>::iterator it =
EventMap.begin();
126 pthread_mutex_unlock( &
MapSem);
150 pthread_mutex_init( &
MapSem, 0);
152 while ((c = getopt(argc, argv,
"d:s:ifTrOvh")) != EOF)
199 if ( getenv(
"RCDAQHOST") )
201 host = getenv(
"RCDAQHOST");
240 cout <<
"Could not open input stream" << std::endl;
247 status = pthread_create(&ThreadEvt, NULL,
253 cout <<
"error in event thread create " << status << endl;
259 struct sockaddr_in servaddr, cliaddr;
262 if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 )
264 perror(
"socket creation failed");
268 memset(&servaddr, 0,
sizeof(servaddr));
269 memset(&cliaddr, 0,
sizeof(cliaddr));
272 servaddr.sin_family = AF_INET;
273 servaddr.sin_addr.s_addr = INADDR_ANY;
274 servaddr.sin_port = htons(
PORT);
277 if ( bind(sockfd, (
const struct sockaddr *)&servaddr,
278 sizeof(servaddr)) < 0 )
280 perror(
"bind failed");
287 len =
sizeof(cliaddr);
293 n = recvfrom(sockfd, (
char *)recbuffer, 2*
sizeof(
int),
294 MSG_WAITALL, (
struct sockaddr *) &cliaddr,
298 cout <<
"request from " << inet_ntoa(cliaddr.sin_addr) <<
" requesting " << recbuffer[0] << endl;
301 pthread_mutex_lock( &
MapSem);
303 map<int, Event*>::iterator
it =
EventMap.find(recbuffer[0]);
306 pthread_mutex_unlock( &
MapSem);
309 sendto(sockfd, (
const char *) buffer,
sizeof(
int),
310 MSG_CONFIRM, (
const struct sockaddr *) &cliaddr,
316 (it->second)->Copy(buffer,
MAXSIZE,&nw,
"");
317 pthread_mutex_unlock( &
MapSem);
318 sendto(sockfd, (
const char *) buffer, nw*
sizeof(
int),
319 MSG_CONFIRM, (
const struct sockaddr *) &cliaddr,