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.
本文介绍了BIO Socket的主要类型,包括BIO_s_socket、BIO_s_connect和BIO_s_accept,并详细解释了它们的功能及如何使用这些接口进行数据的发送与接收。此外,还探讨了线程安全性和内部数据结构。
1万+

被折叠的 条评论
为什么被折叠?



