use curl code for large apple ssl send

This commit is contained in:
Benjamin Sergeant 2020-01-12 22:04:06 -08:00
parent b96b3b099f
commit 2a954b5b5b

View File

@ -112,10 +112,45 @@ namespace ix
OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection, OSStatus SocketAppleSSL::writeToSocket(SSLConnectionRef connection,
const void* data, const void* data,
size_t* len) size_t* dataLength)
{ {
int fd = (int) (long) connection; #if 1
if (fd < 0) return errSSLInternal; int sock = (int) (long) connection;
if (sock < 0) return errSSLInternal;
size_t bytesSent = 0;
ssize_t length;
size_t dataLen = *dataLength;
const UInt8 *dataPtr = (UInt8 *)data;
OSStatus ortn;
int theErr;
*dataLength = 0;
do {
length = write(sock,
(char *)dataPtr + bytesSent,
dataLen - bytesSent);
} while((length > 0) &&
( (bytesSent += length) < dataLen) );
if(length <= 0) {
theErr = errno;
if(theErr == EAGAIN) {
ortn = errSSLWouldBlock;
}
else {
ortn = errSecIO;
}
}
else {
ortn = noErr;
}
*dataLength = bytesSent;
return ortn;
#else
assert(data != nullptr); assert(data != nullptr);
assert(len != nullptr); assert(len != nullptr);
@ -155,6 +190,7 @@ namespace ix
default: return errSecIO; default: return errSecIO;
} }
} }
#endif
} }
@ -238,31 +274,24 @@ namespace ix
ssize_t SocketAppleSSL::send(char* buf, size_t nbyte) ssize_t SocketAppleSSL::send(char* buf, size_t nbyte)
{ {
ssize_t sent = 0; std::lock_guard<std::mutex> lock(_mutex);
while (nbyte > 0) size_t processed = 0;
OSStatus status = SSLWrite(_sslContext, buf, nbyte, &processed);
if (status == noErr)
{ {
std::lock_guard<std::mutex> lock(_mutex); return processed;
}
size_t processed = 0; else if (status == errSSLWouldBlock)
OSStatus status = SSLWrite(_sslContext, buf + sent, nbyte, &processed); {
errno = EWOULDBLOCK;
if (status == noErr) return -1;
{ }
nbyte -= processed; else
sent += processed; {
} return -1;
else if (status == errSSLWouldBlock)
{
errno = EWOULDBLOCK;
return -1;
}
else
{
return -1;
}
} }
return sent;
} }
ssize_t SocketAppleSSL::send(const std::string& buffer) ssize_t SocketAppleSSL::send(const std::string& buffer)