Belle II Software development
IOInfo Class Reference

Public Member Functions

const char * getLocalIP () const
 
unsigned int getLocalAddress () const
 
int getLocalPort () const
 
const char * getRemoteIP () const
 
unsigned int getRemoteAddress () const
 
int getRemotePort () const
 
int getState () const
 
int getTXQueue () const
 
int getRXQueue () const
 
void setLocalAddress (unsigned int addr)
 
void setLocalPort (int port)
 
void setRemoteAddress (unsigned int addr)
 
void setRemotePort (int port)
 
void setState (int state)
 
void setTXQueue (int queue)
 
void setRXQueue (int queue)
 

Static Public Member Functions

static int checkTCP (std::vector< IOInfo > &info)
 
static int checkTCP (IOInfo &info)
 

Private Attributes

unsigned int m_local_addr
 
int m_local_port
 
unsigned int m_remote_addr
 
int m_remote_port
 
int m_state
 
int m_tx_queue
 
int m_rx_queue
 

Detailed Description

Definition at line 19 of file IOInfo.h.

Constructor & Destructor Documentation

◆ IOInfo()

IOInfo ( )
inline

Definition at line 25 of file IOInfo.h.

25{}

◆ ~IOInfo()

~IOInfo ( )
inline

Definition at line 26 of file IOInfo.h.

26{}

Member Function Documentation

◆ checkTCP() [1/2]

int checkTCP ( IOInfo info)
static

Definition at line 19 of file IOInfo.cc.

20{
21 std::vector<IOInfo> info_v;
22 info_v.push_back(info);
23 int ret = checkTCP(info_v);
24 info = info_v[0];
25 return ret;
26}

◆ checkTCP() [2/2]

int checkTCP ( std::vector< IOInfo > &  info)
static

Definition at line 28 of file IOInfo.cc.

29{
30 size_t count = 0;
31 for (size_t i = 0; i < info.size(); i++) {
32 info[i].setState(0);
33 info[i].setTXQueue(0);
34 info[i].setRXQueue(0);
35 }
36 count = 0;
37 std::string line;
38 std::stringstream ss;
39 std::string sl, local_address, rem_address, st, queue;
40 std::ifstream fin("/proc/net/tcp");
41 getline(fin, line);
42 while (fin && getline(fin, line)) {
43 ss.str("");
44 ss << line;
45 ss >> sl >> local_address >> rem_address >> st >> queue;
46 unsigned int addr = strtoul(local_address.substr(0, 8).c_str(), NULL, 16);
47 int port = strtoul(local_address.substr(9).c_str(), NULL, 16);
48 unsigned int raddr = strtoul(rem_address.substr(0, 8).c_str(), NULL, 16);
49 int rport = strtoul(rem_address.substr(9).c_str(), NULL, 16);
50 for (size_t i = 0; i < info.size(); i++) {
51 if (info[i].getState() > 0) continue;
52 int sti = strtoul(st.c_str(), NULL, 16);
53 if (//addr == info[i].getLocalAddress() &&
54 port == info[i].getLocalPort() && sti == 1) {
55 info[i].setRemoteAddress(raddr);
56 info[i].setRemotePort(rport);
57 info[i].setState(sti);
58 info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
59 info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
60 count++;
61 } else if (raddr == info[i].getRemoteAddress() &&
62 rport == info[i].getRemotePort() && sti == 1) {
63 info[i].setLocalAddress(addr);
64 info[i].setLocalPort(port);
65 info[i].setState(sti);
66 info[i].setTXQueue(strtoul(queue.substr(0, 8).c_str(), NULL, 16));
67 info[i].setRXQueue(strtoul(queue.substr(9).c_str(), NULL, 16));
68 count++;
69 }
70 if (count == info.size()) return count;
71 }
72 }
73 return count;
74}

◆ getLocalAddress()

unsigned int getLocalAddress ( ) const
inline

Definition at line 30 of file IOInfo.h.

30{ return m_local_addr; }

◆ getLocalIP()

const char * getLocalIP ( ) const

Definition at line 76 of file IOInfo.cc.

77{
78 sockaddr_in addr;
79 addr.sin_addr.s_addr = m_local_addr;
80 return inet_ntoa(addr.sin_addr);
81}

◆ getLocalPort()

int getLocalPort ( ) const
inline

Definition at line 31 of file IOInfo.h.

31{ return m_local_port; }

◆ getRemoteAddress()

unsigned int getRemoteAddress ( ) const
inline

Definition at line 33 of file IOInfo.h.

33{ return m_remote_addr; }

◆ getRemoteIP()

const char * getRemoteIP ( ) const

Definition at line 83 of file IOInfo.cc.

84{
85 sockaddr_in addr;
86 addr.sin_addr.s_addr = m_remote_addr;
87 return inet_ntoa(addr.sin_addr);
88}

◆ getRemotePort()

int getRemotePort ( ) const
inline

Definition at line 34 of file IOInfo.h.

34{ return m_remote_port; }

◆ getRXQueue()

int getRXQueue ( ) const
inline

Definition at line 37 of file IOInfo.h.

37{ return m_rx_queue; }

◆ getState()

int getState ( ) const
inline

Definition at line 35 of file IOInfo.h.

35{ return m_state; }

◆ getTXQueue()

int getTXQueue ( ) const
inline

Definition at line 36 of file IOInfo.h.

36{ return m_tx_queue; }

◆ setLocalAddress()

void setLocalAddress ( unsigned int  addr)
inline

Definition at line 38 of file IOInfo.h.

38{ m_local_addr = addr; }

◆ setLocalPort()

void setLocalPort ( int  port)
inline

Definition at line 39 of file IOInfo.h.

39{ m_local_port = port; }

◆ setRemoteAddress()

void setRemoteAddress ( unsigned int  addr)
inline

Definition at line 40 of file IOInfo.h.

40{ m_remote_addr = addr; }

◆ setRemotePort()

void setRemotePort ( int  port)
inline

Definition at line 41 of file IOInfo.h.

41{ m_remote_port = port; }

◆ setRXQueue()

void setRXQueue ( int  queue)
inline

Definition at line 44 of file IOInfo.h.

44{ m_rx_queue = queue; }

◆ setState()

void setState ( int  state)
inline

Definition at line 42 of file IOInfo.h.

42{ m_state = state; }

◆ setTXQueue()

void setTXQueue ( int  queue)
inline

Definition at line 43 of file IOInfo.h.

43{ m_tx_queue = queue; }

Member Data Documentation

◆ m_local_addr

unsigned int m_local_addr
private

Definition at line 47 of file IOInfo.h.

◆ m_local_port

int m_local_port
private

Definition at line 48 of file IOInfo.h.

◆ m_remote_addr

unsigned int m_remote_addr
private

Definition at line 49 of file IOInfo.h.

◆ m_remote_port

int m_remote_port
private

Definition at line 50 of file IOInfo.h.

◆ m_rx_queue

int m_rx_queue
private

Definition at line 53 of file IOInfo.h.

◆ m_state

int m_state
private

Definition at line 51 of file IOInfo.h.

◆ m_tx_queue

int m_tx_queue
private

Definition at line 52 of file IOInfo.h.


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