Skip to content

Commit f59e4d4

Browse files
committed
ssl: update rdoc for SSLSocket#pending and #wait_readable
Clarify how they (do not) interact with read buffers. SSLSocket#pending corresponds to SSL_pending(). It reports data that is already processed and is immediately available to read from the OpenSSL library's internal buffer. SSLSocket#wait_readable does not check for buffered data, either in the OpenSSL library or in OpenSSL::Buffering, so it may block even when data is already available to read. This is different from IO#wait_readable. I considered changing SSLSocket#wait_readable to check these buffers, but rejected it because it is also used when the caller specifically needs to wait for new records from the peer, particularly after SSLSocket#write_nonblock returns :wait_readable.
1 parent ed948ea commit f59e4d4

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎ext/openssl/ossl_ssl.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,14 @@ ossl_ssl_get_state(VALUE self)
24402440
* call-seq:
24412441
* ssl.pending => Integer
24422442
*
2443-
* The number of bytes that are immediately available for reading.
2443+
* Returns the number of bytes buffered by the OpenSSL library and immediately
2444+
* available for reading with #sysread.
2445+
*
2446+
* This does not include data read ahead and buffered by SSLSocket. It may
2447+
* therefore return 0 even when data is available for reading with methods
2448+
* that are aware of the SSLSocket buffer, such as #read or #gets.
2449+
*
2450+
* See also the man page SSL_pending(3).
24442451
*/
24452452
static VALUE
24462453
ossl_ssl_pending(VALUE self)

‎lib/openssl/ssl.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,23 @@ def close_on_exec?
223223
to_io.close_on_exec?
224224
end
225225

226+
# Calls IO#wait on the underlying socket.
227+
#
228+
# Note that this method may block even when there is data immediately
229+
# available to read, unlike IO#wait_readable.
226230
def wait(*args)
227231
to_io.wait(*args)
228232
end
229233

234+
# Calls IO#wait_readable on the underlying socket.
235+
#
236+
# Note that this method may block even when there is data immediately
237+
# available to read, unlike IO#wait_readable.
230238
def wait_readable(*args)
231239
to_io.wait_readable(*args)
232240
end
233241

242+
# Calls IO#wait_writable on the underlying socket.
234243
def wait_writable(*args)
235244
to_io.wait_writable(*args)
236245
end

0 commit comments

Comments
 (0)