use of io.undertow.websockets.core.UTF8Output in project undertow by undertow-io.
the class FrameHandler method onFullCloseMessage.
@Override
protected void onFullCloseMessage(final WebSocketChannel channel, final BufferedBinaryMessage message) {
if (session.isSessionClosed()) {
// we have already handled this when we sent the close frame
message.getData().free();
return;
}
final Pooled<ByteBuffer[]> pooled = message.getData();
final ByteBuffer singleBuffer = toBuffer(pooled.getResource());
final ByteBuffer toSend = singleBuffer.duplicate();
// send the close immediatly
WebSockets.sendClose(toSend, channel, null);
session.getContainer().invokeEndpointMethod(executor, new Runnable() {
@Override
public void run() {
try {
if (singleBuffer.remaining() > 1) {
final CloseReason.CloseCode code = CloseReason.CloseCodes.getCloseCode(singleBuffer.getShort());
final String reasonPhrase = singleBuffer.remaining() > 1 ? new UTF8Output(singleBuffer).extract() : null;
session.closeInternal(new CloseReason(code, reasonPhrase));
} else {
session.closeInternal(new CloseReason(CloseReason.CloseCodes.NO_STATUS_CODE, null));
}
} catch (IOException e) {
invokeOnError(e);
} finally {
pooled.close();
}
}
});
}
Aggregations