Belle II Software development
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
16using namespace std;
17using namespace Belle2;
18
19int main(int argc, char** argv)
20{
21 if (argc < 2) {
22 printf("Wrong number of arguments\n");
23 return 1;
24 }
25
26 // Open socket to accept connection
27 SocketRecv recsock((unsigned short)(atoi(argv[1])));
28
29 // Register it in SocketManager
30 SocketManager sockman(recsock.sock());
31
32 // Loop forever
33 int count = 0;
34 for (;;) {
35 // Check I/O request
36 int is = sockman.examine();
37 if (is == 0) {
38 printf("New connection made\n");
39 } else if (is == 1) {
40 int datbuf;
41 vector<int>& socklist = sockman.connected_socket_list();
42 printf("no. of connected sockets = %zu\n", socklist.size());
43 for (vector<int>::iterator it = socklist.begin(); it != socklist.end(); ++it) {
44 int fd = *it;
45 int isNow = read(fd, &datbuf, 4);
46 printf("Data read from sock %d (%d), ret = %d\n", fd, count++, isNow);
47 }
48 }
49 }
50 return 0;
51}
Abstract base class for different kinds of events.
STL namespace.