| 201 | } |
| 202 | |
| 203 | bool BasePipeServer::SendPacket(uint32_t packetFamily, uint32_t packetId, const uint8_t* data, uint32_t dataLength) |
| 204 | { |
| 205 | // Construct a packet from the id and data given and send it to the client. |
| 206 | // Encode the header. |
| 207 | uint32_t header[2]; |
| 208 | header[0] = packetFamily << 26 | packetId << 16; |
| 209 | header[1] = dataLength; |
| 210 | // Add the header to the packet. |
| 211 | std::vector<uint8_t> packet(8 + dataLength); |
| 212 | InsertU32(header[0], packet.data(), m_Endianness); |
| 213 | InsertU32(header[1], packet.data() + 4, m_Endianness); |
| 214 | // And the rest of the data if there is any. |
| 215 | if (dataLength > 0) |
| 216 | { |
| 217 | if (data == nullptr) |
| 218 | { |
| 219 | throw ProfilingException( |
| 220 | "basePipeServer: SendPacket: Attempting to send a non-zero length data packet with a null data pointer" |
| 221 | ); |
| 222 | } |
| 223 | memcpy((packet.data() + 8), data, dataLength); |
| 224 | } |
| 225 | EchoPacket(PacketDirection::Sending, packet.data(), packet.size()); |
| 226 | if (-1 == arm::pipe::Write(m_ClientConnection, packet.data(), packet.size())) |
| 227 | { |
| 228 | std::cerr << ": Failure when writing to client socket: " << strerror(errno) << std::endl; |
| 229 | return false; |
| 230 | } |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | bool BasePipeServer::ReadHeader(uint32_t headerAsWords[2]) |
| 235 | { |
no test coverage detected