Skip to content

Commit

Permalink
IosSslSocket: deplete the SSL buffer before issuing a new read.
Browse files Browse the repository at this point in the history
Recommended here:
#998 (comment)

More details in the same thread:
#998 (comment)

	Change on 2018/11/27 by antoniocortes <[email protected]>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=223006145
  • Loading branch information
antonio-cortes-perez committed Nov 27, 2018
1 parent 1ff7977 commit f3f3459
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions jre_emul/Classes/com/google/j2objc/net/ssl/IosSslSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ - (jint)readWithByteArray:(IOSByteArray *)b
OSStatus status;

[_socket startHandshake];

// Deplete the SSL buffer before issuing a new read.
size_t available = 0;
checkStatus(SSLGetBufferedReadSize(_socket->_sslContext, &available));
if (available != 0) {
len = MIN(((jint) available), len);
}

@synchronized (_socket) {
do {
size_t temp;
status = SSLRead(_socket->_sslContext, b->buffer_ + off, len, &temp);
off += temp;
len -= temp;
processed += temp;
// if less data than requested was actually transferred then, keep calling SSLRead until
// something different from errSSLWouldBlock is returned.
} while (status == errSSLWouldBlock);
status = SSLRead(_socket->_sslContext, b->buffer_ + off, len, &processed);
} while (status == errSSLWouldBlock && processed == 0);
}

if (status == errSSLClosedGraceful || status == errSSLClosedAbort) {
Expand Down

0 comments on commit f3f3459

Please sign in to comment.