diff options
-rw-r--r-- | SmartDeviceLink/private/SDLIAPDataSession.m | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/SmartDeviceLink/private/SDLIAPDataSession.m b/SmartDeviceLink/private/SDLIAPDataSession.m index 06d2e1f1d..be8b8cfbb 100644 --- a/SmartDeviceLink/private/SDLIAPDataSession.m +++ b/SmartDeviceLink/private/SDLIAPDataSession.m @@ -58,10 +58,14 @@ NS_ASSUME_NONNULL_BEGIN if (bytesWritten >= 0) { if (bytesWritten == bytesRemaining) { [self.sendDataQueue popBuffer]; - } else { + } else if (bytesRemaining > bytesWritten) { // Cleave the sent bytes from the data, the remainder will sit at the head of the queue SDLLogV(@"SDLIAPDataSession writeDataToSessionStream bytes written %ld", (long)bytesWritten); [remainder replaceBytesInRange:NSMakeRange(0, (NSUInteger)bytesWritten) withBytes:NULL length:0]; + } else { + // Error processing current data. Remove corrupted buffer + SDLLogE(@"Unable to remove sent bytes. Bytes remaining is less than bytes written %lu < %lu. Clearing buffer", bytesRemaining, bytesWritten); + [self.sendDataQueue popBuffer]; } } else { // The write operation failed but there is no further information about the error. This can occur when disconnecting from an external accessory. |