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?