/* Low-level data read callback for the simplified SSL I/O API.  */
static int sock_read(void *ctx, unsigned char *buf, size_t len)
/* Low-level data read callback for the simplified SSL I/O API.  */
static int sock_read(void *ctx, unsigned char *buf, size_t len)
{
    for (;;) {
        ssize_t rlen;
        rlen = read(*(int *)ctx, buf, len);
        if (rlen <= 0) {
            if (rlen < 0 && errno == EINTR) {
                    continue;
            }
            return -1;
        }
        return (int)rlen;
    }
}