Something seems off in the tls_server example. It's working for me, but it seems that there is no possibility of it having a "success" the way it is written. In the following extract, the while exists when ret is different than 0 (when it actually wrote). Then the value of ret is check to be non-zero and then an error is printed. Would it be better to reset ret after it has written, right? This is the first time I'm playing with these libraries so I might be wrong.
while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
{
if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
{
printf(" failed\n ! mbedtls_ssl_write returned %d\n\n", ret);
goto exit;
}
}
len = ret;
printf(" %d bytes written. Closing socket on client.\n\n%s", len, (char *) buf);
mbedtls_ssl_close_notify(&ssl);
exit:
mbedtls_ssl_session_reset(&ssl);
mbedtls_net_free(&client_ctx);
mbedtls_net_free(&server_ctx);
if(ret != 0)
{
char error_buf[100];
mbedtls_strerror(ret, error_buf, 100);
printf("\n\nLast error was: %d - %s\n\n", ret, error_buf);
failures++;
} else {
successes++;
}