Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #254 from kikettas/fix/websocket-eventloop-assert
Browse files Browse the repository at this point in the history
Fixed issue with EvenLoop assert
  • Loading branch information
tanner0101 committed Apr 11, 2018
2 parents b26f765 + b6ea53e commit 0800921
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Sources/WebSocket/WebSocketHandler.swift
Expand Up @@ -101,15 +101,17 @@ internal final class WebsocketHandler: ChannelInboundHandler {
currentCtx = nil
}

func send(count: Int, opcode: WebSocketOpcode, bufferWriter: (inout ByteBuffer) -> ()) {
func send(count: Int, opcode: WebSocketOpcode, bufferWriter: @escaping (inout ByteBuffer) -> ()) {
let ctx = currentCtx!
guard ctx.channel.isActive else { return }
// We can't send if we sent a close message.
guard !self.awaitingClose else { return }
var buffer = ctx.channel.allocator.buffer(capacity: count)
bufferWriter(&buffer)
let frame = WebSocketFrame(fin: true, opcode: opcode, data: buffer)
ctx.writeAndFlush(wrapOutboundOut(frame), promise: nil)
ctx.eventLoop.execute {
guard ctx.channel.isActive else { return }
// We can't send if we sent a close message.
guard !self.awaitingClose else { return }
var buffer = ctx.channel.allocator.buffer(capacity: count)
bufferWriter(&buffer)
let frame = WebSocketFrame(fin: true, opcode: opcode, data: buffer)
ctx.writeAndFlush(self.wrapOutboundOut(frame), promise: nil)
}
}

private func receivedClose(ctx: ChannelHandlerContext, frame: WebSocketFrame) {
Expand Down

0 comments on commit 0800921

Please sign in to comment.