我正在尝试使用OpenSSL创建一个非阻塞套接字,以便可以遍历SSL_read()直到没有剩余数据,然后中断该循环。经过大量工作,我终于使连接正常工作,但是现在对于前一千次迭代,SSL_read()将返回-1。之后,它将为我提供套接字上的实际数据。SSL_read()也不返回读取的准确字节数,即使它正在读取正确的字节,它也总是说-1。我能够使其在使用阻塞套接字的情况下正常工作,但非阻塞似乎有问题...
char *sslRead (connection *c)
{
const int readSize = 1024;
char *rc = NULL;
int r;
int received = -1, count = 0;
int TotalReceived = 0, ReallocSize = 0;
char buffer[1024];
if (c)
{
while (1)
{
received = SSL_read (c->sslHandle, buffer, readSize);
buffer[received] = '\0';
TotalReceived += received;
printf("Buffsize - %i - %s \n", received, buffer);
if (received <= 0)
{
// this line added per advice of Eric Tsui but does not
// change behaviour
received …Run Code Online (Sandbox Code Playgroud)