summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLUploadFileOperation.m
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2017-07-31 17:49:05 -0400
committerNicoleYarroch <nicole@livio.io>2017-07-31 17:49:05 -0400
commit12642df8a10fb833f766829d4bb9a88954c07c82 (patch)
tree5e57119f04c842cdfed69fa899bb3f856f720c67 /SmartDeviceLink/SDLUploadFileOperation.m
parentb415fbee4edd688c297f72a24de9e7e9a840ea5e (diff)
downloadsdl_ios-12642df8a10fb833f766829d4bb9a88954c07c82.tar.gz
Fixed broken large file test case
- Added method to TestConnectionManager to return specific request. Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink/SDLUploadFileOperation.m')
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m30
1 files changed, 18 insertions, 12 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index bac053557..6ff7dc515 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -131,7 +131,11 @@ NS_ASSUME_NONNULL_BEGIN
// If no errors, watch for a response containing the amount of storage left on the SDL Core
SDLPutFileResponse *putFileResponse = (SDLPutFileResponse *)response;
- bytesAvailable = [self sdl_getBytesAvailableFromResponse:putFileResponse request:request highestCorrelationIDReceived:highestCorrelationIDReceived currentBytesAvailable:bytesAvailable];
+ NSInteger highestCurrentCorrelationIDReceived = [self sdl_highestCurrentCorrelationID:request highestCorrelationIDReceived:highestCorrelationIDReceived];
+ if (highestCorrelationIDReceived != highestCurrentCorrelationIDReceived) {
+ highestCorrelationIDReceived = highestCurrentCorrelationIDReceived;
+ bytesAvailable = [putFileResponse.spaceAvailable unsignedIntegerValue];
+ }
dispatch_group_leave(putFileGroup);
}];
@@ -203,6 +207,10 @@ NS_ASSUME_NONNULL_BEGIN
@return The data read from the socket
*/
- (nullable NSData *)sdl_getDataChunkWithSize:(NSInteger)size inputStream:(NSInputStream *)inputStream {
+ if (size <= 0) {
+ return nil;
+ }
+
uint8_t buffer[size];
NSInteger bytesRead = [inputStream read:buffer maxLength:size];
if (bytesRead) {
@@ -217,19 +225,17 @@ NS_ASSUME_NONNULL_BEGIN
/**
One of the reponses returned by the SDL Core will contain the correct remaining free storage size on the SDL Core. Since communication with the SDL Core is asychronous, there is no way to predict which response contains the correct bytes available other than to watch for the largest correlation id, since that will be the last reponse sent by the SDL Core.
- @param putFileResponse The response sent by the SDL Core after a putfile is sent
- @param request The correlation id for the response
- @param highestCorrelationIDReceived The largest received correlation id
- @param currentBytesAvailable The current number bytes available
- @return The amount of storage space left on the SDL Core
+ @param request The newest response returned by the SDL Core for a putfile
+ @param highestCorrelationIDReceived The largest currently received correlation id
+ @return Whether or not the newest request contains the highest correlationId
*/
-- (NSInteger)sdl_getBytesAvailableFromResponse:(SDLPutFileResponse *)putFileResponse request:(nullable SDLRPCRequest *)request highestCorrelationIDReceived:(NSInteger)highestCorrelationIDReceived currentBytesAvailable:(NSInteger)currentBytesAvailable {
- // The number of bytes available is sent with the last response
- if ([request.correlationID integerValue] > highestCorrelationIDReceived) {
- highestCorrelationIDReceived = [request.correlationID integerValue];
- return [putFileResponse.spaceAvailable unsignedIntegerValue];
+- (NSInteger)sdl_highestCurrentCorrelationID:(nullable SDLRPCRequest *)request highestCorrelationIDReceived:(NSInteger)highestCorrelationIDReceived {
+ NSInteger newCorrelationID = [request.correlationID integerValue];
+ if (newCorrelationID > highestCorrelationIDReceived) {
+ return newCorrelationID;
}
- return currentBytesAvailable;
+
+ return highestCorrelationIDReceived;
}
#pragma mark - Property Overrides