pyopenssl
pyopenssl copied to clipboard
Using the same buffer with recv
As I was reading through the source code of pyopenssl to get an understanding of how to use memory BIO's, I saw the following comment:
Receive data on the connection. NOTE: If you get one of the WantRead,
WantWrite or WantX509Lookup exceptions on this, you have to call the
method again with the SAME buffer.
However, in the code for the method below, it appears that it is impossible to call the method again with the SAME buffer, as a new buffer is allocated every single time with
buf = _ffi.new("char[]", bufsiz)
Is this a bug in the code, or a bug in the documentation?
def recv(self, bufsiz, flags=None):
"""
Receive data on the connection. NOTE: If you get one of the WantRead,
WantWrite or WantX509Lookup exceptions on this, you have to call the
method again with the SAME buffer.
:param bufsiz: The maximum number of bytes to read
:param flags: (optional) Included for compatibility with the socket
API, the value is ignored
:return: The string read from the Connection
"""
buf = _ffi.new("char[]", bufsiz)
result = _lib.SSL_read(self._ssl, buf, bufsiz)
self._raise_ssl_error(self._ssl, result)
return _ffi.buffer(buf, result)[:]