diff options
Diffstat (limited to 'src/lib/libcrypto/man/BIO_s_accept.3')
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_accept.3 | 279 |
1 files changed, 279 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/BIO_s_accept.3 b/src/lib/libcrypto/man/BIO_s_accept.3 new file mode 100644 index 0000000000..f5adfcc07c --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_accept.3 | |||
| @@ -0,0 +1,279 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_ACCEPT 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_accept , | ||
| 6 | .Nm BIO_set_accept_port , | ||
| 7 | .Nm BIO_get_accept_port , | ||
| 8 | .Nm BIO_new_accept , | ||
| 9 | .Nm BIO_set_nbio_accept , | ||
| 10 | .Nm BIO_set_accept_bios , | ||
| 11 | .Nm BIO_set_bind_mode , | ||
| 12 | .Nm BIO_get_bind_mode , | ||
| 13 | .Nm BIO_do_accept | ||
| 14 | .Nd accept BIO | ||
| 15 | .Sh SYNOPSIS | ||
| 16 | .In openssl/bio.h | ||
| 17 | .Ft BIO_METHOD * | ||
| 18 | .Fo BIO_s_accept | ||
| 19 | .Fa void | ||
| 20 | .Fc | ||
| 21 | .Ft long | ||
| 22 | .Fo BIO_set_accept_port | ||
| 23 | .Fa "BIO *b" | ||
| 24 | .Fa "char *name" | ||
| 25 | .Fc | ||
| 26 | .Ft char * | ||
| 27 | .Fo BIO_get_accept_port | ||
| 28 | .Fa "BIO *b" | ||
| 29 | .Fc | ||
| 30 | .Ft BIO * | ||
| 31 | .Fo BIO_new_accept | ||
| 32 | .Fa "char *host_port" | ||
| 33 | .Fc | ||
| 34 | .Ft long | ||
| 35 | .Fo BIO_set_nbio_accept | ||
| 36 | .Fa "BIO *b" | ||
| 37 | .Fa "int n" | ||
| 38 | .Fc | ||
| 39 | .Ft long | ||
| 40 | .Fo BIO_set_accept_bios | ||
| 41 | .Fa "BIO *b" | ||
| 42 | .Fa "char *bio" | ||
| 43 | .Fc | ||
| 44 | .Ft long | ||
| 45 | .Fo BIO_set_bind_mode | ||
| 46 | .Fa "BIO *b" | ||
| 47 | .Fa "long mode" | ||
| 48 | .Fc | ||
| 49 | .Ft long | ||
| 50 | .Fo BIO_get_bind_mode | ||
| 51 | .Fa "BIO *b" | ||
| 52 | .Fa "long dummy" | ||
| 53 | .Fc | ||
| 54 | .Fd #define BIO_BIND_NORMAL 0 | ||
| 55 | .Fd #define BIO_BIND_REUSEADDR_IF_UNUSED 1 | ||
| 56 | .Fd #define BIO_BIND_REUSEADDR 2 | ||
| 57 | .Ft int | ||
| 58 | .Fo BIO_do_accept | ||
| 59 | .Fa "BIO *b" | ||
| 60 | .Fc | ||
| 61 | .Sh DESCRIPTION | ||
| 62 | .Fn BIO_s_accept | ||
| 63 | returns the accept BIO method. | ||
| 64 | This is a wrapper round the platform's TCP/IP socket accept routines. | ||
| 65 | .Pp | ||
| 66 | Using accept BIOs, TCP/IP connections can be accepted | ||
| 67 | and data transferred using only BIO routines. | ||
| 68 | In this way any platform specific operations | ||
| 69 | are hidden by the BIO abstraction. | ||
| 70 | .Pp | ||
| 71 | Read and write operations on an accept BIO | ||
| 72 | will perform I/O on the underlying connection. | ||
| 73 | If no connection is established and the port (see below) is set up | ||
| 74 | properly then the BIO waits for an incoming connection. | ||
| 75 | .Pp | ||
| 76 | Accept BIOs support | ||
| 77 | .Xr BIO_puts 3 | ||
| 78 | but not | ||
| 79 | .Xr BIO_gets 3 . | ||
| 80 | .Pp | ||
| 81 | If the close flag is set on an accept BIO, then any active | ||
| 82 | connection on that chain is shutdown and the socket closed when | ||
| 83 | the BIO is freed. | ||
| 84 | .Pp | ||
| 85 | Calling | ||
| 86 | .Xr BIO_reset 3 | ||
| 87 | on a accept BIO will close any active connection and reset the BIO | ||
| 88 | into a state where it awaits another incoming connection. | ||
| 89 | .Pp | ||
| 90 | .Xr BIO_get_fd 3 | ||
| 91 | and | ||
| 92 | .Xr BIO_set_fd 3 | ||
| 93 | can be called to retrieve or set the accept socket. | ||
| 94 | See | ||
| 95 | .Xr BIO_s_fd 3 . | ||
| 96 | .Pp | ||
| 97 | .Fn BIO_set_accept_port | ||
| 98 | uses the string | ||
| 99 | .Fa name | ||
| 100 | to set the accept port. | ||
| 101 | The port is represented as a string of the form | ||
| 102 | .Ar host : Ns Ar port , | ||
| 103 | where | ||
| 104 | .Ar host | ||
| 105 | is the interface to use and | ||
| 106 | .Ar port | ||
| 107 | is the port. | ||
| 108 | Either or both values can be | ||
| 109 | .Qq * | ||
| 110 | which is interpreted as meaning any interface or port respectively. | ||
| 111 | .Ar port | ||
| 112 | has the same syntax as the port specified in | ||
| 113 | .Xr BIO_set_conn_port 3 | ||
| 114 | for connect BIOs. | ||
| 115 | It can be a numerical port string or a string to lookup using | ||
| 116 | .Xr getservbyname 3 | ||
| 117 | and a string table. | ||
| 118 | .Pp | ||
| 119 | .Fn BIO_new_accept | ||
| 120 | combines | ||
| 121 | .Xr BIO_new 3 | ||
| 122 | and | ||
| 123 | .Fn BIO_set_accept_port | ||
| 124 | into a single call. | ||
| 125 | It creates a new accept BIO with port | ||
| 126 | .Fa host_port . | ||
| 127 | .Pp | ||
| 128 | .Fn BIO_set_nbio_accept | ||
| 129 | sets the accept socket to blocking mode (the default) if | ||
| 130 | .Fa n | ||
| 131 | is 0 or non blocking mode if | ||
| 132 | .Fa n | ||
| 133 | is 1. | ||
| 134 | .Pp | ||
| 135 | .Fn BIO_set_accept_bios | ||
| 136 | can be used to set a chain of BIOs which will be duplicated | ||
| 137 | and prepended to the chain when an incoming connection is received. | ||
| 138 | This is useful if, for example, a buffering or SSL BIO | ||
| 139 | is required for each connection. | ||
| 140 | The chain of BIOs must not be freed after this call, | ||
| 141 | they will be automatically freed when the accept BIO is freed. | ||
| 142 | .Pp | ||
| 143 | .Fn BIO_set_bind_mode | ||
| 144 | and | ||
| 145 | .Fn BIO_get_bind_mode | ||
| 146 | set and retrieve the current bind mode. | ||
| 147 | If | ||
| 148 | .Dv BIO_BIND_NORMAL Pq the default | ||
| 149 | is set, then another socket cannot be bound to the same port. | ||
| 150 | If | ||
| 151 | .Dv BIO_BIND_REUSEADDR | ||
| 152 | is set, then other sockets can bind to the same port. | ||
| 153 | If | ||
| 154 | .Dv BIO_BIND_REUSEADDR_IF_UNUSED | ||
| 155 | is set, then an attempt is first made to use | ||
| 156 | .Dv BIO_BIN_NORMAL ; | ||
| 157 | if this fails and the port is not in use, | ||
| 158 | then a second attempt is made using | ||
| 159 | .Dv BIO_BIND_REUSEADDR . | ||
| 160 | .Pp | ||
| 161 | .Fn BIO_do_accept | ||
| 162 | serves two purposes. | ||
| 163 | When it is first called, after the accept BIO has been setup, | ||
| 164 | it will attempt to create the accept socket and bind an address to it. | ||
| 165 | Second and subsequent calls to | ||
| 166 | .Fn BIO_do_accept | ||
| 167 | will await an incoming connection, or request a retry in non blocking mode. | ||
| 168 | .Sh NOTES | ||
| 169 | When an accept BIO is at the end of a chain, it will await an | ||
| 170 | incoming connection before processing I/O calls. | ||
| 171 | When an accept BIO is not at then end of a chain, | ||
| 172 | it passes I/O calls to the next BIO in the chain. | ||
| 173 | .Pp | ||
| 174 | When a connection is established a new socket BIO is created | ||
| 175 | for the connection and appended to the chain. | ||
| 176 | That is the chain is now accept->socket. | ||
| 177 | This effectively means that attempting I/O on an initial accept | ||
| 178 | socket will await an incoming connection then perform I/O on it. | ||
| 179 | .Pp | ||
| 180 | If any additional BIOs have been set using | ||
| 181 | .Fn BIO_set_accept_bios , | ||
| 182 | then they are placed between the socket and the accept BIO, | ||
| 183 | that is the chain will be accept->otherbios->socket. | ||
| 184 | .Pp | ||
| 185 | If a server wishes to process multiple connections (as is normally | ||
| 186 | the case), then the accept BIO must be made available for further | ||
| 187 | incoming connections. | ||
| 188 | This can be done by waiting for a connection and then calling: | ||
| 189 | .Pp | ||
| 190 | .Dl connection = BIO_pop(accept); | ||
| 191 | .Pp | ||
| 192 | After this call, | ||
| 193 | .Sy connection | ||
| 194 | will contain a BIO for the recently established connection and | ||
| 195 | .Sy accept | ||
| 196 | will now be a single BIO again which can be used | ||
| 197 | to await further incoming connections. | ||
| 198 | If no further connections will be accepted, the | ||
| 199 | .Sy accept | ||
| 200 | can be freed using | ||
| 201 | .Xr BIO_free 3 . | ||
| 202 | .Pp | ||
| 203 | If only a single connection will be processed, | ||
| 204 | it is possible to perform I/O using the accept BIO itself. | ||
| 205 | This is often undesirable however because the accept BIO | ||
| 206 | will still accept additional incoming connections. | ||
| 207 | This can be resolved by using | ||
| 208 | .Xr BIO_pop 3 | ||
| 209 | (see above) and freeing up the accept BIO after the initial connection. | ||
| 210 | .Pp | ||
| 211 | If the underlying accept socket is non-blocking and | ||
| 212 | .Fn BIO_do_accept | ||
| 213 | is called to await an incoming connection, it is possible for | ||
| 214 | .Xr BIO_should_io_special 3 | ||
| 215 | with the reason | ||
| 216 | .Dv BIO_RR_ACCEPT . | ||
| 217 | If this happens, then it is an indication that an accept attempt | ||
| 218 | would block: the application should take appropriate action | ||
| 219 | to wait until the underlying socket has accepted a connection | ||
| 220 | and retry the call. | ||
| 221 | .Pp | ||
| 222 | .Fn BIO_set_accept_port , | ||
| 223 | .Fn BIO_get_accept_port , | ||
| 224 | .Fn BIO_set_nbio_accept , | ||
| 225 | .Fn BIO_set_accept_bios , | ||
| 226 | .Fn BIO_set_bind_mode , | ||
| 227 | .Fn BIO_get_bind_mode , | ||
| 228 | and | ||
| 229 | .Fn BIO_do_accept | ||
| 230 | are macros. | ||
| 231 | .Sh EXAMPLES | ||
| 232 | This example accepts two connections on port 4444, | ||
| 233 | sends messages down each and finally closes both down. | ||
| 234 | .Bd -literal -offset 2n | ||
| 235 | BIO *abio, *cbio, *cbio2; | ||
| 236 | ERR_load_crypto_strings(); | ||
| 237 | abio = BIO_new_accept("4444"); | ||
| 238 | |||
| 239 | /* First call to BIO_accept() sets up accept BIO */ | ||
| 240 | if (BIO_do_accept(abio) <= 0) { | ||
| 241 | fprintf(stderr, "Error setting up accept\en"); | ||
| 242 | ERR_print_errors_fp(stderr); | ||
| 243 | exit(0); | ||
| 244 | } | ||
| 245 | |||
| 246 | /* Wait for incoming connection */ | ||
| 247 | if (BIO_do_accept(abio) <= 0) { | ||
| 248 | fprintf(stderr, "Error accepting connection\en"); | ||
| 249 | ERR_print_errors_fp(stderr); | ||
| 250 | exit(0); | ||
| 251 | } | ||
| 252 | fprintf(stderr, "Connection 1 established\en"); | ||
| 253 | |||
| 254 | /* Retrieve BIO for connection */ | ||
| 255 | cbio = BIO_pop(abio); | ||
| 256 | |||
| 257 | BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\en"); | ||
| 258 | fprintf(stderr, "Sent out data on connection 1\en"); | ||
| 259 | |||
| 260 | /* Wait for another connection */ | ||
| 261 | if (BIO_do_accept(abio) <= 0) { | ||
| 262 | fprintf(stderr, "Error accepting connection\en"); | ||
| 263 | ERR_print_errors_fp(stderr); | ||
| 264 | exit(0); | ||
| 265 | } | ||
| 266 | fprintf(stderr, "Connection 2 established\en"); | ||
| 267 | |||
| 268 | /* Close accept BIO to refuse further connections */ | ||
| 269 | cbio2 = BIO_pop(abio); | ||
| 270 | BIO_free(abio); | ||
| 271 | |||
| 272 | BIO_puts(cbio2, "Connection 2: Sending out Data on second\en"); | ||
| 273 | fprintf(stderr, "Sent out data on connection 2\en"); | ||
| 274 | BIO_puts(cbio, "Connection 1: Second connection established\en"); | ||
| 275 | |||
| 276 | /* Close the two established connections */ | ||
| 277 | BIO_free(cbio); | ||
| 278 | BIO_free(cbio2); | ||
| 279 | .Ed | ||
