boolean writeBytes(Frame frame) {

        synchronized (this) {
            if (m_handshaked == false ||
                m_destroying == true) {
                return false;
            }
        }

        int n = -1;
        ByteBuffer data = frame.getData();
        int size = data.capacity();
        int offset = 0;

        try {
            while(offset < size) {
                n = m_socketChannel.write(data);
                offset += n;
            }
        } catch (Exception e) {
            n = -1;
        }

        if (n <= 0) {
            // We do not destroy the connection at this point, even if we
            // we have a write error. The receiveHandler will take care of
            // it.
            return false;
        }

        return true;
    }