5 BIO_read_ex, BIO_write_ex, BIO_read, BIO_write,
6 BIO_gets, BIO_get_line, BIO_puts
11 #include <openssl/bio.h>
13 int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
14 int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
16 int BIO_read(BIO *b, void *data, int dlen);
17 int BIO_gets(BIO *b, char *buf, int size);
18 int BIO_get_line(BIO *b, char *buf, int size);
19 int BIO_write(BIO *b, const void *data, int dlen);
20 int BIO_puts(BIO *b, const char *buf);
24 BIO_read_ex() attempts to read I<dlen> bytes from BIO I<b> and places the data
25 in I<data>. If any bytes were successfully read then the number of bytes read is
26 stored in I<*readbytes>.
28 BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>. If
29 successful then the number of bytes written is stored in I<*written>.
31 BIO_read() attempts to read I<len> bytes from BIO I<b> and places
34 BIO_gets() performs the BIOs "gets" operation and places the data
35 in I<buf>. Usually this operation will attempt to read a line of data
36 from the BIO of maximum length I<size-1>. There are exceptions to this,
37 however; for example, BIO_gets() on a digest BIO will calculate and
38 return the digest and other BIOs may not support BIO_gets() at all.
39 The returned string is always NUL-terminated and the '\n' is preserved
40 if present in the input data.
41 On binary input there may be NUL characters within the string;
42 in this case the return value (if nonnegative) may give an incorrect length.
44 BIO_get_line() attempts to read from BIO <b> a line of data up to the next '\n'
45 or the maximum length I<size-1> is reached and places the data in I<buf>.
46 The returned string is always NUL-terminated and the '\n' is preserved
47 if present in the input data.
48 On binary input there may be NUL characters within the string;
49 in this case the return value (if nonnegative) gives the actual length read.
50 For implementing this, unfortunately the data needs to be read byte-by-byte.
52 BIO_write() attempts to write I<len> bytes from I<buf> to BIO I<b>.
54 BIO_puts() attempts to write a NUL-terminated string I<buf> to BIO I<b>.
58 BIO_read_ex() and BIO_write_ex() return 1 if data was successfully read or
59 written, and 0 otherwise.
61 BIO_write() and BIO_write_ex() return 0 if the BIO I<b> is NULL.
63 BIO_gets() returns -2 if the "gets" operation is not implemented by the BIO
64 or -1 on other errors.
65 Otherwise it typically returns the amount of data read,
66 but depending on the implementation it may return only the length up to
67 the first NUL character contained in the data read.
68 In any case the trailing NUL that is added after the data read
69 is not included in the length returned.
71 All other functions return either the amount of data successfully read or
72 written (if the return value is positive) or that no data was successfully
73 read or written if the result is 0 or -1. If the return value is -2 then
74 the operation is not implemented in the specific BIO type.
78 A 0 or -1 return is not necessarily an indication of an error. In
79 particular when the source/sink is nonblocking or of a certain type
80 it may merely be an indication that no data is currently available and that
81 the application should retry the operation later.
83 One technique sometimes used with blocking sockets is to use a system call
84 (such as select(), poll() or equivalent) to determine when data is available
85 and then call read() to read the data. The equivalent with BIOs (that is call
86 select() on the underlying I/O structure and then call BIO_read() to
87 read the data) should B<not> be used because a single call to BIO_read()
88 can cause several reads (and writes in the case of SSL BIOs) on the underlying
89 I/O structure and may block as a result. Instead select() (or equivalent)
90 should be combined with non blocking I/O so successive reads will request
91 a retry instead of blocking.
93 See L<BIO_should_retry(3)> for details of how to
94 determine the cause of a retry and other I/O issues.
96 If the "gets" method is not supported by a BIO then BIO_get_line() can be used.
97 It is also possible to make BIO_gets() usable even if the "gets" method is not
98 supported by adding a buffering BIO L<BIO_f_buffer(3)> to the chain.
102 L<BIO_should_retry(3)>
106 BIO_gets() on 1.1.0 and older when called on BIO_fd() based BIO did not
107 keep the '\n' at the end of the line in the buffer.
109 BIO_get_line() was added in OpenSSL 3.0.
113 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
115 Licensed under the Apache License 2.0 (the "License"). You may not use
116 this file except in compliance with the License. You can obtain a copy
117 in the file LICENSE in the source distribution or at
118 L<https://www.openssl.org/source/license.html>.