On Fri, Jun 8, 2012 at 10:20 PM, Stefan Hajnoczi <stefa...@gmail.com> wrote: > On Fri, Jun 8, 2012 at 3:15 PM, Zhi Yong Wu <zwu.ker...@gmail.com> wrote: >> On Fri, Jun 8, 2012 at 6:31 PM, Stefan Hajnoczi <stefa...@gmail.com> wrote: >>> On Thu, Jun 7, 2012 at 3:54 PM, <zwu.ker...@gmail.com> wrote: >>>> @@ -86,7 +82,16 @@ static void net_socket_send(void *opaque) >>>> /* end of connection */ >>>> eoc: >>>> qemu_set_fd_handler(s->fd, NULL, NULL, NULL); >>>> + qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); >>> >>> What happens when this is not a listen socket? I suggest setting >>> listen_fd to -1 during creation and not calling qemu_set_fd_handler() >> listen_fd isn't -1 here, and is one valid value when this function is >> executed. >>> when listen_fd is -1 here. If listen_fd is 0 then we'll register >>> net_socket_accept when standard input becomes ready! >>> >>>> closesocket(s->fd); >>>> + >>>> + s->fd = 0; >>> >>> -1 should be used since 0 is a valid file descriptor (standard input). >> OK. done, but In fact, some other places default fd to zero. > > Where? Maybe those places need to be fixed too. The danger with fd=0 > is that we call functions like read()/write()/close() on standard > input by mistake. When net_socket_accept() is registered, fd/listen_fd has been not zero in our codes. So that case you said will not happen for our codes. > > Stefan
-- Regards, Zhi Yong Wu