Belle II Software  release-06-02-00
sm_server.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <daq/dataflow/SocketLib.h>
10 #include <daq/dataflow/SocketManager.h>
11 
12 #include <cstdio>
13 #include <cstdlib>
14 #include <unistd.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 int main(int argc, char** argv)
20 {
21  // Open socket to accept connection
22  SocketRecv recsock((unsigned short)(atoi(argv[1])));
23 
24  // Register it in SocketManager
25  SocketManager sockman(recsock.sock());
26 
27  // Loop forever
28  int count = 0;
29  for (;;) {
30  // Check I/O request
31  int is = sockman.examine();
32  if (is == 0) {
33  printf("New connection made\n");
34  } else if (is == 1) {
35  int datbuf;
36  vector<int>& socklist = sockman.connected_socket_list();
37  printf("no. of connected sockets = %d\n", socklist.size());
38  for (vector<int>::iterator it = socklist.begin(); it != socklist.end(); ++it) {
39  int fd = *it;
40  int is = read(fd, &datbuf, 4);
41  printf("Data read from sock %d (%d), ret = %d\n", fd, count++, is);
42  }
43  }
44  }
45 }
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75