BIO IO operation function
--- Translation according to OpenSSL DOC / CRYPTO / BIO / BIO_READ.POD and its own understanding
(Author: DragonKing Mail: wzhah@263.net Posted: http: //gdwzh.126.com of openssl professional forum)
These functions are the basic read and write operation functions of the BIO, including four, their definitions are as follows (OpenSSL / BIO.H):
INT BIO_READ (Bio * B, Void * BUF, INT LEN);
INT BIO_GETS (Bio * B, Char * BUF, INT SIZE);
INT BIO_WRITE (BIO * B, Const Void * BUF, INT LEN);
INT BIO_PUTS (BIO * B, Const Char * BUF);
[BIO_READ]
Read the data of the specified quantity byte LEN from the BIO interface and store it in the buf. Success returns the length of the data that is really read, the failure returns 0 or -1, and if the BIO does not implement this function, Returns -2.
[BIO_GETS]
This function reads data from the BIO to the maximum size of size. Typically, the function will read a row of data in maximum length, but there are exceptions, such as Digest type BIO, which calculates and returns the entire Digest information. In addition, some BIOs may not support this function. Success returns the length of the data that is really read, the failure returns 0 or -1, and if the BIO does not implement this function, Returns -2. When you need to pay attention, if the corresponding BIO does not support this function, the call to the function may cause the BIO chain to automatically add a BIO to the Bio.
[BIO_WRITE]
Write the length of Len to the BIO. Success returns the length of the truly written data, the failure returns 0 or -1, returns -2 if the BIO does not implement this function.
[BIO_PUTS]
Write a string of NULL as the end of the BIO, successfully returns the length of the true written data, the failure returns 0 or -1, if the BIO does not implement this function, returns -2.
It should be noted that the return refers to 0 or -1 is not necessarily an error. In non-blocking Source / Sink or other specific types of BIO, this only represents currently no data can be read, and it is necessary to perform this operation later.
Sometimes, you may use some of the system call technologies (such as SELECT, POLL, Equivalent) using SOKECT, which determines if there is a valid data in the BIO to be read by the read function, but it is recommended not to in the blocking interface. Use these techniques, because in this case, if you call BIO_READ, the READ function is called multiple times in the underlying IO, resulting in port obstruction. It is recommended that SELECT (or Equivalent) should be used with non-blocking IOs, which can reread the IO after failure, rather than blocking.
Why does IO Operation of BIO fail and how to deal with these situations, please participate in the documentation of the BIO_SHOULD_RETRY () function.