connection::packet_size_indicator connection::bytes_available()
{
- // max packet size is unsigned int
-
// no size information -> no packet
if (buffer.size() < sizeof(packet_size_indicator))
return 0;
return false;
}
+/** @brief get (maybe incomplete) data of the next packet from the buffer. Does not remove the data
+ from the connection buffer.
+ @param[out] data the data package
+ @retval full size of the packet when it will be complete
+*/
+unsigned int connection::peek_packet(std::string& data)
+{
+ // no size information -> no packet
+ if (buffer.size() < sizeof(packet_size_indicator))
+ return 0;
+
+ packet_size_indicator psize=ntohl(*((packet_size_indicator*)(buffer.data())));
+
+ // not the full data available?
+ packet_size_indicator currsize=psize;
+ if (buffer.size() < currsize+sizeof(packet_size_indicator))
+ currsize=buffer.size()-sizeof(packet_size_indicator);
+
+ data.assign(buffer,sizeof(packet_size_indicator),currsize);
+
+ return psize;
+}
+
/// send a blob to the peer
void connection::write(const std::string& data)
{