Debian Codegraph @

upstream/debian-unstable/man3/BIO_read.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "BIO_READ 3SSL"
58 .TH BIO_READ 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 BIO_read_ex, BIO_write_ex, BIO_read, BIO_write,
65 BIO_gets, BIO_get_line, BIO_puts
66 \&\- BIO I/O functions
67 .SH SYNOPSIS
68 .IX Header "SYNOPSIS"
69 .Vb 1
70 \& #include <openssl/bio.h>
71 \&
72 \& int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
73 \& int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
74 \&
75 \& int BIO_read(BIO *b, void *data, int dlen);
76 \& int BIO_gets(BIO *b, char *buf, int size);
77 \& int BIO_get_line(BIO *b, char *buf, int size);
78 \& int BIO_write(BIO *b, const void *data, int dlen);
79 \& int BIO_puts(BIO *b, const char *buf);
80 .Ve
81 .SH DESCRIPTION
82 .IX Header "DESCRIPTION"
83 \&\fBBIO_read_ex()\fR attempts to read \fIdlen\fR bytes from BIO \fIb\fR and places the data
84 in \fIdata\fR. If any bytes were successfully read then the number of bytes read is
85 stored in \fI*readbytes\fR.
86 .PP
87 \&\fBBIO_write_ex()\fR attempts to write \fIdlen\fR bytes from \fIdata\fR to BIO \fIb\fR.
88 If successful then the number of bytes written is stored in \fI*written\fR
89 unless \fIwritten\fR is NULL.
90 .PP
91 \&\fBBIO_read()\fR attempts to read \fIlen\fR bytes from BIO \fIb\fR and places
92 the data in \fIbuf\fR.
93 .PP
94 \&\fBBIO_gets()\fR performs the BIOs "gets" operation and places the data
95 in \fIbuf\fR. Usually this operation will attempt to read a line of data
96 from the BIO of maximum length \fIsize\-1\fR. There are exceptions to this,
97 however; for example, \fBBIO_gets()\fR on a digest BIO will calculate and
98 return the digest and other BIOs may not support \fBBIO_gets()\fR at all.
99 The returned string is always NUL-terminated and the '\en' is preserved
100 if present in the input data.
101 On binary input there may be NUL characters within the string;
102 in this case the return value (if nonnegative) may give an incorrect length.
103 .PP
104 \&\fBBIO_get_line()\fR attempts to read from BIO \fIb\fR a line of data up to the next '\en'
105 or the maximum length \fIsize\-1\fR is reached and places the data in \fIbuf\fR.
106 The returned string is always NUL-terminated and the '\en' is preserved
107 if present in the input data.
108 On binary input there may be NUL characters within the string;
109 in this case the return value (if nonnegative) gives the actual length read.
110 For implementing this, unfortunately the data needs to be read byte-by-byte.
111 .PP
112 \&\fBBIO_write()\fR attempts to write \fIlen\fR bytes from \fIbuf\fR to BIO \fIb\fR.
113 .PP
114 \&\fBBIO_puts()\fR attempts to write a NUL-terminated string \fIbuf\fR to BIO \fIb\fR,
115 without the terminating NUL byte and without appending '\en'
116 (so, similar to \fBfputs\fR\|(3), and not \fBputs\fR\|(3)).
117 .SH "RETURN VALUES"
118 .IX Header "RETURN VALUES"
119 \&\fBBIO_read_ex()\fR returns 1 if data was successfully read, and 0 otherwise.
120 .PP
121 \&\fBBIO_write_ex()\fR returns 1 if no error was encountered writing data, 0 otherwise.
122 Requesting to write 0 bytes is not considered an error.
123 .PP
124 \&\fBBIO_write()\fR returns \-2 if the "write" operation is not implemented by the BIO
125 or \-1 on other errors.
126 Otherwise it returns the number of bytes written.
127 This may be 0 if the BIO \fIb\fR is NULL or \fIdlen <= 0\fR.
128 .PP
129 \&\fBBIO_gets()\fR returns \-2 if the "gets" operation is not implemented by the BIO
130 or \-1 on other errors.
131 Otherwise it typically returns the amount of data read,
132 but depending on the implementation it may return only the length up to
133 the first NUL character contained in the data read.
134 In any case the trailing NUL that is added after the data read
135 is not included in the length returned.
136 .PP
137 All other functions return either the amount of data successfully read or
138 written (if the return value is positive) or that no data was successfully
139 read or written if the result is 0 or \-1. If the return value is \-2 then
140 the operation is not implemented in the specific BIO type.
141 .SH NOTES
142 .IX Header "NOTES"
143 A 0 or \-1 return is not necessarily an indication of an error. In
144 particular when the source/sink is nonblocking or of a certain type
145 it may merely be an indication that no data is currently available and that
146 the application should retry the operation later.
147 .PP
148 One technique sometimes used with blocking sockets is to use a system call
149 (such as \fBselect()\fR, \fBpoll()\fR or equivalent) to determine when data is available
150 and then call \fBread()\fR to read the data. The equivalent with BIOs (that is call
151 \&\fBselect()\fR on the underlying I/O structure and then call \fBBIO_read()\fR to
152 read the data) should \fBnot\fR be used because a single call to \fBBIO_read()\fR
153 can cause several reads (and writes in the case of SSL BIOs) on the underlying
154 I/O structure and may block as a result. Instead \fBselect()\fR (or equivalent)
155 should be combined with non blocking I/O so successive reads will request
156 a retry instead of blocking.
157 .PP
158 See \fBBIO_should_retry\fR\|(3) for details of how to
159 determine the cause of a retry and other I/O issues.
160 .PP
161 If the "gets" method is not supported by a BIO then \fBBIO_get_line()\fR can be used.
162 It is also possible to make \fBBIO_gets()\fR usable even if the "gets" method is not
163 supported by adding a buffering BIO \fBBIO_f_buffer\fR\|(3) to the chain.
164 .SH "SEE ALSO"
165 .IX Header "SEE ALSO"
166 \&\fBBIO_should_retry\fR\|(3)
167 .SH HISTORY
168 .IX Header "HISTORY"
169 \&\fBBIO_gets()\fR on 1.1.0 and older when called on \fBBIO_fd()\fR based BIO did not
170 keep the '\en' at the end of the line in the buffer.
171 .PP
172 \&\fBBIO_get_line()\fR was added in OpenSSL 3.0.
173 .PP
174 \&\fBBIO_write_ex()\fR returns 1 if the size of the data to write is 0 and the
175 \&\fIwritten\fR parameter of the function can be NULL since OpenSSL 3.0.
176 .SH COPYRIGHT
177 .IX Header "COPYRIGHT"
178 Copyright 2000\-2026 The OpenSSL Project Authors. All Rights Reserved.
179 .PP
180 Licensed under the Apache License 2.0 (the "License"). You may not use
181 this file except in compliance with the License. You can obtain a copy
182 in the file LICENSE in the source distribution or at
183 <https://www.openssl.org/source/license.html>.