@@ -2629,6 +2629,7 @@ - (void)closeWithError:(NSError *)error
2629
2629
#if SECURE_TRANSPORT_MAYBE_AVAILABLE
2630
2630
{
2631
2631
[sslPreBuffer reset ];
2632
+ sslErrCode = noErr;
2632
2633
2633
2634
if (sslContext)
2634
2635
{
@@ -4517,8 +4518,19 @@ - (void)doReadData
4517
4518
if (result == errSSLWouldBlock)
4518
4519
waiting = YES ;
4519
4520
else
4520
- error = [self sslError: result];
4521
-
4521
+ {
4522
+ if (result == errSSLClosedGraceful || result == errSSLClosedAbort)
4523
+ {
4524
+ // We've reached the end of the stream.
4525
+ // Handle this the same way we would an EOF from the socket.
4526
+ socketEOF = YES ;
4527
+ sslErrCode = result;
4528
+ }
4529
+ else
4530
+ {
4531
+ error = [self sslError: result];
4532
+ }
4533
+ }
4522
4534
// It's possible that bytesRead > 0, even if the result was errSSLWouldBlock.
4523
4535
// This happens when the SSLRead function is able to read some data,
4524
4536
// but not the entire amount we requested.
@@ -4910,7 +4922,23 @@ - (void)doReadEOF
4910
4922
{
4911
4923
if (error == nil )
4912
4924
{
4913
- error = [self connectionClosedError ];
4925
+ if ([self usingSecureTransportForTLS ])
4926
+ {
4927
+ #if SECURE_TRANSPORT_MAYBE_AVAILABLE
4928
+ if (sslErrCode != noErr && sslErrCode != errSSLClosedGraceful)
4929
+ {
4930
+ error = [self sslError: sslErrCode];
4931
+ }
4932
+ else
4933
+ {
4934
+ error = [self connectionClosedError ];
4935
+ }
4936
+ #endif
4937
+ }
4938
+ else
4939
+ {
4940
+ error = [self connectionClosedError ];
4941
+ }
4914
4942
}
4915
4943
[self closeWithError: error];
4916
4944
}
@@ -6402,6 +6430,8 @@ - (void)ssl_startTLS
6402
6430
[sslPreBuffer didWrite: preBufferLength];
6403
6431
}
6404
6432
6433
+ sslErrCode = noErr;
6434
+
6405
6435
// Start the SSL Handshake process
6406
6436
6407
6437
[self ssl_continueSSLHandshake ];
0 commit comments