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

Method WaitForPacket

profiling/server/src/basePipeServer/BasePipeServer.cpp:111–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111arm::pipe::Packet BasePipeServer::WaitForPacket(uint32_t timeoutMs)
112{
113 // Is there currently more than a headers worth of data waiting to be read?
114 int bytes_available;
115 arm::pipe::Ioctl(m_ClientConnection, FIONREAD, &bytes_available);
116 if (bytes_available > 8)
117 {
118 // Yes there is. Read it:
119 return ReceivePacket();
120 }
121 else
122 {
123 // No there's not. Poll for more data.
124 struct pollfd pollingFd[1]{};
125 pollingFd[0].fd = m_ClientConnection;
126 int pollResult = arm::pipe::Poll(pollingFd, 1, static_cast<int>(timeoutMs));
127
128 switch (pollResult)
129 {
130 // Error
131 case -1:
132 throw ProfilingException(std::string("File descriptor reported an error during polling: ") +
133 strerror(errno));
134
135 // Timeout
136 case 0:
137 throw arm::pipe::TimeoutException("Timeout while waiting to receive packet.");
138
139 // Normal poll return. It could still contain an error signal
140 default:
141 // Check if the socket reported an error
142 if (pollingFd[0].revents & (POLLNVAL | POLLERR | POLLHUP))
143 {
144 if (pollingFd[0].revents == POLLNVAL)
145 {
146 throw arm::pipe::ProfilingException(
147 std::string("Error while polling receiving socket: POLLNVAL"));
148 }
149 if (pollingFd[0].revents == POLLERR)
150 {
151 throw arm::pipe::ProfilingException(
152 std::string("Error while polling receiving socket: POLLERR: ") + strerror(errno));
153 }
154 if (pollingFd[0].revents == POLLHUP)
155 {
156 throw arm::pipe::ProfilingException(
157 std::string("Connection closed by remote client: POLLHUP"));
158 }
159 }
160
161 // Check if there is data to read
162 if (!(pollingFd[0].revents & (POLLIN)))
163 {
164 // This is a corner case. The socket as been woken up but not with any data.
165 // We'll throw a timeout exception to loop around again.
166 throw arm::pipe::TimeoutException(
167 "File descriptor was polled but no data was available to receive.");
168 }

Callers 2

ReceiveLoopMethod · 0.80

Calls 5

IoctlFunction · 0.85
ReceivePacketFunction · 0.85
PollFunction · 0.85
ProfilingExceptionClass · 0.85
TimeoutExceptionClass · 0.50

Tested by

no test coverage detected