/* Licensed under BSD-MIT - see LICENSE file for details */
#include <ccan/net/net.h>
#include <ccan/noerr/noerr.h>
-#include <sys/types.h>
-#include <sys/socket.h>
#include <poll.h>
-#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
}
-int net_connect_async(const struct addrinfo *addrinfo, struct pollfd pfds[2])
+int net_connect_async(const struct addrinfo *addrinfo, struct pollfd *pfds)
{
const struct addrinfo *addr[2] = { NULL, NULL };
unsigned int i;
return -1;
}
-void net_connect_abort(struct pollfd pfds[2])
+void net_connect_abort(struct pollfd *pfds)
{
unsigned int i;
}
}
-int net_connect_complete(struct pollfd pfds[2])
+int net_connect_complete(struct pollfd *pfds)
{
unsigned int i;
static int make_listen_fd(const struct addrinfo *addrinfo)
{
- int saved_errno, fd, on = 1;
+ int fd, on = 1;
fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
addrinfo->ai_protocol);
if (fd < 0)
return -1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
+ goto fail;
+
if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
goto fail;
return fd;
fail:
- saved_errno = errno;
- close(fd);
- errno = saved_errno;
+ close_noerr(fd);
return -1;
}