qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] net/net: Add ReadState for reuse codes


From: Zhang Chen
Subject: Re: [Qemu-devel] [PATCH] net/net: Add ReadState for reuse codes
Date: Thu, 12 May 2016 16:23:00 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2



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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]