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, BIO_new_accept,
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
37       transferred using only BIO routines. In this way any platform specific
38       operations 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
43       connection.
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
52       connection.
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.  The host can be can be
60       "*" which is interpreted as meaning any interface; "port" has the same
61       syntax as the port specified in BIO_set_conn_port() for connect BIOs,
62       that is it can be a numerical port string or a string to lookup using
63       getservbyname() and a string table.
64
65       BIO_new_accept() combines BIO_new() and BIO_set_accept_port() into a
66       single call: that is it creates a new accept BIO with port host_port.
67
68       BIO_set_nbio_accept() sets the accept socket to blocking mode (the
69       default) if n is 0 or non blocking mode if n is 1.
70
71       BIO_set_accept_bios() can be used to set a chain of BIOs which will be
72       duplicated and prepended to the chain when an incoming connection is
73       received. This is useful if, for example, a buffering or SSL BIO is
74       required for each connection. The chain of BIOs must not be freed after
75       this call, they will be automatically freed when the accept BIO is
76       freed.
77
78       BIO_set_bind_mode() and BIO_get_bind_mode() set and retrieve the
79       current bind mode. If BIO_BIND_NORMAL (the default) is set then another
80       socket cannot be bound to the same port. If BIO_BIND_REUSEADDR is set
81       then other sockets can bind to the same port. If
82       BIO_BIND_REUSEADDR_IF_UNUSED is set then and attempt is first made to
83       use BIO_BIN_NORMAL, if this fails and the port is not in use then a
84       second attempt is made using BIO_BIND_REUSEADDR.
85
86       BIO_do_accept() serves two functions. When it is first called, after
87       the accept BIO has been setup, it will attempt to create the accept
88       socket and bind an address to it. Second and subsequent calls to
89       BIO_do_accept() will await an incoming connection, or request a retry
90       in non blocking mode.
91

NOTES

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

RETURN VALUES

137       TBA
138

EXAMPLE

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

SEE ALSO

184       TBA
185
186
187
1881.0.2o                            2020-01-28                   BIO_s_accept(3)
Impressum