1 | =pod
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | BIO_read_ex, BIO_write_ex, BIO_read, BIO_write,
|
---|
6 | BIO_gets, BIO_get_line, BIO_puts
|
---|
7 | - BIO I/O functions
|
---|
8 |
|
---|
9 | =head1 SYNOPSIS
|
---|
10 |
|
---|
11 | #include <openssl/bio.h>
|
---|
12 |
|
---|
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);
|
---|
15 |
|
---|
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);
|
---|
21 |
|
---|
22 | =head1 DESCRIPTION
|
---|
23 |
|
---|
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>.
|
---|
27 |
|
---|
28 | BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>.
|
---|
29 | If successful then the number of bytes written is stored in I<*written>
|
---|
30 | unless I<written> is NULL.
|
---|
31 |
|
---|
32 | BIO_read() attempts to read I<len> bytes from BIO I<b> and places
|
---|
33 | the data in I<buf>.
|
---|
34 |
|
---|
35 | BIO_gets() performs the BIOs "gets" operation and places the data
|
---|
36 | in I<buf>. Usually this operation will attempt to read a line of data
|
---|
37 | from the BIO of maximum length I<size-1>. There are exceptions to this,
|
---|
38 | however; for example, BIO_gets() on a digest BIO will calculate and
|
---|
39 | return the digest and other BIOs may not support BIO_gets() at all.
|
---|
40 | The returned string is always NUL-terminated and the '\n' is preserved
|
---|
41 | if present in the input data.
|
---|
42 | On binary input there may be NUL characters within the string;
|
---|
43 | in this case the return value (if nonnegative) may give an incorrect length.
|
---|
44 |
|
---|
45 | BIO_get_line() attempts to read from BIO <b> a line of data up to the next '\n'
|
---|
46 | or the maximum length I<size-1> is reached and places the data in I<buf>.
|
---|
47 | The returned string is always NUL-terminated and the '\n' is preserved
|
---|
48 | if present in the input data.
|
---|
49 | On binary input there may be NUL characters within the string;
|
---|
50 | in this case the return value (if nonnegative) gives the actual length read.
|
---|
51 | For implementing this, unfortunately the data needs to be read byte-by-byte.
|
---|
52 |
|
---|
53 | BIO_write() attempts to write I<len> bytes from I<buf> to BIO I<b>.
|
---|
54 |
|
---|
55 | BIO_puts() attempts to write a NUL-terminated string I<buf> to BIO I<b>.
|
---|
56 |
|
---|
57 | =head1 RETURN VALUES
|
---|
58 |
|
---|
59 | BIO_read_ex() returns 1 if data was successfully read, and 0 otherwise.
|
---|
60 |
|
---|
61 | BIO_write_ex() returns 1 if no error was encountered writing data, 0 otherwise.
|
---|
62 | Requesting to write 0 bytes is not considered an error.
|
---|
63 |
|
---|
64 | BIO_write() returns -2 if the "write" operation is not implemented by the BIO
|
---|
65 | or -1 on other errors.
|
---|
66 | Otherwise it returns the number of bytes written.
|
---|
67 | This may be 0 if the BIO I<b> is NULL or I<dlen <= 0>.
|
---|
68 |
|
---|
69 | BIO_gets() returns -2 if the "gets" operation is not implemented by the BIO
|
---|
70 | or -1 on other errors.
|
---|
71 | Otherwise it typically returns the amount of data read,
|
---|
72 | but depending on the implementation it may return only the length up to
|
---|
73 | the first NUL character contained in the data read.
|
---|
74 | In any case the trailing NUL that is added after the data read
|
---|
75 | is not included in the length returned.
|
---|
76 |
|
---|
77 | All other functions return either the amount of data successfully read or
|
---|
78 | written (if the return value is positive) or that no data was successfully
|
---|
79 | read or written if the result is 0 or -1. If the return value is -2 then
|
---|
80 | the operation is not implemented in the specific BIO type.
|
---|
81 |
|
---|
82 | =head1 NOTES
|
---|
83 |
|
---|
84 | A 0 or -1 return is not necessarily an indication of an error. In
|
---|
85 | particular when the source/sink is nonblocking or of a certain type
|
---|
86 | it may merely be an indication that no data is currently available and that
|
---|
87 | the application should retry the operation later.
|
---|
88 |
|
---|
89 | One technique sometimes used with blocking sockets is to use a system call
|
---|
90 | (such as select(), poll() or equivalent) to determine when data is available
|
---|
91 | and then call read() to read the data. The equivalent with BIOs (that is call
|
---|
92 | select() on the underlying I/O structure and then call BIO_read() to
|
---|
93 | read the data) should B<not> be used because a single call to BIO_read()
|
---|
94 | can cause several reads (and writes in the case of SSL BIOs) on the underlying
|
---|
95 | I/O structure and may block as a result. Instead select() (or equivalent)
|
---|
96 | should be combined with non blocking I/O so successive reads will request
|
---|
97 | a retry instead of blocking.
|
---|
98 |
|
---|
99 | See L<BIO_should_retry(3)> for details of how to
|
---|
100 | determine the cause of a retry and other I/O issues.
|
---|
101 |
|
---|
102 | If the "gets" method is not supported by a BIO then BIO_get_line() can be used.
|
---|
103 | It is also possible to make BIO_gets() usable even if the "gets" method is not
|
---|
104 | supported by adding a buffering BIO L<BIO_f_buffer(3)> to the chain.
|
---|
105 |
|
---|
106 | =head1 SEE ALSO
|
---|
107 |
|
---|
108 | L<BIO_should_retry(3)>
|
---|
109 |
|
---|
110 | =head1 HISTORY
|
---|
111 |
|
---|
112 | BIO_gets() on 1.1.0 and older when called on BIO_fd() based BIO did not
|
---|
113 | keep the '\n' at the end of the line in the buffer.
|
---|
114 |
|
---|
115 | BIO_get_line() was added in OpenSSL 3.0.
|
---|
116 |
|
---|
117 | BIO_write_ex() returns 1 if the size of the data to write is 0 and the
|
---|
118 | I<written> parameter of the function can be NULL since OpenSSL 3.0.
|
---|
119 |
|
---|
120 | =head1 COPYRIGHT
|
---|
121 |
|
---|
122 | Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
|
---|
123 |
|
---|
124 | Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
125 | this file except in compliance with the License. You can obtain a copy
|
---|
126 | in the file LICENSE in the source distribution or at
|
---|
127 | L<https://www.openssl.org/source/license.html>.
|
---|
128 |
|
---|
129 | =cut
|
---|