Sortix cross-nightly manual
This manual documents Sortix cross-nightly. You can instead view this document in the latest official manual.
NAME
BIO_s_accept, BIO_set_accept_port, BIO_get_accept_port, BIO_new_accept, BIO_set_nbio_accept, BIO_set_accept_bios, BIO_set_bind_mode, BIO_get_bind_mode, BIO_do_accept — accept BIOSYNOPSIS
#include <openssl/bio.h>BIO_s_accept(void);
BIO_set_accept_port(BIO *b, char *name);
BIO_get_accept_port(BIO *b);
BIO_new_accept(const char *host_port);
BIO_set_nbio_accept(BIO *b, int n);
BIO_set_accept_bios(BIO *b, char *bio);
BIO_set_bind_mode(BIO *b, long mode);
BIO_get_bind_mode(BIO *b, long dummy);
#define BIO_BIND_REUSEADDR_IF_UNUSED 1
#define BIO_BIND_REUSEADDR 2
BIO_do_accept(BIO *b);
DESCRIPTION
BIO_s_accept() returns the accept BIO method. This is a wrapper round the platform's TCP/IP socket accept(2) routines.NOTES
When an accept BIO is at the end of a chain, it will await an incoming connection before processing I/O calls. When an accept BIO is not at the end of a chain, it passes I/O calls to the next BIO in the chain.connection = BIO_pop(accept);
cmd constant |
larg | corresponding macro |
| BIO_C_DO_STATE_MACHINE | 0 | BIO_do_accept() |
| BIO_C_GET_ACCEPT | 0 | BIO_get_accept_port() |
| BIO_C_GET_BIND_MODE | 0 | BIO_get_bind_mode() |
| BIO_C_GET_FD | 0 | BIO_get_fd(3) |
| BIO_C_SET_ACCEPT | 0 | BIO_set_accept_port() |
| 1 | BIO_set_nbio_accept() | |
| 2 | BIO_set_accept_bios() | |
| BIO_C_SET_FD | fd | BIO_set_fd(3) |
| BIO_C_SET_NBIO | n | BIO_set_nbio(3) |
| BIO_C_SET_BIND_MODE | mode | BIO_set_bind_mode() |
| BIO_CTRL_GET_CLOSE | 0 | BIO_get_close(3) |
| BIO_CTRL_RESET | 0 | BIO_reset(3) |
| BIO_CTRL_SET_CLOSE | flag | BIO_set_close(3) |
RETURN VALUES
When called on an accept BIO object, BIO_method_type(3) returns the constant BIO_TYPE_ACCEPT and BIO_method_name(3) returns a pointer to the static string “socket accept”.EXAMPLES
This example accepts two connections on port 4444, sends messages down each and finally closes both down.
BIO *abio, *cbio, *cbio2;
ERR_load_crypto_strings();
abio = BIO_new_accept("4444");
/* First call to BIO_accept() sets up accept BIO */
if (BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error setting up accept\n");
ERR_print_errors_fp(stderr);
exit(0);
}
/* Wait for incoming connection */
if (BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error accepting connection\n");
ERR_print_errors_fp(stderr);
exit(0);
}
fprintf(stderr, "Connection 1 established\n");
/* Retrieve BIO for connection */
cbio = BIO_pop(abio);
BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n");
fprintf(stderr, "Sent out data on connection 1\n");
/* Wait for another connection */
if (BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error accepting connection\n");
ERR_print_errors_fp(stderr);
exit(0);
}
fprintf(stderr, "Connection 2 established\n");
/* Close accept BIO to refuse further connections */
cbio2 = BIO_pop(abio);
BIO_free(abio);
BIO_puts(cbio2, "Connection 2: Sending out Data on second\n");
fprintf(stderr, "Sent out data on connection 2\n");
BIO_puts(cbio, "Connection 1: Second connection established\n");
/* Close the two established connections */
BIO_free(cbio);
BIO_free(cbio2);