1BIO_s_accept(3)                     OpenSSL                    BIO_s_accept(3)
2
3
4

NAME

6       BIO_s_accept, BIO_set_accept_port, BIO_get_accept_port,
7       BIO_set_nbio_accept, BIO_set_accept_bios, BIO_set_bind_mode,
8       BIO_get_bind_mode, BIO_do_accept - accept BIO
9

SYNOPSIS

11        #include <openssl/bio.h>
12
13        BIO_METHOD *BIO_s_accept(void);
14
15        long BIO_set_accept_port(BIO *b, char *name);
16        char *BIO_get_accept_port(BIO *b);
17
18        BIO *BIO_new_accept(char *host_port);
19
20        long BIO_set_nbio_accept(BIO *b, int n);
21        long BIO_set_accept_bios(BIO *b, char *bio);
22
23        long BIO_set_bind_mode(BIO *b, long mode);
24        long BIO_get_bind_mode(BIO *b, long dummy);
25
26        #define BIO_BIND_NORMAL                0
27        #define BIO_BIND_REUSEADDR_IF_UNUSED   1
28        #define BIO_BIND_REUSEADDR             2
29
30        int BIO_do_accept(BIO *b);
31

DESCRIPTION

33       BIO_s_accept() returns the accept BIO method. This is a wrapper round
34       the platform's TCP/IP socket accept routines.
35
36       Using accept BIOs, TCP/IP connections can be accepted and data trans‐
37       ferred using only BIO routines. In this way any platform specific oper‐
38       ations are hidden by the BIO abstraction.
39
40       Read and write operations on an accept BIO will perform I/O on the
41       underlying connection. If no connection is established and the port
42       (see below) is set up properly then the BIO waits for an incoming con‐
43       nection.
44
45       Accept BIOs support BIO_puts() but not BIO_gets().
46
47       If the close flag is set on an accept BIO then any active connection on
48       that chain is shutdown and the socket closed when the BIO is freed.
49
50       Calling BIO_reset() on a accept BIO will close any active connection
51       and reset the BIO into a state where it awaits another incoming connec‐
52       tion.
53
54       BIO_get_fd() and BIO_set_fd() can be called to retrieve or set the
55       accept socket. See BIO_s_fd(3)
56
57       BIO_set_accept_port() uses the string name to set the accept port. The
58       port is represented as a string of the form "host:port", where "host"
59       is the interface to use and "port" is the port.  Either or both values
60       can be "*" which is interpreted as meaning any interface or port
61       respectively. "port" has the same syntax as the port specified in
62       BIO_set_conn_port() for connect BIOs, that is it can be a numerical
63       port string or a string to lookup using getservbyname() and a string
64       table.
65
66       BIO_new_accept() combines BIO_new() and BIO_set_accept_port() into a
67       single call: that is it creates a new accept BIO with port host_port.
68
69       BIO_set_nbio_accept() sets the accept socket to blocking mode (the
70       default) if n is 0 or non blocking mode if n is 1.
71
72       BIO_set_accept_bios() can be used to set a chain of BIOs which will be
73       duplicated and prepended to the chain when an incoming connection is
74       received. This is useful if, for example, a buffering or SSL BIO is
75       required for each connection. The chain of BIOs must not be freed after
76       this call, they will be automatically freed when the accept BIO is
77       freed.
78
79       BIO_set_bind_mode() and BIO_get_bind_mode() set and retrieve the cur‐
80       rent bind mode. If BIO_BIND_NORMAL (the default) is set then another
81       socket cannot be bound to the same port. If BIO_BIND_REUSEADDR is set
82       then other sockets can bind to the same port. If BIO_BIND_REUSE‐
83       ADDR_IF_UNUSED is set then and attempt is first made to use
84       BIO_BIN_NORMAL, if this fails and the port is not in use then a second
85       attempt is made using BIO_BIND_REUSEADDR.
86
87       BIO_do_accept() serves two functions. When it is first called, after
88       the accept BIO has been setup, it will attempt to create the accept
89       socket and bind an address to it. Second and subsequent calls to
90       BIO_do_accept() will await an incoming connection, or request a retry
91       in non blocking mode.
92

NOTES

94       When an accept BIO is at the end of a chain it will await an incoming
95       connection before processing I/O calls. When an accept BIO is not at
96       then end of a chain it passes I/O calls to the next BIO in the chain.
97
98       When a connection is established a new socket BIO is created for the
99       connection and appended to the chain. That is the chain is now
100       accept->socket. This effectively means that attempting I/O on an ini‐
101       tial accept socket will await an incoming connection then perform I/O
102       on it.
103
104       If any additional BIOs have been set using BIO_set_accept_bios() then
105       they are placed between the socket and the accept BIO, that is the
106       chain will be accept->otherbios->socket.
107
108       If a server wishes to process multiple connections (as is normally the
109       case) then the accept BIO must be made available for further incoming
110       connections. This can be done by waiting for a connection and then
111       calling:
112
113        connection = BIO_pop(accept);
114
115       After this call connection will contain a BIO for the recently estab‐
116       lished connection and accept will now be a single BIO again which can
117       be used to await further incoming connections.  If no further connec‐
118       tions will be accepted the accept can be freed using BIO_free().
119
120       If only a single connection will be processed it is possible to perform
121       I/O using the accept BIO itself. This is often undesirable however
122       because the accept BIO will still accept additional incoming connec‐
123       tions. This can be resolved by using BIO_pop() (see above) and freeing
124       up the accept BIO after the initial connection.
125
126       If the underlying accept socket is non-blocking and BIO_do_accept() is
127       called to await an incoming connection it is possible for
128       BIO_should_io_special() with the reason BIO_RR_ACCEPT. If this happens
129       then it is an indication that an accept attempt would block: the appli‐
130       cation should take appropriate action to wait until the underlying
131       socket has accepted a connection and retry the call.
132
133       BIO_set_accept_port(), BIO_get_accept_port(), BIO_set_nbio_accept(),
134       BIO_set_accept_bios(), BIO_set_bind_mode(), BIO_get_bind_mode() and
135       BIO_do_accept() are macros.
136

RETURN VALUES

138       TBA
139

EXAMPLE

141       This example accepts two connections on port 4444, sends messages down
142       each and finally closes both down.
143
144        BIO *abio, *cbio, *cbio2;
145        ERR_load_crypto_strings();
146        abio = BIO_new_accept("4444");
147
148        /* First call to BIO_accept() sets up accept BIO */
149        if(BIO_do_accept(abio) <= 0) {
150               fprintf(stderr, "Error setting up accept\n");
151               ERR_print_errors_fp(stderr);
152               exit(0);
153        }
154
155        /* Wait for incoming connection */
156        if(BIO_do_accept(abio) <= 0) {
157               fprintf(stderr, "Error accepting connection\n");
158               ERR_print_errors_fp(stderr);
159               exit(0);
160        }
161        fprintf(stderr, "Connection 1 established\n");
162        /* Retrieve BIO for connection */
163        cbio = BIO_pop(abio);
164        BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n");
165        fprintf(stderr, "Sent out data on connection 1\n");
166        /* Wait for another connection */
167        if(BIO_do_accept(abio) <= 0) {
168               fprintf(stderr, "Error accepting connection\n");
169               ERR_print_errors_fp(stderr);
170               exit(0);
171        }
172        fprintf(stderr, "Connection 2 established\n");
173        /* Close accept BIO to refuse further connections */
174        cbio2 = BIO_pop(abio);
175        BIO_free(abio);
176        BIO_puts(cbio2, "Connection 2: Sending out Data on second\n");
177        fprintf(stderr, "Sent out data on connection 2\n");
178
179        BIO_puts(cbio, "Connection 1: Second connection established\n");
180        /* Close the two established connections */
181        BIO_free(cbio);
182        BIO_free(cbio2);
183

SEE ALSO

185       TBA
186
187
188
1890.9.8b                            2002-12-12                   BIO_s_accept(3)
Impressum