mirror of https://github.com/xemu-project/xemu.git
sockets: factor out create_fast_reuse_socket
Another refactoring step to prepare for fixing the problem exposed with the test-listen test in the previous commit Signed-off-by: Knut Omang <knut.omang@oracle.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
89382c3de5
commit
39f80521df
|
@ -149,6 +149,16 @@ int inet_ai_family_from_address(InetSocketAddress *addr,
|
||||||
return PF_UNSPEC;
|
return PF_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int create_fast_reuse_socket(struct addrinfo *e)
|
||||||
|
{
|
||||||
|
int slisten = qemu_socket(e->ai_family, e->ai_socktype, e->ai_protocol);
|
||||||
|
if (slisten < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
socket_set_fast_reuse(slisten);
|
||||||
|
return slisten;
|
||||||
|
}
|
||||||
|
|
||||||
static int try_bind(int socket, InetSocketAddress *saddr, struct addrinfo *e)
|
static int try_bind(int socket, InetSocketAddress *saddr, struct addrinfo *e)
|
||||||
{
|
{
|
||||||
#ifndef IPV6_V6ONLY
|
#ifndef IPV6_V6ONLY
|
||||||
|
@ -253,7 +263,8 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
||||||
getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
|
getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
|
||||||
uaddr,INET6_ADDRSTRLEN,uport,32,
|
uaddr,INET6_ADDRSTRLEN,uport,32,
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
slisten = qemu_socket(e->ai_family, e->ai_socktype, e->ai_protocol);
|
|
||||||
|
slisten = create_fast_reuse_socket(e);
|
||||||
if (slisten < 0) {
|
if (slisten < 0) {
|
||||||
if (!e->ai_next) {
|
if (!e->ai_next) {
|
||||||
error_setg_errno(errp, errno, "Failed to create socket");
|
error_setg_errno(errp, errno, "Failed to create socket");
|
||||||
|
@ -261,8 +272,6 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_set_fast_reuse(slisten);
|
|
||||||
|
|
||||||
port_min = inet_getport(e);
|
port_min = inet_getport(e);
|
||||||
port_max = saddr->has_to ? saddr->to + port_offset : port_min;
|
port_max = saddr->has_to ? saddr->to + port_offset : port_min;
|
||||||
for (p = port_min; p <= port_max; p++) {
|
for (p = port_min; p <= port_max; p++) {
|
||||||
|
|
Loading…
Reference in New Issue