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

Prevent reconnection crash #294

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Source/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ open class WebSocket : NSObject, StreamDelegate {
didDisconnect = false
isConnecting = true
createHTTPRequest()
isConnecting = false
}

/**
Expand Down Expand Up @@ -319,6 +318,9 @@ open class WebSocket : NSObject, StreamDelegate {
//higher level API we will cut over to at some point
//NSStream.getStreamsToHostWithName(url.host, port: url.port.integerValue, inputStream: &inputStream, outputStream: &outputStream)

// Disconnect and clean up any existing streams before setting up a new pair
disconnectStream(nil)

var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
let h = url.host! as NSString
Expand Down Expand Up @@ -494,6 +496,7 @@ open class WebSocket : NSObject, StreamDelegate {
let code = processHTTP(buffer, bufferLen: bufferLen)
switch code {
case 0:
isConnecting = false
connected = true
guard canDispatch else {return}
callbackQueue.async { [weak self] in
Expand Down Expand Up @@ -906,6 +909,7 @@ open class WebSocket : NSObject, StreamDelegate {
private func doDisconnect(_ error: NSError?) {
guard !didDisconnect else { return }
didDisconnect = true
isConnecting = false
connected = false
guard canDispatch else {return}
callbackQueue.async { [weak self] in
Expand Down