((TCPNIOConnection) connection).onWrite(buffer, written);
} catch (IOException e) {
// Mark connection as closed remotely.
((TCPNIOConnection) connection).terminate0(null,
new CloseReason(CloseType.REMOTELY, e));
throw e;
}
} else if (message instanceof FileTransfer) {
written = ((FileTransfer) message).writeTo((SocketChannel) connection.getChannel());
((TCPNIOConnection) connection).onWrite(null, written);