jetfire
jetfire copied to clipboard
NSRunLoop Crash!
I have met a crash at
[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.inputStream open];
[self.outputStream open];
size_t dataLen = [data length];
[self.outputStream write:[data bytes] maxLength:dataLen];
while (self.isRunLoop) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
The Line [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
always crash when I create many socket in a short time. Maybe there is a third sdk conflict with these above code.
And I spent half day to fix this problem , and finally I find a way to avoid this bug. The code is:
[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:@"JFRWebSocketRunLoopMode"];
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:@"JFRWebSocketRunLoopMode"];
[self.inputStream open];
[self.outputStream open];
size_t dataLen = [data length];
[self.outputStream write:[data bytes] maxLength:dataLen];
while (self.isRunLoop) {
[[NSRunLoop currentRunLoop] runMode:@"JFRWebSocketRunLoopMode" beforeDate:[NSDate distantFuture]];
}
I am not sure why this crash happend, neither not sure why my fix can works.
But I think should let you know this issue.
I have the same crash
I fixed the crash on my fork (with extra refactoring and design changes), the real issue was the ability to initialize multiple connections when calling [socket connect] a few times on a disconnected socket (created state marked asynchronously).
#67 Add blocking connect and move handling connection to dedicated NSThread