有一个用于原始套接字的api:
int sz;
ioctlsocket(sock, FIONREAD, &sz);
::recv(sock, buff, sz, 0);
在ioctlsocket可以用来获得进入缓冲区的大小,而是如何与OpenSSL的得到它:
int sz = what?
SSL_read(pSSL, buff, sz);
但是如何使用openssl获取[传入缓冲区大小]?
OpenSSL使用BIO
。BIO_get_write_buf_size
写缓冲区有一个,但读缓冲区没有相应的控件。您可以使用设置读取缓冲区的大小BIO_set_read_buffer_size
。但是我相信这会为设置缓冲区BIO
,而不是套接字上的I / O缓冲区。见struct bio_bio_st
在crypto/bio/bss_bio.c
,并在文档BIO_f_buffer(3)
和BIO_s_bio(3)
。
你应该能够调用BIO_get_fd
上BIO
得到根本插座,然后使用ioctl
或ioctlsocket
。您可以在BIO
中找到SSL*
。OpenSSL方便地具有SSL_get_rbio
和SSL_get_wbio
。来自ssl/ssl.h
:
struct ssl_st
{
/* protocol version
* (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION)
*/
int version;
int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
const SSL_METHOD *method; /* SSLv3 */
/* There are 2 BIO's even though they are normally both the
* same. This is so data can be read and written to different
* handlers */
#ifndef OPENSSL_NO_BIO
BIO *rbio; /* used by SSL_read */
BIO *wbio; /* used by SSL_write */
BIO *bbio; /* used during session-id reuse to concatenate messages */
#else
char *rbio; /* used by SSL_read */
char *wbio; /* used by SSL_write */
char *bbio;
#endif
/* This holds a variable that indicates what we were doing
* when a 0 or -1 is returned. This is needed for
* non-blocking IO so we know what request needs re-doing when
* in SSL_accept or SSL_connect */
int rwstate;
...
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句