Buffer type BIO
--- Translation according to OpenSSL DOC / CRYPTO / BIO_F_BUFFER.POD and its understanding
(Author: DragonKing, Mail: wzhah@263.net, Posted: httpgdwzh.126.com the openssl professional forum)
Buffer Type BIO is a filter-type Bio, which is defined as follows (OpenSSL / BIO.H):
BIO_METHOD * BIO_F_BUFFER (VOID);
#define bio_get_buffer_num_lines (b) BIO_CTRL (B, BIO_C_GET_BUFF_NUM_LINES, 0, NULL)
#define bio_set_read_buffer_size (b, size) BIO_INT_CTRL (B, BIO_C_SET_BUFF_SIZE, SIZE, 0)
#DEFINE BIO_SET_WRITE_BUFFER_SIZE (B, Size) BIO_INT_CTRL (B, BIO_C_SET_BUFF_SIZE, SIZE, 1)
#define bio_set_buffer_size (b, size) BIO_CTRL (B, BIO_C_SET_BUFF_SIZE, SIZE, NULL)
#define bio_set_buffer_read_data (B, BUF, NUM) BIO_CTRL (B, BIO_C_SET_BUFF_READ_DATA, NUM, BUF)
[BIO_F_BUFFER]
This function returns a BIO_METHOD structure of a buffer type that is defined as follows (bf_buff.c):
Static Bio_Method Methods_Buffer =
{
BIO_TYPE_BUFFER,
"buffer",
Buffer_write,
Buffer_read,
Buffer_puts,
Buffer_gets,
Buffer_ctrl,
Buffer_new,
Buffer_free,
Buffer_callback_ctrl,
}
As can be seen from the structural definition, this type of BIO supports all BIO I / O functions. The data stored in the buffer BIO is stored in the buffer. It is regularly written to the next Bio of the BIO chain. In fact, the data will only write the following Bio when only the buffer is full or calling the BIO_FLUSH function. ,, When any data stored in the buffer needs to be written (such as before using the BIO_POP function to remove a buffer type Bio from the BIO chain), the BIO_FLUSH function must be used, if the end of the BIO chain is a non-blocking type BIO, sometimes calling BIO_FLUSH may fail, and need to try again. When reading data from this type of BIO, data is filled from the next BIO to the BIO's internal buffer, and then read it. This type of BIO supports the Bio_Gets and Bio_puts methods. In fact, the BIO_GETS function is implemented by the next BIO's BIO_READ function, so if a BIO does not support the Bio_gets method (such as the SSL type Bio), you can use a Buffer type by pre-additional BIO to implement the function of Bio_Gets.
When the BIO_RESET is called, all data in this type of BIO will be emptied.
[BIO_GET_BUFFER_NUM_LINES]
Returns the number of rows of current data in the buffer.
[BIO_SET_READ_BUFFER_SIZE, BIO_SET_WRITE_BUFFER_SIZE and BIO_SET_BUFFER_SIZE] These three functions are set, write or read and write buffers for buffer type BIO, respectively. The initial buffer size is determined by macro default_buffer_size, the default is 1024. If the set buffer is small and less than default_buffer_size, it will be ignored, that is, the buffer size is maintained as the size defined by default_buffer_size. When the buffer is reset, the data inside will be cleared. Successfully executed returns 1, otherwise returns 0.
[BIO_SET_BUFFER_READ_DATA]
This function empties the original data of the buffer and populates the buffer using the data in the NUM BUF. If the size of the NUM is greater than the current buffer setting size, the buffer will automatically expand. Successful settings returns 1, otherwise it returns 0.