Well, it’s a little bit complicated and there are so little documents on socket BIO, so I will give more instruction and more sample codes.
First introduce some key points.
a) There are three main kinds of BIO socket: BIO_s_socket, BIO_s_connect, and BIO_s_accept. You may regard the first one as a “raw” socket, the second one a client socket, and the last one a server socket. You may assign a fd(SOCKET) to them later.
b) Fd, is just the Socket object. You may use BIO_get_fd() or BIO_set_fd() to get or set the socket object. And the socket object is stored in BIO.num.
c) BIO.ptr pointing to a private struct that contain socket information such as address, state, blocking mode and so on. There are two kinds of struct: BIO_ACCEPT and BIO_CONNECT.
d) You may use the three function to send or receive data.
int BIO_puts(BIO *b, const char *in); // send string
int BIO_write(BIO *b, const void *in, int inl); // send raw data
int BIO_read(BIO *b, void *out, int outl); //receive data.
e) It’s thread safe, you can pass the BIO pointer to one thread.