Commit Graph

8 Commits

Author SHA1 Message Date
Eric Blake 0399293e5b util: Shorten references into SocketAddress
An upcoming patch will alter how simple unions, like SocketAddress,
are laid out, which will impact all lines of the form 'addr->u.XXX'
(expanding it to the longer 'addr->u.XXX.data').  For better
legibility in that patch, and less need for line wrapping, it's better
to use a temporary variable to reduce the effect of a layout change to
just the variable initializations, rather than every reference within
a SocketAddress.  Also, take advantage of some C99 initialization where
it makes sense (simplifying g_new0() to g_new()).

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1457021813-10704-7-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-05 10:41:52 +01:00
Peter Maydell 250f53ddaa Merge I/O fixes 2016/02/16 v1
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCAAGBQJWw0NlAAoJEL6G67QVEE/f1/UP/iw5KIjKJGUv+eF3GP5dx779
 6ZFuOfZ2QNGCon6uaRbfvZ/fsnyyHg/7WiXKO2QT/6dF+A602dbY5/HLfTq+5khr
 StNNlS5s12S81uWp4OspucHU6Vx0q7FFLfTLckPYg6Ban8nGW0CZH/KnllaKJZAu
 THJlaW6GecnYME4K8bWtBL2kiHv7AXjmztbtUedAtGH82DCMYkkzRE9EJgk0Fh/J
 Kdf0LSGtbuY0v1VgusFB5bi1nBQd2wTYhGCZztRqB8HO+FTpj16hv/xm2IDq03N/
 iV1OyB1dV6Yuc/ZeHINrKCtnkCZj2OhY6UC8u0R5Hnfc6P9sNr3e3dov92bN7L6r
 OQoE03kqaHg0c2Q0gp8jbGcSKHq0BcaCg+6MgODkUH4XZXMi8YdZoUHu/95rGblL
 9u4j2Fnplthz/PCfsbIddb5rnetUnF0X8QHIdMvvhneghwyCQTZ9emFC3LN/HWyY
 vbFURfxDWcmYQ8idAZi3kLsCCD/5M1wjj+KTMkORoKAVrJVWkM4zcAMoKfipONEg
 XHBsMlQJjhROcMltRf+IUHIV06IU+zxNAU8nJS+ZnYAxkWpr/Ep4Ah5LdLSIN6mQ
 /8hsCmkWGhGFlCSkZU45aXg5D4XzjrGYhvKzx8M3nM4mXLfcaxRxeLgpLivQe0Po
 X/IoYKebusTQOwrJX1IJ
 =+3s5
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/berrange/tags/pull-io-next-2016-02-16-1' into staging

Merge I/O fixes 2016/02/16 v1

# gpg: Signature made Tue 16 Feb 2016 15:42:29 GMT using RSA key ID 15104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>"
# gpg:                 aka "Daniel P. Berrange <berrange@redhat.com>"

* remotes/berrange/tags/pull-io-next-2016-02-16-1:
  io: convert QIOChannelBuffer to use uint8_t instead of char
  io: introduce helper for creating channels from file descriptors
  io: improve docs for QIOChannelSocket async functions

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-02-16 15:47:35 +00:00
Peter Maydell 681c28a33e tests: Clean up includes
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: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
2016-02-16 14:29:27 +00:00
Daniel P. Berrange c767ae62b9 io: introduce helper for creating channels from file descriptors
Depending on what object a file descriptor refers to a different
type of IO channel will be needed - either a QIOChannelFile or
a QIOChannelSocket. Introduce a qio_channel_new_fd() method
which will return the appropriate channel implementation.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-02-15 14:49:00 +00:00
Daniel P. Berrange 7b3c618ad0 io: fix stack allocation when sending of file descriptors
When sending file descriptors over a socket, we have to
allocate a data buffer to hold the FDs in the scmsghdr.
Unfortunately we allocated the buffer on the stack inside
an if () {} block, but called sendmsg() outside the block.
So the stack bytes holding the FDs were liable to be
overwritten with other data. By luck this was not a problem
when sending 1 FD, but if sending 2 or more then it would
fail.

The fix is to simply move the variables outside the nested
'if' block. To keep valgrind quiet we also zero-initialize
the 'control' buffer.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-12-23 10:53:03 +00:00
Daniel P. Berrange bead59946a io: fix setting of QIO_CHANNEL_FEATURE_FD_PASS on server connections
The QIO_CHANNEL_FEATURE_FD_PASS feature flag is set in the
qio_channel_socket_set_fd() method, however, this only deals
with client side connections.

To ensure server side connections also have the feature flag
set, we must set it in qio_channel_socket_accept() too. This
also highlighted a typo fix where the code updated the
sockaddr struct in the wrong object instance.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-12-22 18:19:32 +00:00
Daniel P. Berrange e4d2edc9d0 io: bind to loopback IP addrs in test suite
The test suite currently binds to 0.0.0.0 or ::, which covers
all interfaces of the machine. It is bad practice for test
suite to open publically accessible ports on a machine, so
switch to use loopback addrs 127.0.0.1 or ::1.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-12-22 18:19:08 +00:00
Daniel P. Berrange 559607ea17 io: add QIOChannelSocket class
Implement a QIOChannel subclass that supports sockets I/O.
The implementation is able to manage a single socket file
descriptor, whether a TCP/UNIX listener, TCP/UNIX connection,
or a UDP datagram. It provides APIs which can listen and
connect either asynchronously or synchronously. Since there
is no asynchronous DNS lookup API available, it uses the
QIOTask helper for spawning a background thread to ensure
non-blocking operation.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-12-18 12:18:31 +00:00