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

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

<h1>BIO_should_retry(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="#NOTES">NOTES</A>
	<LI><A HREF="#BUGS">BUGS</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BIO_should_retry, BIO_should_read, BIO_should_write, BIO_should_io_special,
BIO_retry_type, BIO_should_retry, BIO_get_retry_BIO, BIO_get_retry_reason -
BIO retry functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bio.h&gt;
</PRE>
<PRE> #define BIO_should_read(a)             ((a)-&gt;flags &amp; BIO_FLAGS_READ)
 \#define BIO_should_write(a)            ((a)-&gt;flags &amp; BIO_FLAGS_WRITE)
 \#define BIO_should_io_special(a)       ((a)-&gt;flags &amp; BIO_FLAGS_IO_SPECIAL)
 \#define BIO_retry_type(a)              ((a)-&gt;flags &amp; BIO_FLAGS_RWS)
 \#define BIO_should_retry(a)            ((a)-&gt;flags &amp; BIO_FLAGS_SHOULD_RETRY)
</PRE>
<PRE> #define BIO_FLAGS_READ         0x01
 \#define BIO_FLAGS_WRITE        0x02
 \#define BIO_FLAGS_IO_SPECIAL   0x04
 \#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
 \#define BIO_FLAGS_SHOULD_RETRY 0x08
</PRE>
<PRE> BIO *  BIO_get_retry_BIO(BIO *bio, int *reason);
 int    BIO_get_retry_reason(BIO *bio);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
These functions determine why a BIO is not able to read or write data. They
will typically be called after a failed <CODE>BIO_read()</CODE> or
<CODE>BIO_write()</CODE> call.

</P>
<P>
<CODE>BIO_should_retry()</CODE> is true if the call that produced this
condition should then be retried at a later time.

</P>
<P>
If <CODE>BIO_should_retry()</CODE> is false then the cause is an error
condition.

</P>
<P>
<CODE>BIO_should_read()</CODE> is true if the cause of the condition is
that a BIO needs to read data.

</P>
<P>
<CODE>BIO_should_write()</CODE> is true if the cause of the condition is
that a BIO needs to read data.

</P>
<P>
<CODE>BIO_should_io_special()</CODE> is true if some ``special'' condition,
that is a reason other than reading or writing is the cause of the
condition.

</P>
<P>
<CODE>BIO_get_retry_reason()</CODE> returns a mask of the cause of a retry
condition consisting of the values <STRONG>BIO_FLAGS_READ</STRONG>, <STRONG>BIO_FLAGS_WRITE</STRONG>,
<STRONG>BIO_FLAGS_IO_SPECIAL</STRONG> though current BIO types will only set one of these.

</P>
<P>
<CODE>BIO_get_retry_BIO()</CODE> determines the precise reason for the
special condition, it returns the BIO that caused this condition and if 
<STRONG>reason</STRONG> is not NULL it contains the reason code. The meaning of the reason code and
the action that should be taken depends on the type of BIO that resulted in
this condition.

</P>
<P>
<CODE>BIO_get_retry_reason()</CODE> returns the reason for a special
condition if passed the relevant BIO, for example as returned by
<CODE>BIO_get_retry_BIO().</CODE>

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
If <CODE>BIO_should_retry()</CODE> returns false then the precise ``error
condition'' depends on the BIO type that caused it and the return code of
the BIO operation. For example if a call to <CODE>BIO_read()</CODE> on a
socket BIO returns 0 and <CODE>BIO_should_retry()</CODE> is false then the
cause will be that the connection closed. A similar condition on a file BIO
will mean that it has reached EOF. Some BIO types may place additional
information on the error queue. For more details see the individual BIO
type manual pages.

</P>
<P>
If the underlying I/O structure is in a blocking mode almost all current
BIO types will not request a retry, because the underlying I/O calls will
not. If the application knows that the BIO type will never signal a retry
then it need not call <CODE>BIO_should_retry()</CODE> after a failed BIO
I/O call. This is typically done with file BIOs.

</P>
<P>
SSL BIOs are the only current exception to this rule: they can request a
retry even if the underlying I/O structure is blocking, if a handshake
occurs during a call to <CODE>BIO_read().</CODE> An application can retry
the failed call immediately or avoid this situation by setting
SSL_MODE_AUTO_RETRY on the underlying SSL structure.

</P>
<P>
While an application may retry a failed non blocking call immediately this
is likely to be very inefficient because the call will fail repeatedly
until data can be processed or is available. An application will normally
wait until the necessary condition is satisfied. How this is done depends
on the underlying I/O structure.

</P>
<P>
For example if the cause is ultimately a socket and
<CODE>BIO_should_read()</CODE> is true then a call to <CODE>select()</CODE>
may be made to wait until data is available and then retry the BIO
operation. By combining the retry conditions of several non blocking BIOs
in a single <CODE>select()</CODE> call it is possible to service several
BIOs in a single thread, though the performance may be poor if SSL BIOs are
present because long delays can occur during the initial handshake process. 

</P>
<P>
It is possible for a BIO to block indefinitely if the underlying I/O
structure cannot process or return any data. This depends on the behaviour
of the platforms I/O functions. This is often not desirable: one solution
is to use non blocking I/O and use a timeout on the <CODE>select()</CODE>
(or equivalent) call.

</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
that is they cannot retry after a partial read or write. This is usually
worked around by only passing the relevant data to ASN1 functions when the
entire structure can be read or written.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
TBA
</P>
:}

