我是 OpenSSL 的新手。我了解 BIO_write(BIO *b, const void *buf, int len) 需要在循环中调用,但我不完全确定我是否正确使用它。我写了一个这样的函数:
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;
}
我正在考虑这样使用它:
if (SendPacket(pBio, pPacket, nPacketLength) == nPacketLength)
{
// Packet sent correctly.
}
else
{
// Error occurred.
}
函数看起来正确吗?任何反馈表示赞赏。