Fix timeouts when messages span multiple SSL records
Fix timeouts when messages span multiple SSL records

From the SSL_read man page:
SSL_read() works based on the SSL/TLS records. The data are received in
records (with a maximum record size of 16kB for SSLv3/TLSv1). Only when
a record has been completely received, it can be processed (decryption
and check of integrity). Therefore data that was not retrieved at the
last call of SSL_read() can still be buffered inside the SSL layer and
will be retrieved on the next call to SSL_read().

Due to this buffering of record data in the SSL layer, sometimes
SSL_read returns only a portion of the data that has been read from the
socket. This is usually fine, but twemproxy uses epoll_wait on the
socket to trigger processing of data. Since the SSL layer has read data
from the socket but not returned it for processing, there is no more
pending data on the socket to trigger processing. This causes the
twemproxy to get stuck between receiving and processing this data.
Ultimately the connection times out.

To resolve this, we want to detect when data is buffered in SSL_read so
that we can read as much as possible. SSL_pending should return that
there is data buffered, but it does not do this reliably. Instead, we
call SSL_read until it returns no more data.

This discussion is the same problem and solution:
http://openssl.6102.n7.nabble.com/OpenSSL-non-blocking-epoll-hanging-on-data-receiving-td66355.html

crashlytics/twemproxy,crashlytics/twemproxy,crashlytics/twemproxy,crashlytics/twemproxy