I’ve always used “over TCP” protocols with a fixed and known size. But what about reading data without a known size where the ‘end’ is marked by a delimiter? (e.g HTTP Headers) This is the function I normally use:
int TcpClient::Recv(std::vector<unsigned char>& buf, size_t toRecv){
int total = 0;
do{
int nRecv = SSL_read(ssl, buf.data() + total, toRecv - total);
if(nRecv <= 0)
break;
total += nRecv;
}while (total < toRecv);
return total;
}
The underlying layer is blocking. Again, this would work fine for known size messages. An option would be reading one byte at a time until the delimiter is found but that would be extremely inefficient due to the overhead of such many function calls. Is it possible to achieve such thing without non-blocking or without the use of hard coded timeouts? Thanks.