Document Descriptor (FD) Type BIO
--- Translation according to OpenSSL DOC / CRYPTO / BIO_S_FD.POD and your understanding
(Author: DragonKing Mailwzhah@263.net Posted on:
Http://gdwzh.126.com OpenSSL Professional Forum)
File Descriptor Type BIO is also a Source / Sink type Bio that defines some of 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 explain is that although there is a BSS_FD.c file, the FD type BIO implementation function is not really in BSS_FD.C, but in BSS_Sock.c, BSS_FD.c This is a simple containment BSS_Sock. C file, so everyone should find the function, should be found in BSS_Sock.c.
[BIO_S_FD]
This function returns a file descriptor type BIO_METHOD structure, which encapsulates some rules of the file descriptor type, such as read () and write () functions. The FD type BIO_METHOD structure 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 it does not implement the Gets method compared to the FILE type BIO. The following is a simple description of some of the same BIO operations:
Bio_read and bio_write read and write the underlying file descriptor structure. Some behaviors of these two functions depends on the behavior of the read and write functions of the file descriptor they have. If the underlying file descriptor is non-blocking type, then they basically introduce the IO of BIO in front of us. The function is the same. See the previous articles and information. Socket is a special descriptor that should not use the file descriptor type BIO to encapsulate it, and you should use a special Socke type Bio, we will introduce later.
Bio_PUTS is supported, but Bio_GETS is not supported in this type descriptor.
If a shutdown flag is set, the file descriptor under the base layer is turned off when the Bio is released.
The BIO_RESET invokes the LSeek (FD, 0, 0) function to point the file pointer to the beginning. The call successfully returns 0, and the failed returns -1.
Bio_seek calls the LSeek (FD, OFS, 0) function, setting the location of the file pointer to the position of the file header off, and successfully returns the location of the file pointer, failed to return -1.
BIO_TELL returns the location of the current file pointer, which actually calls the LSEEK (FD, 0, 1) function, failed to return -1.
[BIO_SET_FD]
This function sets the BIO's underlying file descriptor to FD, and the closing flag is also set, and its meaning is the same as the corresponding meaning of the file type BIO. Returns 1.
[BIO_GET_FD] Returns the underlying file descriptor of the corresponding BIO, exists in parameter C, but also returns to the return value. c should be an int * type pointer. If the BIO has not initialized, call the function will fail, return -1. [BIO_NEW_FD]
Create and return a base descriptor as an FD, close the flag of the file descriptor type of Close_Flag. In fact, this function calls BIO_S_FD, BIO_NEW, and BIO_SET_FD to complete this feature in turn. This function returns NULL if the call failed.
Here is a simple example:
BIO * OUT;
OUT = BIO_NEW_FD (fileno (stdout), bio_noclose);
Bio_Printf (Out, "Hello World / N");
BIO_FREE (OUT);