当其中一个返回SSL_ERROR_WANT_READ或SSL_ERROR_WANT_WRITE时,您可以将调用插入到SSL_Read() & SSL_Write()中吗?

时间:2021-01-29 21:07:44

I have a client program which talks to a server using a message-based protocol. Every request is matched by 1 or more responses.

我有一个客户端程序,它使用基于消息的协议与服务器对话。每个请求都匹配一个或多个响应。

It's possible for multiple requests to be queued on a socket at once, and the I/O is done on a separate thread using non-blocking I/O. The algorithm is basically to wait for the socket to become readable and/or writable using select() (based on whether there's requests to send and/or responses to read), then to do the read and/or write. This works fine.

可以同时在套接字上排队多个请求,并且I/O使用非阻塞I/O在一个单独的线程上完成。该算法基本上是等待套接字通过select()变得可读和/或可写(基于是否有发送和/或响应进行读取),然后进行读和/或写。这是很好。

Now, if I enable SSL on the socket, we have to use SSL_Read()/SSL_Write() instead of send()/recv(). Now, my question is, can I call SSL_Write() after SSL_Read() fails with WANT_READ/WANT_WRITE (or vice versa), or do I have to keep calling SSL_Write() until it succeeds/fails? The documentation doesn't seem to explicitly rule this out, but it's kind of vague here.

现在,如果我在套接字上启用SSL,我们必须使用SSL_Read()/SSL_Write()而不是send()/recv()。现在,我的问题是,我是否可以在SSL_Read()在WANT_READ/WANT_WRITE(反之亦然)失败后调用SSL_Write(),或者我是否必须继续调用SSL_Write(),直到它成功/失败?文档似乎没有明确地排除这一点,但是这里有点模糊。

1 个解决方案

#1


0  

can I call SSL_Write() after SSL_Read() fails with WANT_READ/WANT_WRITE (or vice versa)

在WANT_READ/WANT_WRITE(或相反)失败后,我可以调用SSL_Write()

If it fails with WANT_WRITE you must call SSL_write(). No 'can I' about it. A read shouldn't fail with WANT_READ, because you were reading, except I guess in non-blocking mode.

如果WANT_WRITE失败,则必须调用SSL_write()。不,我不能。在WANT_READ中,读取不应该失败,因为您正在读取,但是我猜是在非阻塞模式下。

or do I have to keep calling SSL_Write() until it succeeds/fails

或者我必须一直调用SSL_Write()直到它成功/失败

Yes, when it wants a write you have to write, and you have to repeat until success. No 'or' about it.

是的,当它需要写作时,你必须写作,你必须重复,直到成功。没有'或'。

I don't really understand why you're even asking. Are there typos in the question?

我真不明白你为什么要问。这个问题有拼写错误吗?

#1


0  

can I call SSL_Write() after SSL_Read() fails with WANT_READ/WANT_WRITE (or vice versa)

在WANT_READ/WANT_WRITE(或相反)失败后,我可以调用SSL_Write()

If it fails with WANT_WRITE you must call SSL_write(). No 'can I' about it. A read shouldn't fail with WANT_READ, because you were reading, except I guess in non-blocking mode.

如果WANT_WRITE失败,则必须调用SSL_write()。不,我不能。在WANT_READ中,读取不应该失败,因为您正在读取,但是我猜是在非阻塞模式下。

or do I have to keep calling SSL_Write() until it succeeds/fails

或者我必须一直调用SSL_Write()直到它成功/失败

Yes, when it wants a write you have to write, and you have to repeat until success. No 'or' about it.

是的,当它需要写作时,你必须写作,你必须重复,直到成功。没有'或'。

I don't really understand why you're even asking. Are there typos in the question?

我真不明白你为什么要问。这个问题有拼写错误吗?