I am doing an handshake between a client and a server, after the handshake the client sends a message and waits for the server to reply with the same message. The first message always goes through, but the client is never able to read the second one and the ones after, it simply reads 0.
I found that the first loop ssl->buffers.clearOutputBuffer.length is equal to zero, but the second time it's like 900, so wolfSSL_read follows a different procedure, doesn't read and sets the buffer at zero. If in debug i set ssl->buffers.clearOutputBuffer.length to zero everything works. So i would like to know how can i do it in code, or what am i doing wrong.
while (true)
{
printf("Send a string to the server\n"
"x to exit\n");
if (fgets(stringtosend, sizeof(stringtosend), stdin) == NULL) {
printf("error reading");
}
do {
ret = wolfSSL_write(ssl, stringtosend, sizeof(stringtosend));
err = wolfSSL_get_error(ssl, ret);
} while (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE);
printf("Sent (%d): %s\n", err, stringtosend);
XMEMSET(readBuf, 0, sizeof(readBuf));
do {
ret = wolfSSL_read(ssl, readBuf, sizeof(readBuf)-1);
err = wolfSSL_get_error(ssl, ret);
} while (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE);
printf("Read (%d): %s\n", err, readBuf);
//ssl->buffers.clearOutputBuffer.length = 0;
if (stringtosend[0] == 'x' && stringtosend[1] == '\n'){
return;
}
}