1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimBIO_get_buffer_num_lines, 6e71b7053SJung-uk KimBIO_set_read_buffer_size, 7e71b7053SJung-uk KimBIO_set_write_buffer_size, 8e71b7053SJung-uk KimBIO_set_buffer_size, 9e71b7053SJung-uk KimBIO_set_buffer_read_data, 10e71b7053SJung-uk KimBIO_f_buffer 11e71b7053SJung-uk Kim- buffering BIO 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim=head1 SYNOPSIS 14e71b7053SJung-uk Kim 15e71b7053SJung-uk Kim #include <openssl/bio.h> 16e71b7053SJung-uk Kim 17e71b7053SJung-uk Kim const BIO_METHOD *BIO_f_buffer(void); 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim long BIO_get_buffer_num_lines(BIO *b); 20e71b7053SJung-uk Kim long BIO_set_read_buffer_size(BIO *b, long size); 21e71b7053SJung-uk Kim long BIO_set_write_buffer_size(BIO *b, long size); 22e71b7053SJung-uk Kim long BIO_set_buffer_size(BIO *b, long size); 23e71b7053SJung-uk Kim long BIO_set_buffer_read_data(BIO *b, void *buf, long num); 24e71b7053SJung-uk Kim 25e71b7053SJung-uk Kim=head1 DESCRIPTION 26e71b7053SJung-uk Kim 27e71b7053SJung-uk KimBIO_f_buffer() returns the buffering BIO method. 28e71b7053SJung-uk Kim 29e71b7053SJung-uk KimData written to a buffering BIO is buffered and periodically written 30e71b7053SJung-uk Kimto the next BIO in the chain. Data read from a buffering BIO comes from 31e71b7053SJung-uk Kiman internal buffer which is filled from the next BIO in the chain. 32e71b7053SJung-uk KimBoth BIO_gets() and BIO_puts() are supported. 33e71b7053SJung-uk Kim 34e71b7053SJung-uk KimCalling BIO_reset() on a buffering BIO clears any buffered data. 35e71b7053SJung-uk Kim 36e71b7053SJung-uk KimBIO_get_buffer_num_lines() returns the number of lines currently buffered. 37e71b7053SJung-uk Kim 38e71b7053SJung-uk KimBIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size() 39e71b7053SJung-uk Kimset the read, write or both read and write buffer sizes to B<size>. The initial 40e71b7053SJung-uk Kimbuffer size is DEFAULT_BUFFER_SIZE, currently 4096. Any attempt to reduce the 41e71b7053SJung-uk Kimbuffer size below DEFAULT_BUFFER_SIZE is ignored. Any buffered data is cleared 42e71b7053SJung-uk Kimwhen the buffer is resized. 43e71b7053SJung-uk Kim 44e71b7053SJung-uk KimBIO_set_buffer_read_data() clears the read buffer and fills it with B<num> 45e71b7053SJung-uk Kimbytes of B<buf>. If B<num> is larger than the current buffer size the buffer 46e71b7053SJung-uk Kimis expanded. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk Kim=head1 NOTES 49e71b7053SJung-uk Kim 50e71b7053SJung-uk KimThese functions, other than BIO_f_buffer(), are implemented as macros. 51e71b7053SJung-uk Kim 52*17f01e99SJung-uk KimBuffering BIOs implement BIO_read_ex() and BIO_gets() by using 53*17f01e99SJung-uk KimBIO_read_ex() operations on the next BIO in the chain and storing the 54*17f01e99SJung-uk Kimresult in an internal buffer, from which bytes are given back to the 55*17f01e99SJung-uk Kimcaller as appropriate for the call; a BIO_gets() is guaranteed to give 56*17f01e99SJung-uk Kimthe caller a whole line, and BIO_read_ex() is guaranteed to give the 57*17f01e99SJung-uk Kimcaller the number of bytes it asks for, unless there's an error or end 58*17f01e99SJung-uk Kimof communication is reached in the next BIO. By prepending a 59*17f01e99SJung-uk Kimbuffering BIO to a chain it is therefore possible to provide 60*17f01e99SJung-uk KimBIO_gets() or exact size BIO_read_ex() functionality if the following 61*17f01e99SJung-uk KimBIOs do not support it. 62*17f01e99SJung-uk Kim 63*17f01e99SJung-uk KimDo not add more than one BIO_f_buffer() to a BIO chain. The result of 64*17f01e99SJung-uk Kimdoing so will force a full read of the size of the internal buffer of 65*17f01e99SJung-uk Kimthe top BIO_f_buffer(), which is 4 KiB at a minimum. 66e71b7053SJung-uk Kim 67e71b7053SJung-uk KimData is only written to the next BIO in the chain when the write buffer fills 68e71b7053SJung-uk Kimor when BIO_flush() is called. It is therefore important to call BIO_flush() 69e71b7053SJung-uk Kimwhenever any pending data should be written such as when removing a buffering 70e71b7053SJung-uk KimBIO using BIO_pop(). BIO_flush() may need to be retried if the ultimate 71e71b7053SJung-uk Kimsource/sink BIO is non blocking. 72e71b7053SJung-uk Kim 73e71b7053SJung-uk Kim=head1 RETURN VALUES 74e71b7053SJung-uk Kim 75e71b7053SJung-uk KimBIO_f_buffer() returns the buffering BIO method. 76e71b7053SJung-uk Kim 77e71b7053SJung-uk KimBIO_get_buffer_num_lines() returns the number of lines buffered (may be 0). 78e71b7053SJung-uk Kim 79e71b7053SJung-uk KimBIO_set_read_buffer_size(), BIO_set_write_buffer_size() and BIO_set_buffer_size() 80e71b7053SJung-uk Kimreturn 1 if the buffer was successfully resized or 0 for failure. 81e71b7053SJung-uk Kim 82e71b7053SJung-uk KimBIO_set_buffer_read_data() returns 1 if the data was set correctly or 0 if 83e71b7053SJung-uk Kimthere was an error. 84e71b7053SJung-uk Kim 85e71b7053SJung-uk Kim=head1 SEE ALSO 86e71b7053SJung-uk Kim 87e71b7053SJung-uk KimL<bio(7)>, 88e71b7053SJung-uk KimL<BIO_reset(3)>, 89e71b7053SJung-uk KimL<BIO_flush(3)>, 90e71b7053SJung-uk KimL<BIO_pop(3)>, 91e71b7053SJung-uk KimL<BIO_ctrl(3)>. 92e71b7053SJung-uk Kim 93e71b7053SJung-uk Kim=head1 COPYRIGHT 94e71b7053SJung-uk Kim 95*17f01e99SJung-uk KimCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. 96e71b7053SJung-uk Kim 97e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 98e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 99e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 100e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 101e71b7053SJung-uk Kim 102e71b7053SJung-uk Kim=cut 103