diff options
author | Juan Quintela <quintela@redhat.com> | 2019-08-19 14:48:21 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2019-09-03 23:24:42 +0200 |
commit | e5b6353cf25c99c3f08bf51e29933352f7140e8f (patch) | |
tree | 5d90c11a5ed6ba280889656555223005cd154c84 /util/qemu-sockets.c | |
parent | 3483534ec314f6057e66966bfceaa9df02c28fbf (diff) |
socket: Add backlog parameter to socket_listen
Current parameter was always one. We continue with that value for now
in all callers.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
Moved trace to socket_listen
Diffstat (limited to 'util/qemu-sockets.c')
-rw-r--r-- | util/qemu-sockets.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index e3a1666578..98ff3a1cce 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -31,6 +31,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qemu/cutils.h" +#include "trace.h" #ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0 @@ -207,6 +208,7 @@ static int try_bind(int socket, InetSocketAddress *saddr, struct addrinfo *e) static int inet_listen_saddr(InetSocketAddress *saddr, int port_offset, + int num, Error **errp) { struct addrinfo ai,*res,*e; @@ -309,7 +311,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr, goto listen_failed; } } else { - if (!listen(slisten, 1)) { + if (!listen(slisten, num)) { goto listen_ok; } if (errno != EADDRINUSE) { @@ -774,6 +776,7 @@ static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp) } static int vsock_listen_saddr(VsockSocketAddress *vaddr, + int num, Error **errp) { struct sockaddr_vm svm; @@ -795,7 +798,7 @@ static int vsock_listen_saddr(VsockSocketAddress *vaddr, return -1; } - if (listen(slisten, 1) != 0) { + if (listen(slisten, num) != 0) { error_setg_errno(errp, errno, "Failed to listen on socket"); closesocket(slisten); return -1; @@ -836,6 +839,7 @@ static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp) } static int vsock_listen_saddr(VsockSocketAddress *vaddr, + int num, Error **errp) { vsock_unsupported(errp); @@ -853,6 +857,7 @@ static int vsock_parse(VsockSocketAddress *addr, const char *str, #ifndef _WIN32 static int unix_listen_saddr(UnixSocketAddress *saddr, + int num, Error **errp) { struct sockaddr_un un; @@ -914,7 +919,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, error_setg_errno(errp, errno, "Failed to bind socket to %s", path); goto err; } - if (listen(sock, 1) < 0) { + if (listen(sock, num) < 0) { error_setg_errno(errp, errno, "Failed to listen on socket"); goto err; } @@ -981,6 +986,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp) #else static int unix_listen_saddr(UnixSocketAddress *saddr, + int num, Error **errp) { error_setg(errp, "unix sockets are not available on windows"); @@ -1004,7 +1010,7 @@ int unix_listen(const char *str, Error **errp) saddr = g_new0(UnixSocketAddress, 1); saddr->path = g_strdup(str); - sock = unix_listen_saddr(saddr, errp); + sock = unix_listen_saddr(saddr, 1, errp); qapi_free_UnixSocketAddress(saddr); return sock; } @@ -1061,9 +1067,13 @@ fail: return NULL; } -static int socket_get_fd(const char *fdstr, Error **errp) +static int socket_get_fd(const char *fdstr, int num, Error **errp) { int fd; + if (num != 1) { + error_setg_errno(errp, EINVAL, "socket_get_fd: too many connections"); + return -1; + } if (cur_mon) { fd = monitor_get_fd(cur_mon, fdstr, errp); if (fd < 0) { @@ -1099,7 +1109,7 @@ int socket_connect(SocketAddress *addr, Error **errp) break; case SOCKET_ADDRESS_TYPE_FD: - fd = socket_get_fd(addr->u.fd.str, errp); + fd = socket_get_fd(addr->u.fd.str, 1, errp); break; case SOCKET_ADDRESS_TYPE_VSOCK: @@ -1112,25 +1122,26 @@ int socket_connect(SocketAddress *addr, Error **errp) return fd; } -int socket_listen(SocketAddress *addr, Error **errp) +int socket_listen(SocketAddress *addr, int num, Error **errp) { int fd; + trace_socket_listen(num); switch (addr->type) { case SOCKET_ADDRESS_TYPE_INET: - fd = inet_listen_saddr(&addr->u.inet, 0, errp); + fd = inet_listen_saddr(&addr->u.inet, 0, num, errp); break; case SOCKET_ADDRESS_TYPE_UNIX: - fd = unix_listen_saddr(&addr->u.q_unix, errp); + fd = unix_listen_saddr(&addr->u.q_unix, num, errp); break; case SOCKET_ADDRESS_TYPE_FD: - fd = socket_get_fd(addr->u.fd.str, errp); + fd = socket_get_fd(addr->u.fd.str, num, errp); break; case SOCKET_ADDRESS_TYPE_VSOCK: - fd = vsock_listen_saddr(&addr->u.vsock, errp); + fd = vsock_listen_saddr(&addr->u.vsock, num, errp); break; default: |