summaryrefslogtreecommitdiff
path: root/io/channel-socket.c
AgeCommit message (Collapse)AuthorFilesLines
2016-03-22include/qemu/osdep.h: Don't include qapi/error.hMarkus Armbruster1-0/+1
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the Error typedef. Since then, we've moved to include qemu/osdep.h everywhere. Its file comment explains: "To avoid getting into possible circular include dependencies, this file should not include any other QEMU headers, with the exceptions of config-host.h, compiler.h, os-posix.h and os-win32.h, all of which are doing a similar job to this file and are under similar constraints." qapi/error.h doesn't do a similar job, and it doesn't adhere to similar constraints: it includes qapi-types.h. That's in excess of 100KiB of crap most .c files don't actually need. Add the typedef to qemu/typedefs.h, and include that instead of qapi/error.h. Include qapi/error.h in .c files that need it and don't get it now. Include qapi-types.h in qom/object.h for uint16List. Update scripts/clean-includes accordingly. Update it further to match reality: replace config.h by config-target.h, add sysemu/os-posix.h, sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h comment quoted above similarly. This reduces the number of objects depending on qapi/error.h from "all of them" to less than a third. Unfortunately, the number depending on qapi-types.h shrinks only a little. More work is needed for that one. Signed-off-by: Markus Armbruster <armbru@redhat.com> [Fix compilation without the spice devel packages. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-10osdep: remove use of socket_error() from all codeDaniel P. Berrange1-19/+19
Now that QEMU wraps the Win32 sockets methods to automatically set errno upon failure, there is no reason for callers to use the socket_error() method. They can rely on accessing errno even on Win32. Remove all use of socket_error() from general code, leaving it as a static method in oslib-win32.c only. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10io: implement socket watch for win32 using WSAEventSelect+selectPaolo Bonzini1-6/+28
On Win32 we cannot directly poll on socket handles. Instead we create a Win32 event object and associate the socket handle with the event. When the event signals readyness we then have to use select to determine which events are ready. Creating Win32 events is moderately heavyweight, so we don't want todo it every time we create a GSource, so this associates a single event with a QIOChannel. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10io: remove checking of EWOULDBLOCKDaniel P. Berrange1-4/+2
Since we now canonicalize WSAEWOULDBLOCK into EAGAIN there is no longer any need to explicitly check EWOULDBLOCK for Win32. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10io: use qemu_accept to ensure SOCK_CLOEXEC is setDaniel P. Berrange1-2/+2
The QIOChannelSocket code mistakenly uses the bare accept() function which does not set SOCK_CLOEXEC. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-03-10io: introduce qio_channel_create_socket_watchPaolo Bonzini1-3/+3
Sockets are not in the same namespace as file descriptors on Windows. As an initial step, introduce separate APIs for file descriptor and socket watches. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-10io: fix copy+paste mistake in socket error messageDaniel P. Berrange1-1/+1
s/write/read/ in the error message reported after readmsg() fails Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-02-09qemu-char, io: fix ordering of arguments for UDP socket creationPaolo Bonzini1-1/+1
Two wrongs make a right, but they should be fixed anyway. Cc: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <1455015557-15106-1-git-send-email-pbonzini@redhat.com>
2016-02-04io: Clean up includesPeter Maydell1-0/+1
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> Message-id: 1454089805-5470-14-git-send-email-peter.maydell@linaro.org
2016-01-20io: use memset instead of { 0 } for initializing arrayDaniel P. Berrange1-1/+5
Some versions of GCC on OS-X complain about CMSG_SPACE not being constant size, which prevents use of { 0 } io/channel-socket.c: In function 'qio_channel_socket_writev': io/channel-socket.c:497:18: error: variable-sized object may not be initialized char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; The compiler is at fault here, but it is nicer to avoid tickling this compiler bug by using memset instead. Reviewed-By: John Arbuckle <programmingkidx@gmail.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-01-19io: fix sign of errno value passed to error reportDaniel P. Berrange1-1/+1
When reporting the number of FDs has been exceeded, pass EINVAL to error_setg_errno, rather than -EINVAL. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-12-23io: fix stack allocation when sending of file descriptorsDaniel P. Berrange1-4/+3
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-22io: fix setting of QIO_CHANNEL_FEATURE_FD_PASS on server connectionsDaniel P. Berrange1-2/+8
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-18io: add QIOChannelSocket classDaniel P. Berrange1-0/+741
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>