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