Skip to content

Commit

Permalink
Merge pull request #1 from adein/protocol_recursion_fix
Browse files Browse the repository at this point in the history
Bugfix for multiple messages in the inputstream buffer
  • Loading branch information
joeljfischer committed Nov 12, 2014
2 parents add5058 + aca1c7c commit 587ed9f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ DerivedData
*.ipa
*.xcuserstate

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

# OS X temporary files #
########################
*.swp
*.lock
profile

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
Expand Down
15 changes: 11 additions & 4 deletions sdl_ios/SmartDeviceLink/SDLProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ - (void)sendRPCRequest:(SDLRPCRequest *)rpcRequest {
if (self.version >= 2) {
[((SDLV2ProtocolHeader*)header) setMessageID:++_messageID];
}


SDLProtocolMessage *message = [SDLProtocolMessage messageWithHeader:header andPayload:messagePayload];

Expand All @@ -140,7 +140,7 @@ - (void)sendRPCRequest:(SDLRPCRequest *)rpcRequest {
[self logRPCSend:smallerMessage];
[self sendDataToTransport:smallerMessage.data withPriority:SDLServiceType_RPC];
}

}

}
Expand Down Expand Up @@ -184,6 +184,12 @@ - (void)handleBytesFromTransport:(NSData *)recievedData {
[self.recieveBuffer appendData:recievedData];
[logMessage appendFormat:@"(%ld) ", (long)self.recieveBuffer.length];

[self processMessages];
}

- (void)processMessages {
NSMutableString *logMessage = [[NSMutableString alloc]init];

// Get the version
UInt8 incomingVersion = [SDLProtocolMessage determineVersion:self.recieveBuffer];

Expand Down Expand Up @@ -217,16 +223,17 @@ - (void)handleBytesFromTransport:(NSData *)recievedData {
return;
}


// Need to maintain the recieveBuffer, remove the bytes from it which we just processed.
self.recieveBuffer = [[self.recieveBuffer subdataWithRange:NSMakeRange(messageSize, self.recieveBuffer.length - messageSize)] mutableCopy];


// Pass on ultimate disposition of the message to the message router.
dispatch_async(_recieveQueue, ^{
[self.messageRouter handleRecievedMessage:message];
});

// Call recursively until the buffer is empty or incomplete message is encountered
if (self.recieveBuffer.length > 0)
[self processMessages];
}

- (void)sendHeartbeat {
Expand Down

0 comments on commit 587ed9f

Please sign in to comment.