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

Feature/pass on timeout #815

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Engine/WSEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ FrameCollectorDelegate, HTTPHandlerDelegate {
transport.write(data: data, completion: {_ in })
case .waiting:
break
case .timedout:
broadcast(event: .timedout)
case .failed(let error):
handleError(error)
case .viability(let isViable):
Expand Down
2 changes: 2 additions & 0 deletions Sources/Server/WebSocketServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class ServerConnection: Connection, HTTPServerDelegate, FramerEventClient
break
case .waiting:
break
case .timedout:
break
case .failed(let error):
print("server connection error: \(error ?? WSError(type: .protocolError, message: "default error, no extra data", code: 0))") //handleError(error)
case .viability(_):
Expand Down
1 change: 1 addition & 0 deletions Sources/Starscream/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public enum WebSocketEvent {
case viabilityChanged(Bool)
case reconnectSuggested(Bool)
case cancelled
case timedout
}

public protocol WebSocketDelegate: class {
Expand Down
13 changes: 11 additions & 2 deletions Sources/Transport/TCPTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ public class TCPTransport: Transport {
switch newState {
case .ready:
self?.delegate?.connectionChanged(state: .connected)
case .waiting:
self?.delegate?.connectionChanged(state: .waiting)
case .waiting(let error):
switch error {
case .posix(let errorCode):
if(errorCode == .ETIMEDOUT){
self?.delegate?.connectionChanged(state: .timedout)
}else{
self?.delegate?.connectionChanged(state: .waiting)
}
default:
self?.delegate?.connectionChanged(state: .waiting)
}
case .cancelled:
self?.delegate?.connectionChanged(state: .cancelled)
case .failed(let error):
Expand Down
1 change: 1 addition & 0 deletions Sources/Transport/Transport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum ConnectionState {
case connected
case waiting
case cancelled
case timedout
case failed(Error?)

//the viability (connection status) of the connection has updated
Expand Down