use of org.httpkit.server.Frame.CloseFrame in project http-kit by http-kit.
the class HttpServer method decodeWs.
private void decodeWs(WsAtta atta, SelectionKey key) {
try {
do {
Frame frame = atta.decoder.decode(buffer);
if (frame instanceof TextFrame || frame instanceof BinaryFrame) {
handler.handle(atta.channel, frame);
atta.decoder.reset();
} else if (frame instanceof PingFrame) {
handler.handle(atta.channel, frame);
atta.decoder.reset();
tryWrite(key, WsEncode(WSDecoder.OPCODE_PONG, frame.data));
} else if (frame instanceof PongFrame) {
// ignored as unsolicited pong frame from client
atta.decoder.reset();
} else if (frame instanceof CloseFrame) {
// A snapshot
boolean closed = atta.channel.isClosed();
handler.clientClose(atta.channel, ((CloseFrame) frame).getStatus());
// close the TCP connection after sent
atta.keepalive = false;
atta.decoder.reset();
// Do not send CLOSE frame again if it has been sent.
if (!closed) {
tryWrite(key, WsEncode(WSDecoder.OPCODE_CLOSE, frame.data));
}
}
} while (// consume all
buffer.hasRemaining());
} catch (ProtocolException e) {
warnLogger.log(null, e);
eventLogger.log(eventNames.serverWsDecodeError);
// TODO more specific error
closeKey(key, CLOSE_MESG_BIG);
}
}
Aggregations