Belle II Software development
EvtSocketManager Class Reference

Public Member Functions

 EvtSocketManager (EvtSocketRecv *sock)
 
int examine ()
 
std::vector< int > & connected_socket_list ()
 
bool connected (int fd, bool wreq=false)
 
bool remove (int fd)
 

Private Attributes

int m_maxfd
 
std::vector< int > m_fd
 
EvtSocketRecvm_recv
 
int m_sock
 
fd_set m_rset
 
fd_set m_wset
 
fd_set m_allset
 

Detailed Description

Definition at line 21 of file EvtSocketManager.h.

Constructor & Destructor Documentation

◆ EvtSocketManager()

Definition at line 18 of file EvtSocketManager.cc.

19{
20 SocketRecv* sock = evtsock->sock();
21
22 FD_ZERO(&m_allset);
23 FD_SET(sock->sock(), &m_allset);
24 m_maxfd = sock->sock();
25 m_recv = evtsock;
26 m_sock = sock->sock();
27}

◆ ~EvtSocketManager()

Definition at line 29 of file EvtSocketManager.cc.

30{
31}

Member Function Documentation

◆ connected()

bool connected ( int  fd,
bool  wreq = false 
)

Definition at line 74 of file EvtSocketManager.cc.

75{
76 if (!wreq) {
77 if (FD_ISSET(fd, &m_rset))
78 return true;
79 else
80 return false;
81 } else {
82 if (FD_ISSET(fd, &m_wset))
83 return true;
84 else
85 return false;
86 }
87}

◆ connected_socket_list()

vector< int > & connected_socket_list ( )

Definition at line 69 of file EvtSocketManager.cc.

70{
71 return m_fd;
72}

◆ examine()

int examine ( )

Definition at line 33 of file EvtSocketManager.cc.

34{
35 memcpy(&m_rset, &m_allset, sizeof(m_rset));
36 memcpy(&m_wset, &m_allset, sizeof(m_wset));
37 struct timeval timeout;
38 timeout.tv_sec = 0; // 1sec
39 timeout.tv_usec = 1000; // 1msec (in microsec)
40 // printf ( "EvtSocketManager: maxfd = %d, start select...\n", m_maxfd);
41 // int rc = select(m_maxfd+1, &m_rset, &m_wset, NULL, NULL );
42 int rc = select(m_maxfd + 1, &m_rset, &m_wset, NULL, &timeout);
43 // printf ( "EvtSocketManager: select returned with %d\n", rc );
44 if (rc < 0)
45 perror("select");
46 else if (rc == 0) // timeout
47 return -1;
48
49 if (FD_ISSET(m_sock, &m_rset)) { // New connection request
50 int fd = (m_recv->sock())->accept();
51 m_fd.push_back(fd);
52 FD_SET(fd, &m_allset);
53 if (fd > m_maxfd) m_maxfd = fd;
54 /*
55 struct sockaddr_in peername;
56 socklen_t lname = sizeof (peername);
57 int is = getpeername ( fd[0], (sockaddr*)&peername, &lname );
58 struct hostent* dest = gethostbyaddr (
59 (char*)&peername.sin_addr.s_addr, sizeof(unsigned int),AF_INET );
60 tprintf ( "DQM_server : connected to host = %s (port %d); fd=%d\n",
61 dest->h_name, ntohs(peername.sin_port), fd[0] );
62 */
63 return 0;
64 } else { //
65 return 1;
66 }
67}

◆ remove()

bool remove ( int  fd)

Definition at line 89 of file EvtSocketManager.cc.

90{
91 FD_CLR(fd, &m_allset);
92 shutdown(fd, SHUT_RDWR);
93 close(fd);
94 vector<int>::iterator pos = find(m_fd.begin(), m_fd.end(), fd);
95 if (pos != m_fd.end()) {
96 m_fd.erase(pos);
97 return true;
98 } else
99 return false;
100}

Member Data Documentation

◆ m_allset

fd_set m_allset
private

Definition at line 42 of file EvtSocketManager.h.

◆ m_fd

std::vector<int> m_fd
private

Definition at line 36 of file EvtSocketManager.h.

◆ m_maxfd

int m_maxfd
private

Definition at line 35 of file EvtSocketManager.h.

◆ m_recv

EvtSocketRecv* m_recv
private

Definition at line 38 of file EvtSocketManager.h.

◆ m_rset

fd_set m_rset
private

Definition at line 40 of file EvtSocketManager.h.

◆ m_sock

int m_sock
private

Definition at line 39 of file EvtSocketManager.h.

◆ m_wset

fd_set m_wset
private

Definition at line 41 of file EvtSocketManager.h.


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