From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0lub-0003ls-6L for qemu-devel@nongnu.org; Thu, 12 May 2016 04:24:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0luU-00046u-ER for qemu-devel@nongnu.org; Thu, 12 May 2016 04:24:00 -0400 Received: from [59.151.112.132] (port=62330 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0luG-0003s4-6M for qemu-devel@nongnu.org; Thu, 12 May 2016 04:23:54 -0400 References: <1462532187-22787-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> <5732F4FF.5060206@redhat.com> <57331577.2090206@cn.fujitsu.com> <5733D852.9080301@redhat.com> <573423B6.2040602@cn.fujitsu.com> <573439B4.9040300@redhat.com> From: Zhang Chen Message-ID: <57343D64.7070503@cn.fujitsu.com> Date: Thu, 12 May 2016 16:23:00 +0800 MIME-Version: 1.0 In-Reply-To: <573439B4.9040300@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH] net/net: Add ReadState for reuse codes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang , qemu devel Cc: "eddie . dong" , "Dr . David Alan Gilbert" , Li Zhijian On 05/12/2016 04:07 PM, Jason Wang wrote: > > > On 2016年05月12日 14:33, Zhang Chen wrote: >>>>>> + ret = net_fill_rstate(&s->rs, buf, size); >>>>>> + >>>>>> + if (ret == -1) { >>>>>> + goto eoc; >>>>>> + } else if (ret == 1) { >>>>>> + if (qemu_send_packet_async(&s->nc, s->rs.buf, >>>>>> + s->rs.packet_len, >>>>>> + net_socket_send_completed) == 0) { >>>>>> + net_socket_read_poll(s, false); >>>>> >>>>> This looks not elegant, maybe we could use callback (which was >>>>> initialized by the helper I mention above) to do this. Any >>>>> thoughts on this? >>>> >>>> Do you mean: >>>> >>>> remove >>>> + if (qemu_send_packet_async(&s->nc, s->rs.buf, >>>> + s->rs.packet_len, >>>> + net_socket_send_completed) == 0) { >>>> + net_socket_read_poll(s, false); >>>> >>>> add >>>> >>>> s->rs->done >>>> >>>> void socket_fill_rsstate_done_cb(SocketReadState *srs, void *opaque) >>>> { >>>> NetSocketState *s = opaque; >>>> >>>> if (qemu_send_packet_async(&s->nc, srs->buf, >>>> srs->packet_len, >>>> net_socket_send_completed) == 0) { >>>> net_socket_read_poll(s, false); >>>> } >>>> } >>> >>> Yes, but there's no need for opaque, we can infer the container by >>> container_of(). >>> >> >> But in filter-mirror.c we need do this: >> >> >> void redirector_fill_rsstate_done_cb(SocketReadState *srs, void >> *opaque) >> { >> NetFilterState *nf = opaque; >> >> redirector_to_filter(nf, srs->buf, srs->packet_len); >> } >> >> so,I think we have to use void *opaque. >> >> >> > > You mean you need to get nf? Since SocketReadState were embedded in > MirrorState, so you could get the address of MirrorState, then it's > not hard to get nf address? > > Got it~~ will fix it in next version. Thanks Zhang Chen > . > -- Thanks zhangchen