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

Fixed issue with EvenLoop assert #254

Merged
merged 1 commit into from Apr 11, 2018
Merged
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
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