Files

32 lines
637 B
C
Raw Permalink Normal View History

#include <netdb.h>
2016-03-01 19:43:11 -08:00
#include "asyncaddrinfo.h"
#include "peer.h"
#include "resolve.h"
void resolve_init() {
2016-03-01 19:43:11 -08:00
asyncaddrinfo_init(2);
}
void resolve_cleanup() {
2016-03-01 19:43:11 -08:00
asyncaddrinfo_cleanup();
}
void resolve(struct peer *peer, const char *node, const char *service, int flags) {
2016-03-01 19:43:11 -08:00
struct addrinfo hints = {
.ai_flags = AI_V4MAPPED | flags,
2016-03-01 19:43:11 -08:00
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
};
2016-03-01 19:43:11 -08:00
peer->fd = asyncaddrinfo_resolve(node, service, &hints);
peer_epoll_add(peer, EPOLLIN);
}
int resolve_result(struct peer *peer, struct addrinfo **addrs) {
2016-03-01 19:43:11 -08:00
int err = asyncaddrinfo_result(peer->fd, addrs);
peer->fd = -1;
return err;
}