@Override
    protected Msg xrecv (int flags_)
    {
        Msg msg_ = null;
        //  If request wasn't send, we can't wait for reply.
        if (!receiving_reply) {
            ZError.errno(ZError.EFSM);
            throw new IllegalStateException("Cannot wait before send");
        }

        //  First part of the reply should be the original request ID.
        if (message_begins) {
            msg_ = super.xrecv (flags_);
            if (msg_ == null)
                return null;

            // TODO: This should also close the connection with the peer!
            if ( !msg_.has_more() || msg_.size () != 0) {
                while (true) {
                    msg_ = super.xrecv (flags_);
                    assert (msg_ != null);
                    if (!msg_.has_more())
                        break;
                }
                ZError.errno(ZError.EAGAIN);
                return null;
            }

            message_begins = false;
        }

        msg_ = super.xrecv (flags_);
        if (msg_ == null)
            return null;

        //  If the reply is fully received, flip the FSM into request-sending state.
        if (!msg_.has_more()) {
            receiving_reply = false;
            message_begins = true;
        }

        return msg_;
    }