OpenSSL BIO Series 13 --- Socket Type Bio

zhaozj2021-02-16  55

Socket type BIO

--- Translation according to OpenSSL DOC / CRYPTO / BIO_S_SOCKET.POD and its own understanding

(Author: DragonKing Mailwzhah@263.net Posted: httpgdwzh.126.com the openssl professional forum)

The Socket type BIO is also a Source / Sink type Bio that encapsulates the socket IO operation, and some of its related functions are defined (openssl / bio.h):

BIO_METHOD * BIO_S_SOCKET (VOID);

#define bio_set_fd (b, fd, c) BIO_INT_CTRL (B, BIO_C_SET_FD, C, FD)

#define bio_get_fd (b, c) BIO_CTRL (B, BIO_C_GET_FD, 0, (Char *) C)

BIO * BIO_NEW_SOCKET (int suck, int close_flag);

As we introduced the FD type Bio, we have said that its function's implementation file is actually put together with the SOKET type BIO, all in the file bss_socket.c, you can know from these definitions, this Do it because the function of these two types of BIO implementation is basically the same, and has a lot of commonality.

[BIO_S_SOCKET]

This function returns a Socket type Bio_Method structure, the definition of the Bio_Method structure is as follows:

Static Bio_Method Methods_SockP =

{

BIO_TYPE_SOCKET,

"Socket",

Sock_write,

SOCK_READ,

Sock_puts,

NULL, / * SOCK_GETS, * /

SOCK_CTRL,

SOCK_NEW,

SOCK_FREE,

NULL,

}

It can be seen that it is basically the same as the FD type BIO in the implementation. It is just that the name of the preamble name and the type field is different. In fact, in the system like Linux, the socket type is the same as the FD type, they can be universal, but why is it to be implemented, it is because some systems such as Windows systems, Socket is different from the file descriptor. Therefore, for the platform's compatibility, OpenSSL will separate these two categories.

BIO_READ and BIO_WRITE are read and write to the underlying Socket structure.

BIO_PUTS is supported, but Bio_GETS is not supported in the socket type BIO. If you see the source code, you can know that although the BIO_GETS is not supported in the socket type, if the function is called, it will not have an exception, will only return -1 error information.

If a shutdown flag is set, then the bottom Socket connection will be turned off when the Bio is released.

[BIO_SET_FD]

This function sets the socket descriptor FD to the underlying IO structure of the BIO, and it can be set to turn off flag C. This function returns 1.

[BIO_GET_FD]

This function returns the Socket descriptor of the specified BIO. If the C parameter is not null, then the descriptor exists in parameter c, of course, the Socket descriptor also also acts as a return value, if the BIO does not initialize, the call failed, returned -1.

[BIO_NEW_SOCKET]

转载请注明原文地址:https://www.9cbs.com/read-24013.html

New Post(0)