Use non-copying BIO interface in ssltest.c.
This commit is contained in:
parent
ac3e3cdc96
commit
6f7af1524e
2
CHANGES
2
CHANGES
@ -17,7 +17,7 @@
|
|||||||
[Steve Henson]
|
[Steve Henson]
|
||||||
|
|
||||||
*) Non-copying interface to BIO pairs.
|
*) Non-copying interface to BIO pairs.
|
||||||
(still totally untested)
|
(still largely untested)
|
||||||
[Bodo Moeller]
|
[Bodo Moeller]
|
||||||
|
|
||||||
*) New function ANS1_tag2str() to convert an ASN1 tag to a descriptive
|
*) New function ANS1_tag2str() to convert an ASN1 tag to a descriptive
|
||||||
|
@ -202,9 +202,8 @@ static int bio_read(BIO *bio, char *buf, int size_)
|
|||||||
* (example usage: bio_nread0(), read from buffer, bio_nread()
|
* (example usage: bio_nread0(), read from buffer, bio_nread()
|
||||||
* or just bio_nread(), read from buffer)
|
* or just bio_nread(), read from buffer)
|
||||||
*/
|
*/
|
||||||
/* WARNING: The non-copying interface is totally untested as of yet --
|
/* WARNING: The non-copying interface is largely untested as of yet
|
||||||
* I wrote it, but have not yet read it; and surely it still is full
|
* and may contain bugs. */
|
||||||
* of bugs. */
|
|
||||||
static size_t bio_nread0(BIO *bio, char **buf)
|
static size_t bio_nread0(BIO *bio, char **buf)
|
||||||
{
|
{
|
||||||
struct bio_bio_st *b, *peer_b;
|
struct bio_bio_st *b, *peer_b;
|
||||||
|
101
ssl/ssltest.c
101
ssl/ssltest.c
@ -56,11 +56,12 @@
|
|||||||
* [including the GNU Public Licence.]
|
* [including the GNU Public Licence.]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#include "openssl/e_os.h"
|
#include "openssl/e_os.h"
|
||||||
|
|
||||||
@ -653,48 +654,40 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count)
|
|||||||
{
|
{
|
||||||
/* "I/O" BETWEEN CLIENT AND SERVER. */
|
/* "I/O" BETWEEN CLIENT AND SERVER. */
|
||||||
|
|
||||||
/* TODO: use non-blocking BIO interface for (say) the client
|
|
||||||
* to illustrate its use and to test it. */
|
|
||||||
|
|
||||||
#define RELAYBUFSIZ 200
|
|
||||||
static char buf[RELAYBUFSIZ];
|
|
||||||
|
|
||||||
/* RELAYBUF is arbitrary. When writing data over some real
|
|
||||||
* network, use a buffer of the same size as in the BIO_pipe
|
|
||||||
* and make that size large (for reading from the network
|
|
||||||
* small buffers usually won't hurt).
|
|
||||||
* Here sizes differ for testing. */
|
|
||||||
|
|
||||||
size_t r1, r2;
|
size_t r1, r2;
|
||||||
size_t num;
|
BIO *io1 = server_io, *io2 = client_io;
|
||||||
int r;
|
/* we use the non-copying interface for io1
|
||||||
|
* and the standard BIO_write/BIO_read interface for io2
|
||||||
|
*/
|
||||||
|
|
||||||
static int prev_progress = 1;
|
static int prev_progress = 1;
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
|
|
||||||
/* client to server */
|
/* io1 to io2 */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
r1 = BIO_ctrl_pending(client_io);
|
size_t num;
|
||||||
r2 = BIO_ctrl_get_write_guarantee(server_io);
|
int r;
|
||||||
|
|
||||||
|
r1 = BIO_ctrl_pending(io1);
|
||||||
|
r2 = BIO_ctrl_get_write_guarantee(io2);
|
||||||
|
|
||||||
num = r1;
|
num = r1;
|
||||||
if (r2 < num)
|
if (r2 < num)
|
||||||
num = r2;
|
num = r2;
|
||||||
if (num)
|
if (num)
|
||||||
{
|
{
|
||||||
if (sizeof buf < num)
|
char *dataptr;
|
||||||
num = sizeof buf;
|
|
||||||
if (INT_MAX < num) /* yeah, right */
|
if (INT_MAX < num) /* yeah, right */
|
||||||
num = INT_MAX;
|
num = INT_MAX;
|
||||||
|
|
||||||
r = BIO_read(client_io, buf, (int)num);
|
r = BIO_nread(io1, &dataptr, (int)num);
|
||||||
if (r != (int)num) /* can't happen */
|
assert(r > 0);
|
||||||
{
|
assert(r <= (int)num);
|
||||||
fprintf(stderr, "ERROR: BIO_read could not read "
|
/* possibly r < num (non-contiguous data) */
|
||||||
"BIO_ctrl_pending() bytes");
|
num = r;
|
||||||
goto err;
|
r = BIO_write(io2, dataptr, (int)num);
|
||||||
}
|
|
||||||
r = BIO_write(server_io, buf, (int)num);
|
|
||||||
if (r != (int)num) /* can't happen */
|
if (r != (int)num) /* can't happen */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: BIO_write could not write "
|
fprintf(stderr, "ERROR: BIO_write could not write "
|
||||||
@ -704,48 +697,58 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count)
|
|||||||
progress = 1;
|
progress = 1;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
printf("C->S relaying: %d bytes\n", (int)num);
|
printf((io1 == client_io) ?
|
||||||
|
"C->S relaying: %d bytes\n" :
|
||||||
|
"S->C relaying: %d bytes\n",
|
||||||
|
(int)num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (r1 && r2);
|
while (r1 && r2);
|
||||||
|
|
||||||
/* server to client */
|
/* io2 to io1 */
|
||||||
do
|
{
|
||||||
{
|
size_t num;
|
||||||
r1 = BIO_ctrl_pending(server_io);
|
int r;
|
||||||
r2 = BIO_ctrl_get_write_guarantee(client_io);
|
|
||||||
|
|
||||||
|
r1 = BIO_ctrl_pending(io2);
|
||||||
|
r2 = BIO_ctrl_get_read_request(io1);
|
||||||
|
/* here we could use ..._get_write_guarantee instead of
|
||||||
|
* ..._get_read_request, but by using the latter
|
||||||
|
* we test restartability of the SSL implementation
|
||||||
|
* more thoroughly */
|
||||||
num = r1;
|
num = r1;
|
||||||
if (r2 < num)
|
if (r2 < num)
|
||||||
num = r2;
|
num = r2;
|
||||||
if (num)
|
if (num)
|
||||||
{
|
{
|
||||||
if (sizeof buf < num)
|
char *dataptr;
|
||||||
num = sizeof buf;
|
|
||||||
if (INT_MAX < num)
|
if (INT_MAX < num)
|
||||||
num = INT_MAX;
|
num = INT_MAX;
|
||||||
|
|
||||||
|
if (num > 1)
|
||||||
|
--num; /* for testing restartability even more thoroughly */
|
||||||
|
|
||||||
r = BIO_read(server_io, buf, (int)num);
|
r = BIO_nwrite(io1, &dataptr, (int)num);
|
||||||
|
assert(r > 0);
|
||||||
|
assert(r <= (int)num);
|
||||||
|
num = r;
|
||||||
|
r = BIO_read(io2, dataptr, (int)num);
|
||||||
if (r != (int)num) /* can't happen */
|
if (r != (int)num) /* can't happen */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: BIO_read could not read "
|
fprintf(stderr, "ERROR: BIO_read could not read "
|
||||||
"BIO_ctrl_pending() bytes");
|
"BIO_ctrl_pending() bytes");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
r = BIO_write(client_io, buf, (int)num);
|
|
||||||
if (r != (int)num) /* can't happen */
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ERROR: BIO_write could not write "
|
|
||||||
"BIO_ctrl_get_write_guarantee() bytes");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
progress = 1;
|
progress = 1;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
printf("S->C relaying: %d bytes\n", (int)num);
|
printf((io2 == client_io) ?
|
||||||
|
"C->S relaying: %d bytes\n" :
|
||||||
|
"S->C relaying: %d bytes\n",
|
||||||
|
(int)num);
|
||||||
}
|
}
|
||||||
}
|
} /* no loop, BIO_ctrl_get_read_request now returns 0 anyway */
|
||||||
while (r1 && r2);
|
|
||||||
|
|
||||||
if (!progress && !prev_progress)
|
if (!progress && !prev_progress)
|
||||||
if (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0)
|
if (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user