MCPcopy Create free account
hub / github.com/ARM-software/armnn / ReadPacket

Method ReadPacket

profiling/client/src/SocketProfilingConnection.cpp:103–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103arm::pipe::Packet SocketProfilingConnection::ReadPacket(uint32_t timeout)
104{
105#if !defined(ARMNN_DISABLE_SOCKETS)
106 // Is there currently at least a header worth of data waiting to be read?
107 int bytes_available = 0;
108 arm::pipe::Ioctl(m_Socket[0].fd, FIONREAD, &bytes_available);
109 if (bytes_available >= 8)
110 {
111 // Yes there is. Read it:
112 return ReceivePacket();
113 }
114
115 // Poll for data on the socket or until timeout occurs
116 int pollResult = arm::pipe::Poll(&m_Socket[0], 1, static_cast<int>(timeout));
117
118 switch (pollResult)
119 {
120 case -1: // Error
121 throw arm::pipe::SocketConnectionException(
122 std::string("SocketProfilingConnection: Error occured while reading from socket: ") + strerror(errno),
123 m_Socket[0].fd,
124 errno);
125
126 case 0: // Timeout
127 throw arm::pipe::TimeoutException("SocketProfilingConnection: Timeout while reading from socket");
128
129 default: // Normal poll return but it could still contain an error signal
130 // Check if the socket reported an error
131 if (m_Socket[0].revents & (POLLNVAL | POLLERR | POLLHUP))
132 {
133 if (m_Socket[0].revents == POLLNVAL)
134 {
135 // This is an unrecoverable error.
136 Close();
137 throw arm::pipe::SocketConnectionException(
138 std::string("SocketProfilingConnection: Error occured while polling receiving socket: POLLNVAL."),
139 m_Socket[0].fd);
140 }
141 if (m_Socket[0].revents == POLLERR)
142 {
143 throw arm::pipe::SocketConnectionException(
144 std::string(
145 "SocketProfilingConnection: Error occured while polling receiving socket: POLLERR: ")
146 + strerror(errno),
147 m_Socket[0].fd,
148 errno);
149 }
150 if (m_Socket[0].revents == POLLHUP)
151 {
152 // This is an unrecoverable error.
153 Close();
154 throw arm::pipe::SocketConnectionException(
155 std::string("SocketProfilingConnection: Connection closed by remote client: POLLHUP."),
156 m_Socket[0].fd);
157 }
158 }
159
160 // Check if there is data to read

Callers 2

HandleCommandsMethod · 0.45

Calls 6

IoctlFunction · 0.85
ReceivePacketFunction · 0.85
PollFunction · 0.85
CloseFunction · 0.85
TimeoutExceptionClass · 0.50
IgnoreUnusedFunction · 0.50

Tested by

no test coverage detected