
#use wml::openssl-macros area=docs page=BIO_read

<title>Documents, BIO_read(3)</title>

<h1>BIO_read(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BIO_read, BIO_write, BIO_gets, BIO_puts - BIO I/O functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bio.h&gt;
</PRE>
<PRE> int    BIO_read(BIO *b, void *buf, int len);
 int    BIO_gets(BIO *b,char *buf, int size);
 int    BIO_write(BIO *b, const void *buf, int len);
 int    BIO_puts(BIO *b,const char *buf);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BIO_read()</CODE> attempts to read <STRONG>len</STRONG> bytes from BIO <STRONG>b</STRONG> and places the data in <STRONG>buf</STRONG>.

</P>
<P>
<CODE>BIO_gets()</CODE> performs the BIOs ``gets'' operation and places the
data in <STRONG>buf</STRONG>. Usually this operation will attempt to read a line of data from the BIO
of maximum length <STRONG>len</STRONG>. There are exceptions to this however, for example <CODE>BIO_gets()</CODE>
on a digest BIO will calculate and return the digest and other BIOs may not
support <CODE>BIO_gets()</CODE> at all.

</P>
<P>
<CODE>BIO_write()</CODE> attempts to write <STRONG>len</STRONG> bytes from <STRONG>buf</STRONG> to BIO <STRONG>b</STRONG>.

</P>
<P>
<CODE>BIO_puts()</CODE> attempts to write a null terminated string <STRONG>buf</STRONG> to BIO <STRONG>b</STRONG>



</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
All these functions return either the amount of data successfully read or
written (if the return value is positive) or that no data was successfully
read or written if the result is 0 or -1. If the return value is -2 then
the operation is not implemented in the specific BIO type.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
A 0 or -1 return is not necessarily an indication of an error. In
particular when the source/sink is non-blocking or of a certain type it may
merely be an indication that no data is currently available and that the
application should retry the operation later.

</P>
<P>
One technique sometimes used with blocking sockets is to use a system call
(such as <CODE>select(),</CODE> <CODE>poll()</CODE> or equivalent) to
determine when data is available and then call <CODE>read()</CODE> to read
the data. The equivalent with BIOs (that is call <CODE>select()</CODE> on
the underlying I/O structure and then call <CODE>BIO_read()</CODE> to read
the data) should <STRONG>not</STRONG> be used because a single call to <CODE>BIO_read()</CODE> can cause several
reads (and writes in the case of SSL BIOs) on the underlying I/O structure
and may block as a result. Instead <CODE>select()</CODE> (or equivalent)
should be combined with non blocking I/O so successive reads will request a
retry instead of blocking.

</P>
<P>
See <A HREF="../crypto/BIO_should_retry.html#">BIO_should_retry(3)</A> for details of how to determine the cause of a retry and other I/O issues.

</P>
<P>
If the <CODE>BIO_gets()</CODE> function is not supported by a BIO then it
possible to work around this by adding a buffering BIO <A HREF="../crypto/BIO_f_buffer.html#">BIO_f_buffer(3)</A>
to the chain.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/BIO_should_retry.html#">BIO_should_retry(3)</A>



</P>
<P>
TBA
</P>
:}

