@Override
    public void deliver(Packet packet) throws UnauthorizedException, PacketException {
        if (isClosed()) {
            if (backupDeliverer != null) {
                backupDeliverer.deliver(packet);
            } else {
                Log.trace("Discarding packet that was due to be delivered on closed connection {}, for which no backup deliverer was configured.", this);
            }
        }
        else {
            boolean errorDelivering = false;
            boolean allowedToWrite = false;
            try {
                requestWriting();
                allowedToWrite = true;
                xmlSerializer.write(packet.getElement());
                xmlSerializer.flush();
            }
            catch (Exception e) {
                Log.debug("Error delivering packet" + "\n" + this.toString(), e);
                errorDelivering = true;
            }
            finally {
                if (allowedToWrite) {
                    releaseWriting();
                }
            }
            if (errorDelivering) {
                close();
                // Retry sending the packet again through the backup deliverer.
                if (backupDeliverer != null) {
                    backupDeliverer.deliver(packet);
                } else {
                    Log.trace("Discarding packet that failed to be delivered to connection {}, for which no backup deliverer was configured.", this);
                }
            }
            else {
                session.incrementServerPacketCount();
            }
        }
    }
Returns true if the socket was closed due to a bad health. The socket is considered to
be in a bad state if a thread has been writing for a while and the write operation has
not finished in a long time or when the client has not sent a heartbeat for a long time.
In any of both cases the socket will be closed.

@return true if the socket was closed due to a bad health.
xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java