X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=ssl.c;h=852a9ce5304256a56700b8f9291736269a19c2bc;hp=0bb549bff7652bf5fc47753b9d3aa1488a644740;hb=401c25dde61a9db0c47170bb213ae3e74252a0c2;hpb=9c5023572da8d77913f62358f46fc6e053085909 diff --git a/ssl.c b/ssl.c index 0bb549bf..852a9ce5 100644 --- a/ssl.c +++ b/ssl.c @@ -260,6 +260,69 @@ extern int ssl_send_data(mbedtls_ssl_context *ssl, const unsigned char *buf, siz } +/********************************************************************* + * + * Function : ssl_send_data_delayed + * + * Description : Sends the contents of buf (for n bytes) to given SSL + * connection, optionally delaying the operation. + * + * Parameters : + * 1 : ssl = SSL context to send data to + * 2 : buf = Pointer to data to be sent + * 3 : len = Length of data to be sent to the SSL context + * 4 : delay = Delay in milliseconds. + * + * Returns : 0 on success (entire buffer sent). + * nonzero on error. + * + *********************************************************************/ +extern int ssl_send_data_delayed(mbedtls_ssl_context *ssl, + const unsigned char *buf, size_t len, + unsigned int delay) +{ + size_t i = 0; + + if (delay == 0) + { + if (ssl_send_data(ssl, buf, len) < 0) + { + return -1; + } + else + { + return 0; + } + } + + while (i < len) + { + size_t write_length; + enum { MAX_WRITE_LENGTH = 10 }; + + if ((i + MAX_WRITE_LENGTH) > len) + { + write_length = len - i; + } + else + { + write_length = MAX_WRITE_LENGTH; + } + + privoxy_millisleep(delay); + + if (ssl_send_data(ssl, buf + i, write_length) < 0) + { + return -1; + } + i += write_length; + } + + return 0; + +} + + /********************************************************************* * * Function : ssl_recv_data