Skip to content
Snippets Groups Projects
  1. Mar 13, 2023
    • Marc-André Lureau's avatar
      win32: avoid mixing SOCKET and file descriptor space · abe34282
      Marc-André Lureau authored
      
      Until now, a win32 SOCKET handle is often cast to an int file
      descriptor, as this is what other OS use for sockets. When necessary,
      QEMU eventually queries whether it's a socket with the help of
      fd_is_socket(). However, there is no guarantee of conflict between the
      fd and SOCKET space. Such conflict would have surprising consequences,
      we shouldn't mix them.
      
      Also, it is often forgotten that SOCKET must be closed with
      closesocket(), and not close().
      
      Instead, let's make the win32 socket wrapper functions return and take a
      file descriptor, and let util/ wrappers do the fd/SOCKET conversion as
      necessary. A bit of adaptation is necessary in io/ as well.
      
      Unfortunately, we can't drop closesocket() usage, despite
      _open_osfhandle() documentation claiming transfer of ownership, testing
      shows bad behaviour if you forget to call closesocket().
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Message-Id: <20230221124802.4103554-15-marcandre.lureau@redhat.com>
      abe34282
    • Marc-André Lureau's avatar
      win32/socket: introduce qemu_socket_select() helper · f5fd677a
      Marc-André Lureau authored
      
      This is a wrapper for WSAEventSelect, with Error handling. By default,
      it will produce a warning, so callers don't have to be modified
      now, and yet we can spot potential mis-use.
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Message-Id: <20230221124802.4103554-7-marcandre.lureau@redhat.com>
      f5fd677a
  2. Oct 26, 2022
    • Bin Meng's avatar
      io/channel-watch: Fix socket watch on Windows · 23f77f05
      Bin Meng authored
      
      Random failure was observed when running qtests on Windows due to
      "Broken pipe" detected by qmp_fd_receive(). What happened is that
      the qtest executable sends testing data over a socket to the QEMU
      under test but no response is received. The errno of the recv()
      call from the qtest executable indicates ETIMEOUT, due to the qmp
      chardev's tcp_chr_read() is never called to receive testing data
      hence no response is sent to the other side.
      
      tcp_chr_read() is registered as the callback of the socket watch
      GSource. The reason of the callback not being called by glib, is
      that the source check fails to indicate the source is ready. There
      are two socket watch sources created to monitor the same socket
      event object from the char-socket backend in update_ioc_handlers().
      During the source check phase, qio_channel_socket_source_check()
      calls WSAEnumNetworkEvents() to discover occurrences of network
      events for the indicated socket, clear internal network event records,
      and reset the event object. Testing shows that if we don't reset the
      event object by not passing the event handle to WSAEnumNetworkEvents()
      the symptom goes away and qtest runs very stably.
      
      It seems we don't need to call WSAEnumNetworkEvents() at all, as we
      don't parse the result of WSANETWORKEVENTS returned from this API.
      We use select() to poll the socket status. Fix this instability by
      dropping the WSAEnumNetworkEvents() call.
      
      Some side notes:
      
      During the testing, I removed the following codes in update_ioc_handlers():
      
        remove_hup_source(s);
        s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
        g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
                              chr, NULL);
        g_source_attach(s->hup_source, chr->gcontext);
      
      and such change also makes the symptom go away.
      
      And if I moved the above codes to the beginning, before the call to
      io_add_watch_poll(), the symptom also goes away.
      
      It seems two sources watching on the same socket event object is
      the key that leads to the instability. The order of adding a source
      watch seems to also play a role but I can't explain why.
      Hopefully a Windows and glib expert could explain this behavior.
      
      Signed-off-by: default avatarBin Meng <bin.meng@windriver.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      23f77f05
    • Bin Meng's avatar
      io/channel-watch: Drop the unnecessary cast · 6c822a03
      Bin Meng authored
      
      There is no need to do a type cast on ssource->socket as it is
      already declared as a SOCKET.
      
      Suggested-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarBin Meng <bin.meng@windriver.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      6c822a03
    • Bin Meng's avatar
      io/channel-watch: Drop a superfluous '#ifdef WIN32' · 985be62d
      Bin Meng authored
      
      In the win32 version qio_channel_create_socket_watch() body there is
      no need to do a '#ifdef WIN32'.
      
      Signed-off-by: default avatarBin Meng <bin.meng@windriver.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      985be62d
  3. Oct 29, 2020
  4. Oct 27, 2020
  5. Feb 21, 2017
  6. Mar 10, 2016
  7. Feb 04, 2016
    • Peter Maydell's avatar
      io: Clean up includes · cae9fc56
      Peter Maydell authored
      
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-14-git-send-email-peter.maydell@linaro.org
      cae9fc56
  8. Dec 18, 2015
    • Daniel P. Berrangé's avatar
      io: add helper module for creating watches on FDs · 1c809fa0
      Daniel P. Berrangé authored
      
      A number of the channel implementations will require the
      ability to create watches on file descriptors / sockets.
      To avoid duplicating this code in each channel, provide a
      helper API for dealing with file descriptor watches.
      
      There are two watch implementations provided. The first
      is useful for bi-directional file descriptors such as
      sockets, regular files, character devices, etc. The
      second works with a pair of unidirectional file descriptors
      such as pipes.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      1c809fa0
Loading