Skip to content

Commit

Permalink
Merge pull request facebookincubator#67 from tenthbitinc/master
Browse files Browse the repository at this point in the history
Make closeWithCode:reason: safer by moving readyState change to work queue
  • Loading branch information
mikelikespie committed Jan 12, 2013
2 parents 5f3e6e2 + c0a0539 commit 4a0996b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions SocketRocket/SRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -625,16 +625,17 @@ - (void)close;
- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
{
assert(code);
if (self.readyState == SR_CLOSING || self.readyState == SR_CLOSED) {
return;
}

BOOL wasConnecting = self.readyState == SR_CONNECTING;

self.readyState = SR_CLOSING;

SRFastLog(@"Closing with code %d reason %@", code, reason);
dispatch_async(_workQueue, ^{
if (self.readyState == SR_CLOSING || self.readyState == SR_CLOSED) {
return;
}

BOOL wasConnecting = self.readyState == SR_CONNECTING;

self.readyState = SR_CLOSING;

SRFastLog(@"Closing with code %d reason %@", code, reason);

if (wasConnecting) {
[self _disconnect];
return;
Expand Down

0 comments on commit 4a0996b

Please sign in to comment.