我正在使用SecureTransport通过HTTPS与Google Places API进行通信。但是,当我在其中间的某处读取响应时,SSLRead例程首先挂起几分钟,然后返回零字节读取,从而使我的响应不完整。它可能是什么?
do {
if (httpResponseBodyContentLength > -1 && offset_recv >= httpResponseBodyContentLength) {
break;
}
size_t bytes_available;
for (int try = 0; try < 30; try++) {
if ((ssl_status = SSLGetBufferedReadSize(ssl_context, &bytes_available)) != 0) {
NetDebugLog(@"%@", [NSError errorWithDomain:NSOSStatusErrorDomain code:ssl_status userInfo:nil]);
bytes_available = 0;
@try {
usleep(30000);
}
@catch (NSException *exception) {
NetDebugLog(@"%@", exception);
}
}
else if (bytes_available == 0) {
@try {
usleep(30000);
}
@catch (NSException *exception) {
NetDebugLog(@"%@", exception);
}
}
else {
break;
}
}
ssl_status = SSLRead(ssl_context, responseBodyBuffer + offset_recv, MIN(responseBodyBufferLength - offset_recv, bytes_available), &bytes_recv_size_t);
bytes_recv_int = bytes_recv_size_t;
NetDebugLog(@"SSLRead() body: %zd bytes of %zd length (%ld offset)", bytes_recv_size_t, MIN(responseBodyBufferLength - offset_recv, bytes_available), offset_recv);
if (ssl_status != 0) {
NSError *ssl_error = [NSError errorWithDomain:NSOSStatusErrorDomain code:ssl_status userInfo:nil];
NetDebugLog(@"%@", ssl_error);
}
[responseBufferNSMutableData appendBytes:responseBodyBuffer + offset_recv length:bytes_recv_int];
responseBodyTotalLength += bytes_recv_int;
offset_recv += bytes_recv_int;
if (ssl_status == -36) {
@throw [NSException exceptionWithName:@"NAExtensions"
reason:[[NSString alloc]initWithFormat:@"SSLRead() failed: %ld", bytes_recv_size_t]
userInfo:nil];
}
else if (offset_recv == responseBodyBufferLength) {
offset_recv = 0;
}
}
while (bytes_recv_int > 0);