65 # ifndef BIO_PAIR_DEBUG
66 # define BIO_PAIR_DEBUG
71 #ifndef BIO_PAIR_DEBUG
89 #if defined(OPENSSL_SYS_VXWORKS)
93 # define SSIZE_MAX INT_MAX
96 static int bio_new(
BIO *bio);
97 static int bio_free(
BIO *bio);
98 static int bio_read(
BIO *bio,
char *buf,
int size);
99 static int bio_write(
BIO *bio,
const char *buf,
int num);
100 static long bio_ctrl(
BIO *bio,
int cmd,
long num,
void *
ptr);
101 static int bio_puts(
BIO *bio,
const char *str);
103 static int bio_make_pair(
BIO *bio1,
BIO *bio2);
104 static void bio_destroy_pair(
BIO *bio);
122 return &methods_biop;
145 static int bio_new(
BIO *bio)
162 static int bio_free(
BIO *bio)
173 bio_destroy_pair(bio);
187 static int bio_read(
BIO *bio,
char *
buf,
int size_)
200 assert(b->
peer != NULL);
202 assert(peer_b != NULL);
203 assert(peer_b->
buf != NULL);
207 if (buf == NULL || size == 0)
210 if (peer_b->
len == 0)
217 if (size <= peer_b->size)
228 if (peer_b->
len < size)
240 assert(rest <= peer_b->
len);
241 if (peer_b->
offset + rest <= peer_b->size)
246 assert(peer_b->
offset + chunk <= peer_b->size);
248 memcpy(buf, peer_b->
buf + peer_b->
offset, chunk);
250 peer_b->
len -= chunk;
262 assert(chunk == rest);
292 assert(b->
peer != NULL);
294 assert(peer_b != NULL);
295 assert(peer_b->
buf != NULL);
299 if (peer_b->
len == 0)
304 return bio_read(bio, &dummy, 1);
328 available = bio_nread0(bio, buf);
352 static int bio_write(
BIO *bio,
const char *buf,
int num_)
360 if (!bio->
init || buf == NULL || num == 0)
365 assert(b->
peer != NULL);
366 assert(b->
buf != NULL);
398 assert(b->
len + rest <= b->size);
401 if (write_offset >= b->
size)
402 write_offset -= b->
size;
405 if (write_offset + rest <= b->size)
409 chunk = b->
size - write_offset;
411 memcpy(b->
buf + write_offset, buf, chunk);
444 assert(b->
peer != NULL);
445 assert(b->
buf != NULL);
464 if (write_offset >= b->
size)
465 write_offset -= b->
size;
466 if (write_offset + num > b->
size)
470 num = b->
size - write_offset;
473 *buf = b->
buf + write_offset;
474 assert(write_offset + num <= b->size);
489 space = bio_nwrite0(bio, buf);
503 static long bio_ctrl(
BIO *bio,
int cmd,
long num,
void *
ptr)
527 size_t new_size =
num;
529 if (b->
size != new_size)
543 ret = (long) b->
size;
548 BIO *other_bio = ptr;
550 if (bio_make_pair(bio, other_bio))
560 bio_destroy_pair(bio);
597 ret = (long) bio_nread0(bio, ptr);
602 ret = (long) bio_nread(bio, ptr, (
size_t)
num);
607 ret = (long) bio_nwrite0(bio, ptr);
612 ret = (long) bio_nwrite(bio, ptr, (
size_t)
num);
641 ret = (long) peer_b->
len;
657 BIO *other_bio = ptr;
660 assert(other_bio != NULL);
661 other_b = other_bio->ptr;
662 assert(other_b != NULL);
664 assert(other_b->buf == NULL);
666 other_b->size = b->
size;
684 assert(other_b != NULL);
685 ret = other_b->
len == 0 && other_b->
closed;
698 static int bio_puts(
BIO *bio,
const char *str)
700 return bio_write(bio, str, strlen(str));
704 static int bio_make_pair(
BIO *bio1,
BIO *bio2)
708 assert(bio1 != NULL);
709 assert(bio2 != NULL);
714 if (b1->
peer != NULL || b2->
peer != NULL)
757 static void bio_destroy_pair(
BIO *bio)
765 if (peer_bio != NULL)
769 assert(peer_b != NULL);
770 assert(peer_b->
peer == bio);
774 assert(peer_b->
buf != NULL);
780 assert(b->
buf != NULL);
790 BIO **bio2_p,
size_t writebuf2)
792 BIO *bio1 = NULL, *bio2 = NULL;