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

Commit

Permalink
Fixed issue with EvenLoop assert
Browse files Browse the repository at this point in the history
  • Loading branch information
kikettas committed Apr 1, 2018
1 parent 4846ea9 commit b6ea53e
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 b6ea53e

Please sign in to comment.