I'm new to OpenSSL. I understand BIO_write(BIO *b, const void *buf, int len) needs to be called in a loop but I'm not entirely sure if I'm using it correctly. I've written a function like this:
int32_t SendPacket(BIO * const pBio, const unsigned char * const pPacket, const int nPacketLength)
{
int32_t nPos = 0;
if (!pBio || !pPacket || !nPacketLength)
return -1;
while (nPos < nPacketLength)
{
int32_t nNumberOfBytesWritten = BIO_write(pBio, &pPacket[nPos], nPacketLength - nPos);
if (nNumberOfBytesWritten <= 0)
{
if (!BIO_should_retry(pBio))
return -1;
}
else
{
nPos += nNumberOfBytesWritten;
}
}
return nPos;
}
And I'm thinking of using it like this:
if (SendPacket(pBio, pPacket, nPacketLength) == nPacketLength)
{
// Packet sent correctly.
}
else
{
// Error occurred.
}
Does the function look correct? Any feedback is appreciated.