$OpenBSD: patch-libs_uv_uv_c,v 1.3 2020/05/19 19:36:53 thfr Exp $

add resolve function from https://github.com/motion-twin
commit 61be4ae30e52a5ffcfa9212b9b81d4e06225c2ea

Index: libs/uv/uv.c
--- libs/uv/uv.c.orig
+++ libs/uv/uv.c
@@ -94,6 +94,46 @@ static void on_write( uv_write_t *wr, int status ) {
 	on_close((uv_handle_t*)wr);
 }
 
+void on_resolve(uv_getaddrinfo_t *h, int status, struct addrinfo *resp) {
+	vclosure *cb = (vclosure*)h->data;
+	hl_remove_root(&h->data);
+	int ipv4 = 0;
+	vbyte *ipv6 = NULL;
+	if (status == 0 && resp) {
+		if (resp->ai_family == AF_INET) {
+			ipv4 = ((struct sockaddr_in*)resp->ai_addr)->sin_addr.s_addr;
+		} else if (resp->ai_family == AF_INET6) {
+			struct in6_addr *ip = &((struct sockaddr_in6 *)resp->ai_addr)->sin6_addr;
+			ipv6 = hl_copy_bytes((vbyte*)ip, sizeof(ip));
+		} else {
+			hl_error("Unsupported address family");
+		}
+	}
+
+	if (cb->hasValue)
+		((void(*)(void*, int, int, vbyte*))cb->fun)(cb->value, status, ipv4, ipv6);
+	else
+		((void(*)(int, int, vbyte*))cb->fun)(status, ipv4, ipv6);
+
+	free(h);
+}
+
+HL_PRIM bool HL_NAME(resolve)(uv_loop_t *loop, char *node, int ihints, vclosure *cb) {
+	// TODO hints
+	uv_getaddrinfo_t *h = UV_ALLOC(uv_getaddrinfo_t);
+	memset(h, 0, sizeof(h));
+	h->data = (void*)cb;
+	int r = uv_getaddrinfo(loop, h, on_resolve, node, NULL, NULL);
+	if (r) {
+		free(h);
+		return false;
+	}
+	hl_add_root(&h->data);
+	return true;
+}
+
+DEFINE_PRIM(_VOID, resolve, _LOOP _BYTES _I32 _FUN(_VOID, _I32 _I32 _BYTES));
+
 HL_PRIM bool HL_NAME(stream_write)( uv_stream_t *s, vbyte *b, int size, vclosure *c ) {
 	uv_write_t *wr = UV_ALLOC(uv_write_t);
 	events_data *d = init_hl_data((uv_handle_t*)wr);
