Remove indentation in the NAME section. There's really no need to
[openssl.git] / doc / crypto / BIO_should_retry.pod
1 =pod
2
3 =head1 NAME
4
5 BIO_should_retry, BIO_should_read, BIO_should_write - BIO retry functions
6
7 =head1 SYNOPSIS
8
9  #include <openssl/bio.h>
10
11  #define BIO_should_read(a)             ((a)->flags & BIO_FLAGS_READ)
12  #define BIO_should_write(a)            ((a)->flags & BIO_FLAGS_WRITE)
13  #define BIO_should_io_special(a)       ((a)->flags & BIO_FLAGS_IO_SPECIAL)
14  #define BIO_retry_type(a)              ((a)->flags & BIO_FLAGS_RWS)
15  #define BIO_should_retry(a)            ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
16
17  #define BIO_FLAGS_READ         0x01
18  #define BIO_FLAGS_WRITE        0x02
19  #define BIO_FLAGS_IO_SPECIAL   0x04
20  #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
21  #define BIO_FLAGS_SHOULD_RETRY 0x08
22
23  BIO *  BIO_get_retry_BIO(BIO *bio, int *reason);
24  int    BIO_get_retry_reason(BIO *bio);
25
26 =head1 DESCRIPTION
27
28 These functions determine why a BIO is not able to read or write data.
29 They will typically be called after a failed BIO_read() or BIO_write()
30 call.
31
32 BIO_should_retry() is true if the call that produced this condition
33 should then be retried at a later time.
34
35 If BIO_should_retry() is false then the cause is an error condition.
36
37 BIO_should_read() is true if the cause of the condition is that a BIO
38 needs to read data.
39
40 BIO_should_write() is true if the cause of the condition is that a BIO
41 needs to read data.
42
43 BIO_should_io_special() is true if some "special" condition, that is a
44 reason other than reading or writing is the cause of the condition.
45
46 BIO_get_retry_reason() returns a mask of the cause of a retry condition
47 consisting of the values B<BIO_FLAGS_READ>, B<BIO_FLAGS_WRITE>,
48 B<BIO_FLAGS_IO_SPECIAL> though current BIO types will only set one of
49 these.
50
51 BIO_get_retry_BIO() determines the precise reason for the special
52 condition, it returns the BIO that caused this condition and if 
53 B<reason> is not NULL it contains the reason code. The meaning of
54 the reason code and the action that should be taken depends on
55 the type of BIO that resulted in this condition.
56
57 BIO_get_retry_reason() returns the reason for a special condition if
58 passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
59
60 =head1 NOTES
61
62 If BIO_should_retry() returns false then the precise "error condition"
63 depends on the BIO type that caused it and the return code of the BIO
64 operation. For example if a call to BIO_read() on a socket BIO returns
65 0 and BIO_should_retry() is false then the cause will be that the
66 connection closed. A similar condition on a file BIO will mean that it
67 has reached EOF. Some BIO types may place additional information on
68 the error queue. For more details see the individual BIO type manual
69 pages.
70
71 If the underlying I/O structure is in a blocking mode almost all current
72 BIO types will not request a retry, because the underlying I/O
73 calls will not. If the application knows that the BIO type will never
74 signal a retry then it need not call BIO_should_retry() after a failed
75 BIO I/O call. This is typically done with file BIOs.
76
77 SSL BIOs are the only current exception to this rule: they can request a
78 retry even if the underlying I/O structure is blocking, if a handshake
79 occurs during a call to BIO_read(). An application can retry the failed
80 call immediately or avoid this situation by setting SSL_MODE_AUTO_RETRY
81 on the underlying SSL structure.
82
83 While an application may retry a failed non blocking call immediately
84 this is likely to be very inefficient because the call will fail
85 repeatedly until data can be processed or is available. An application
86 will normally wait until the necessary condition is satisfied. How
87 this is done depends on the underlying I/O structure.
88
89 For example if the cause is ultimately a socket and BIO_should_read()
90 is true then a call to select() may be made to wait until data is
91 available and then retry the BIO operation. By combining the retry
92 conditions of several non blocking BIOs in a single select() call
93 it is possible to service several BIOs in a single thread, though
94 the performance may be poor if SSL BIOs are present because long delays
95 can occur during the initial handshake process. 
96
97 It is possible for a BIO to block indefinitely if the underlying I/O
98 structure cannot process or return any data. This depends on the behaviour of
99 the platforms I/O functions. This is often not desirable: one solution
100 is to use non blocking I/O and use a timeout on the select() (or
101 equivalent) call.
102
103 =head1 BUGS
104
105 The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O:
106 that is they cannot retry after a partial read or write. This is usually
107 worked around by only passing the relevant data to ASN1 functions when
108 the entire structure can be read or written.
109
110 =head1 SEE ALSO
111
112 TBA