Belle II Software development
EventServer Class Reference

Public Member Functions

 EventServer (std::string rbufname, int port)
 
int server ()
 

Private Attributes

EvtSocketRecvm_sock
 
EvtSocketManagerm_man
 
RingBufferm_rbuf
 
int m_port
 
int m_force_exit
 

Detailed Description

Definition at line 25 of file EventServer.h.

Constructor & Destructor Documentation

◆ EventServer()

EventServer ( std::string  rbufname,
int  port 
)

Definition at line 17 of file EventServer.cc.

17 : m_port(port)
18{
19 // Attach to RingBuffer
20 m_rbuf = new RingBuffer(rbufname.c_str());
21
22 // Open EvtSocket
23 m_sock = new EvtSocketRecv(m_port, false);
24 m_man = new EvtSocketManager(m_sock);
25}
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39

◆ ~EventServer()

Definition at line 27 of file EventServer.cc.

28{
29 delete m_rbuf;
30 delete m_sock;
31 delete m_man;
32}

Member Function Documentation

◆ server()

int server ( )

Definition at line 34 of file EventServer.cc.

35{
36 SocketIO sio;
37 MsgHandler msghdl(0);
38 char* evtbuffer = new char[MAXEVTSIZE];
39
40 // vector<int> recvsock;
41 int loop_counter [[maybe_unused]] = 0;
42 while (m_force_exit == 0) {
43 // Pick up a event from RingBuffer (non blocking)
44 int size = m_rbuf->remq((int*)evtbuffer);
45 // if ( size > 0 )
46 // printf ( "From RB : event size = %d\n", size );
47
48 // Check connection request
49 int exam_stat = m_man->examine();
50 // printf("Examine: exam_stat = %d\n", exam_stat);
51 if (exam_stat == 0) {
52 printf("Initial connection request detected!\n");
53 // int fd = recvsock[;
54 } else if (exam_stat == 1 && size > 0) { //
55 // printf ( "Event data data ready on socket\n" );
56 vector<int>& recvsock = m_man->connected_socket_list();
57 // printf ( "size of recvsock = %d\n", recvsock.size() );
58 for (vector<int>::iterator it = recvsock.begin();
59 it != recvsock.end(); ++it) {
60 int fd = *it;
61 if (m_man->connected(fd, true)) {
62 int is = sio.put(fd, evtbuffer, size * 4);
63 // printf ( "data put on socket : %d\n", is );
64 if (is <= 0) {
65 printf("EventServer: fd %d disconnected\n", fd);
66 m_man->remove(fd);
67 break;
68 }
69 }
70 }
71 }
72 usleep(1000);
73 loop_counter++;
74 }
75 return 0;
76}
A class to encode/decode an EvtMessage.
Definition: MsgHandler.h:103
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308

Member Data Documentation

◆ m_force_exit

int m_force_exit
private

Definition at line 37 of file EventServer.h.

◆ m_man

EvtSocketManager* m_man
private

Definition at line 34 of file EventServer.h.

◆ m_port

int m_port
private

Definition at line 36 of file EventServer.h.

◆ m_rbuf

RingBuffer* m_rbuf
private

Definition at line 35 of file EventServer.h.

◆ m_sock

EvtSocketRecv* m_sock
private

Definition at line 33 of file EventServer.h.


The documentation for this class was generated from the following files: