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

Method ReceivePacket

profiling/client/src/SocketProfilingConnection.cpp:178–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178arm::pipe::Packet SocketProfilingConnection::ReceivePacket()
179{
180#if !defined(ARMNN_DISABLE_SOCKETS)
181 char header[8] = {};
182 long receiveResult = arm::pipe::Read(m_Socket[0].fd, &header, sizeof(header));
183 // We expect 8 as the result here. 0 means EOF, socket is closed. -1 means there been some other kind of error.
184 switch( receiveResult )
185 {
186 case 0:
187 // Socket has closed.
188 Close();
189 throw arm::pipe::SocketConnectionException(
190 std::string("SocketProfilingConnection: Remote socket has closed the connection."),
191 m_Socket[0].fd);
192 case -1:
193 // There's been a socket error. We will presume it's unrecoverable.
194 Close();
195 throw arm::pipe::SocketConnectionException(
196 std::string("SocketProfilingConnection: Error occured while reading the packet: ") + strerror(errno),
197 m_Socket[0].fd,
198 errno);
199 default:
200 if (receiveResult < 8)
201 {
202 throw arm::pipe::SocketConnectionException(
203 std::string(
204 "SocketProfilingConnection: The received packet did not contains a valid PIPE header."),
205 m_Socket[0].fd);
206 }
207 break;
208 }
209
210 // stream_metadata_identifier is the first 4 bytes
211 uint32_t metadataIdentifier = 0;
212 std::memcpy(&metadataIdentifier, header, sizeof(metadataIdentifier));
213
214 // data_length is the next 4 bytes
215 uint32_t dataLength = 0;
216 std::memcpy(&dataLength, header + 4u, sizeof(dataLength));
217
218 std::unique_ptr<unsigned char[]> packetData;
219 if (dataLength > 0)
220 {
221 packetData = std::make_unique<unsigned char[]>(dataLength);
222 long receivedLength = arm::pipe::Read(m_Socket[0].fd, packetData.get(), dataLength);
223 if (receivedLength < 0)
224 {
225 throw arm::pipe::SocketConnectionException(
226 std::string("SocketProfilingConnection: Error occured while reading the packet: ") + strerror(errno),
227 m_Socket[0].fd,
228 errno);
229 }
230 if (dataLength != static_cast<uint32_t>(receivedLength))
231 {
232 // What do we do here if we can't read in a full packet?
233 throw arm::pipe::SocketConnectionException(
234 std::string("SocketProfilingConnection: Invalid PIPE packet."),
235 m_Socket[0].fd);

Callers

nothing calls this directly

Calls 5

ReadFunction · 0.85
CloseFunction · 0.85
PacketClass · 0.50
TimeoutExceptionClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected