BIO series of openssl 12 --- file descriptor (fd) Type BIO, openssl12 ---
File descriptor (fd) Type BIO
--- Based on openssl doc \ crypto \ bio_s_fd.pod translation and your own understanding, write
(Author: DragonKing Mailwzhah@263.net released in: httpgdwzh.126.com openssl proprietary)
Industry Forum)
The file descriptor Type BIO is also a source/sink Type BIO, which defines the following types of functions (
Openssl \ bio. h ):
BIO_METHOD * BIO_s_fd (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_fd (int fd, int close_flag );
One thing to note is that, although the bss_fd.c file exists, concerning the fd Type BIO implementation function,
It is not really in bss_fd.c, but in bss_sock.c. bss_fd.c contains bss_sock.
. C file, so you should find the implementation function in bss_sock.c.
[BIO_s_fd]
This function returns a BIO_METHOD structure of the file descriptor type, which encapsulates
Such as read () and write () functions. The structure of BIO_METHOD of fd type is as follows:
Static BIO_METHOD methods_fdp =
{
BIO_TYPE_FD, "file descriptor ",
Fd_write,
Fd_read,
Fd_puts,
NULL,/* fd_gets ,*/
Fd_ctrl,
Fd_new,
Fd_free,
NULL,
};
It can be seen that, compared with file type BIO, it does not implement the gets method. Below are some of the same BIO operation letters
Here is a simple description of the number:
BIO_read and BIO_write perform read and write operations on the underlying file descriptor structure. Some rows of these two functions
The underlying file descriptor is not
Blocking type, so they are basically the same as the IO operation function we introduced earlier. See the previous section.
. Socket is a special type of descriptor. It should not be encapsulated by BIO of the file descriptor type.
Instead, we will introduce the special socke Type BIO later.
BIO_puts is supported, but BIO_gets is not supported in this type descriptor.
If the close flag is set, the underlying file descriptor is closed when BIO is released.
BIO_reset calls the lseek (fd, 0, 0) function to point the file pointer to the starting position. 0 is returned if the call is successful,
-1 is returned for failure.
BIO_seek calls the lseek (fd, ofs, 0) function to set the position of the file pointer to offset ofs from the file header
Location. The position of the file pointer is returned successfully. If the pointer fails,-1 is returned.
BIO_tell returns the position of the current file pointer. It actually calls the lseek (fd,) function and returns-
1.
[BIO_set_fd]
This function sets the underlying file descriptor of BIO to fd, and the flag is also set. Its meaning and file
Type BIO has the same meaning. Returns 1.
[BIO_get_fd] returns the underlying file descriptor of BIO, which is stored in parameter c.
Return Value. C should be int * type pointer. If BIO is not initialized, calling this function will fail-
1.
[BIO_new_fd]
Create and return a file descriptor Type BIO with the underlying descriptor fd and close_flag.
In fact, this function calls BIO_s_fd, BIO_new, and BIO_set_fd in sequence to complete this function. If you call this function
Return NULL if an error occurs.
The following is a simple example:
BIO * out;
Out = BIO_new_fd (fileno (stdout), BIO_NOCLOSE );
BIO_printf (out, "Hello World \ n ");
BIO_free (out );