Example #1
0
static ssize_t ssl_send(IOBuf *iob, char *buffer, int len)
{
    int sent = 0;
    int total = 0;
    check(iob->use_ssl, "IOBuf not set up to use ssl");

    if(!iob->handshake_performed) {
        int rcode = ssl_do_handshake(iob);
        check(rcode == 0, "SSL handshake failed: %d", rcode);
    }

    for(sent = 0; len > 0; buffer += sent, len -= sent, total += sent) {
        sent = ssl_write(&iob->ssl, (const unsigned char*) buffer, len);

        check(sent != -1, "Error sending SSL data.");
        check(sent <= len, "Buffer overflow. Too much data sent by ssl_write");

        // make sure we don't hog the process trying to stream out
        if(sent < len) {
            taskyield();
        }
    };

    return total;
error:
    return -1;
}
Example #2
0
static ssize_t ssl_recv(IOBuf *iob, char *buffer, int len)
{
    check(iob->use_ssl, "IOBuf not set up to use ssl");
    if(!iob->handshake_performed) {
        int rcode = ssl_do_handshake(iob);
        check(rcode == 0, "handshake failed");
    }
    return ssl_read(&iob->ssl, (unsigned char*) buffer, len);
error:
    return -1;
}
Example #3
0
static ssize_t ssl_send(IOBuf *iob, char *buffer, int len)
{
    ssize_t sent = 0;

    check(iob->use_ssl, "IOBuf not set up to use ssl");
    if(!iob->handshake_performed) {
        int rcode = ssl_do_handshake(iob);
        check(rcode == 0, "handshake failed");
    }

    do {
        // must send in chunks of SSL_MAX_CONTENT_LEN
        sent += ssl_write(&iob->ssl, (const unsigned char*) (buffer + sent), (len - sent));
    } while (sent < len);	

    return sent;
error:
    return -1;
}