The following worked code for me.
count = SSL_read(ssl, buf, sizeof(buf)); // get request
int32_t ssl_error = SSL_get_error (ssl, count);
switch (ssl_error) {
case SSL_ERROR_NONE:
printf("SSL_ERROR_NONE\n");
break;
case SSL_ERROR_WANT_READ:
printf("SSL_ERROR_WANT_READ\n");
break;
case SSL_ERROR_WANT_WRITE:
printf("SSL_ERROR_WANT_WRITE\n");
break;
case SSL_ERROR_ZERO_RETURN:
printf("SSL_ERROR_ZERO_RETURN\n");
break;
default:
break;
}
if (( count > 0 ) && (ssl_error == SSL_ERROR_NONE))
{
buf[count] = 0;
printf("count > 0 Client msg: \"%s\"\n", buf);
sprintf(reply, HTMLecho, buf); // construct reply
SSL_write(ssl, reply, strlen(reply)); // send reply
} else if ((count < 0) && (ssl_error == SSL_ERROR_WANT_READ)){
printf("count < 0 \n");
if (errno != EAGAIN)
{
printf("count < 0 errno != EAGAIN \n");
perror ("read");
done = 1;
}
break;
} else if (count==0){
ERR_print_errors_fp(stderr);
printf("count == 0 Client Disconnected.\n");
done = 1;
break;
}