Skip to content

Commit

Permalink
Add channelInactive callback to mark WebSocket as closed. (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
bridger authored Feb 26, 2020
1 parent 766b4b0 commit e35af05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/WebSocketKit/WebSocketHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ private final class WebSocketHandler: ChannelInboundHandler {
let frame = self.unwrapInboundIn(data)
self.webSocket.handle(incoming: frame)
}

func channelInactive(context: ChannelHandlerContext) {
let closedAbnormally = WebSocketErrorCode.unknown(1005)
_ = webSocket.close(code: closedAbnormally)

// We always forward the error on to let others see it.
context.fireChannelInactive()
}
}

0 comments on commit e35af05

Please sign in to comment.