gpt4 book ai didi

c - 如何获取底层套接字读取缓冲区大小?

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:06 24 4
gpt4 key购买 nike

有一个用于原始套接字的 api:

int sz;
ioctlsocket(sock, FIONREAD, &sz);
::recv(sock, buff, sz, 0);

ioctlsocket 可用于获取传入缓冲区大小,但如何使用 openssl 获取它:

int sz = what?
SSL_read(pSSL, buff, sz);

最佳答案

but how to get [incoming buffer size] with openssl?

OpenSSL 使用 BIO。写缓冲区有BIO_get_write_buf_size,但读缓冲区没有相应的控制。您可以使用 BIO_set_read_buffer_size 设置读取缓冲区大小。但我相信为 BIO 设置缓冲区,而不是套接字上的 I/O 缓冲区。请参阅 crypto/bio/bss_bio.c 中的 struct bio_bio_stBIO_f_buffer(3) 中的文档和 BIO_s_bio(3) .

您应该可以在BIO 上调用BIO_get_fd 来获取底层套接字,然后使用ioctlioctlsocket。您可以在 SSL* 中找到 BIO。 OpenSSL 方便地具有 SSL_get_rbioSSL_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;
...
};

关于c - 如何获取底层套接字读取缓冲区大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23407795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com