Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion handlers are always called with "not completed" message in SDLProtocolMessageAssembler #92

Closed
jacobkeeler opened this issue Feb 26, 2015 · 1 comment
Labels
bug A defect in the library

Comments

@jacobkeeler
Copy link

In [SDLProtocolMessageAssembler handleMessage], the completionHandler is always called with done set to NO at the end of the function, even if the message assembly was completed.

if (self.parts.count == self.frameCount + 1) { // +1 since we also require the first-frame
    ...
    // Execute completion handler.
    if (completionHandler != nil) {
        completionHandler(YES, assembledMessage);
    }

    // Done with this data, release it.
    self.parts = nil;

}

// Not done, let caller know
if (completionHandler != nil) {
    completionHandler(NO, nil);
}

This results in the completionHandler being called twice when the message assembly is completed, once claiming that it was completed, and once claiming that it wasn't.

The last if statement should just be changed to an else if so that only one of the calls can be run.

if (self.parts.count == self.frameCount + 1) { // +1 since we also require the first-frame
    ...
    // Execute completion handler.
    if (completionHandler != nil) {
        completionHandler(YES, assembledMessage);
    }

    // Done with this data, release it.
    self.parts = nil;
}
// Not done, let caller know
else if (completionHandler != nil) {
    completionHandler(NO, nil);
}
@jacobkeeler jacobkeeler added the bug A defect in the library label Feb 26, 2015
@justinjdickow
Copy link
Contributor

@jacobkeeler Probably a little nit picky but I think to be more clear about what is going on in this code it should actually read

// Not done, let caller know
else {
  if (completionHandler != nil) {
      completionHandler(NO, nil);
  }
}

because the if statement only determines if there is a completionHandler to call, and in the case that there were other operations to perform if the message assembly hasn't completed (not that there are), they should not be blocked by a nil completion handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect in the library
Projects
None yet
Development

No branches or pull requests

3 participants