1*1dcdf01fSchristos=pod 2*1dcdf01fSchristos 3*1dcdf01fSchristos=head1 NAME 4*1dcdf01fSchristos 5*1dcdf01fSchristosBIO_read_ex, BIO_write_ex, BIO_read, BIO_write, BIO_gets, BIO_puts 6*1dcdf01fSchristos- BIO I/O functions 7*1dcdf01fSchristos 8*1dcdf01fSchristos=head1 SYNOPSIS 9*1dcdf01fSchristos 10*1dcdf01fSchristos #include <openssl/bio.h> 11*1dcdf01fSchristos 12*1dcdf01fSchristos int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes); 13*1dcdf01fSchristos int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); 14*1dcdf01fSchristos 15*1dcdf01fSchristos int BIO_read(BIO *b, void *data, int dlen); 16*1dcdf01fSchristos int BIO_gets(BIO *b, char *buf, int size); 17*1dcdf01fSchristos int BIO_write(BIO *b, const void *data, int dlen); 18*1dcdf01fSchristos int BIO_puts(BIO *b, const char *buf); 19*1dcdf01fSchristos 20*1dcdf01fSchristos=head1 DESCRIPTION 21*1dcdf01fSchristos 22*1dcdf01fSchristosBIO_read_ex() attempts to read B<dlen> bytes from BIO B<b> and places the data 23*1dcdf01fSchristosin B<data>. If any bytes were successfully read then the number of bytes read is 24*1dcdf01fSchristosstored in B<*readbytes>. 25*1dcdf01fSchristos 26*1dcdf01fSchristosBIO_write_ex() attempts to write B<dlen> bytes from B<data> to BIO B<b>. If 27*1dcdf01fSchristossuccessful then the number of bytes written is stored in B<*written>. 28*1dcdf01fSchristos 29*1dcdf01fSchristosBIO_read() attempts to read B<len> bytes from BIO B<b> and places 30*1dcdf01fSchristosthe data in B<buf>. 31*1dcdf01fSchristos 32*1dcdf01fSchristosBIO_gets() performs the BIOs "gets" operation and places the data 33*1dcdf01fSchristosin B<buf>. Usually this operation will attempt to read a line of data 34*1dcdf01fSchristosfrom the BIO of maximum length B<size-1>. There are exceptions to this, 35*1dcdf01fSchristoshowever; for example, BIO_gets() on a digest BIO will calculate and 36*1dcdf01fSchristosreturn the digest and other BIOs may not support BIO_gets() at all. 37*1dcdf01fSchristosThe returned string is always NUL-terminated and the '\n' is preserved 38*1dcdf01fSchristosif present in the input data. 39*1dcdf01fSchristos 40*1dcdf01fSchristosBIO_write() attempts to write B<len> bytes from B<buf> to BIO B<b>. 41*1dcdf01fSchristos 42*1dcdf01fSchristosBIO_puts() attempts to write a NUL-terminated string B<buf> to BIO B<b>. 43*1dcdf01fSchristos 44*1dcdf01fSchristos=head1 RETURN VALUES 45*1dcdf01fSchristos 46*1dcdf01fSchristosBIO_read_ex() and BIO_write_ex() return 1 if data was successfully read or 47*1dcdf01fSchristoswritten, and 0 otherwise. 48*1dcdf01fSchristos 49*1dcdf01fSchristosAll other functions return either the amount of data successfully read or 50*1dcdf01fSchristoswritten (if the return value is positive) or that no data was successfully 51*1dcdf01fSchristosread or written if the result is 0 or -1. If the return value is -2 then 52*1dcdf01fSchristosthe operation is not implemented in the specific BIO type. The trailing 53*1dcdf01fSchristosNUL is not included in the length returned by BIO_gets(). 54*1dcdf01fSchristos 55*1dcdf01fSchristos=head1 NOTES 56*1dcdf01fSchristos 57*1dcdf01fSchristosA 0 or -1 return is not necessarily an indication of an error. In 58*1dcdf01fSchristosparticular when the source/sink is nonblocking or of a certain type 59*1dcdf01fSchristosit may merely be an indication that no data is currently available and that 60*1dcdf01fSchristosthe application should retry the operation later. 61*1dcdf01fSchristos 62*1dcdf01fSchristosOne technique sometimes used with blocking sockets is to use a system call 63*1dcdf01fSchristos(such as select(), poll() or equivalent) to determine when data is available 64*1dcdf01fSchristosand then call read() to read the data. The equivalent with BIOs (that is call 65*1dcdf01fSchristosselect() on the underlying I/O structure and then call BIO_read() to 66*1dcdf01fSchristosread the data) should B<not> be used because a single call to BIO_read() 67*1dcdf01fSchristoscan cause several reads (and writes in the case of SSL BIOs) on the underlying 68*1dcdf01fSchristosI/O structure and may block as a result. Instead select() (or equivalent) 69*1dcdf01fSchristosshould be combined with non blocking I/O so successive reads will request 70*1dcdf01fSchristosa retry instead of blocking. 71*1dcdf01fSchristos 72*1dcdf01fSchristosSee L<BIO_should_retry(3)> for details of how to 73*1dcdf01fSchristosdetermine the cause of a retry and other I/O issues. 74*1dcdf01fSchristos 75*1dcdf01fSchristosIf the BIO_gets() function is not supported by a BIO then it possible to 76*1dcdf01fSchristoswork around this by adding a buffering BIO L<BIO_f_buffer(3)> 77*1dcdf01fSchristosto the chain. 78*1dcdf01fSchristos 79*1dcdf01fSchristos=head1 SEE ALSO 80*1dcdf01fSchristos 81*1dcdf01fSchristosL<BIO_should_retry(3)> 82*1dcdf01fSchristos 83*1dcdf01fSchristos=head1 HISTORY 84*1dcdf01fSchristos 85*1dcdf01fSchristosBIO_gets() on 1.1.0 and older when called on BIO_fd() based BIO does not 86*1dcdf01fSchristoskeep the '\n' at the end of the line in the buffer. 87*1dcdf01fSchristos 88*1dcdf01fSchristos=head1 COPYRIGHT 89*1dcdf01fSchristos 90*1dcdf01fSchristosCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. 91*1dcdf01fSchristos 92*1dcdf01fSchristosLicensed under the OpenSSL license (the "License"). You may not use 93*1dcdf01fSchristosthis file except in compliance with the License. You can obtain a copy 94*1dcdf01fSchristosin the file LICENSE in the source distribution or at 95*1dcdf01fSchristosL<https://www.openssl.org/source/license.html>. 96*1dcdf01fSchristos 97*1dcdf01fSchristos=cut 98