Belle II Software  release-05-01-25
sm_server.cc
1 //+
2 // Test server function using SocketManager class
3 //-
4 
5 #include <daq/dataflow/SocketLib.h>
6 #include <daq/dataflow/SocketManager.h>
7 
8 #include <cstdio>
9 #include <cstdlib>
10 #include <unistd.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 int main(int argc, char** argv)
16 {
17  // Open socket to accept connection
18  SocketRecv recsock((unsigned short)(atoi(argv[1])));
19 
20  // Register it in SocketManager
21  SocketManager sockman(recsock.sock());
22 
23  // Loop forever
24  int count = 0;
25  for (;;) {
26  // Check I/O request
27  int is = sockman.examine();
28  if (is == 0) {
29  printf("New connection made\n");
30  } else if (is == 1) {
31  int datbuf;
32  vector<int>& socklist = sockman.connected_socket_list();
33  printf("no. of connected sockets = %d\n", socklist.size());
34  for (vector<int>::iterator it = socklist.begin(); it != socklist.end(); ++it) {
35  int fd = *it;
36  int is = read(fd, &datbuf, 4);
37  printf("Data read from sock %d (%d), ret = %d\n", fd, count++, is);
38  }
39  }
40  }
41 }
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SocketManager
Definition: SocketManager.h:20
Belle2::SocketRecv
Definition: SocketLib.h:48