diff --git a/config-unix.mk b/config-unix.mk index 26dad80e..0236f09f 100644 --- a/config-unix.mk +++ b/config-unix.mk @@ -71,7 +71,7 @@ uv-platform.o: $(UV_OS_FILE) uv.h uv-unix.h $(CC) $(CPPFLAGS) $(CFLAGS) -c $(UV_OS_FILE) -o uv-platform.o uv-unix.o: uv-unix.c uv.h uv-unix.h - $(CC) $(CPPFLAGS) $(CFLAGS) -c uv-unix.c -o uv-unix.o + $(CC) $(CPPFLAGS) -Ieio $(CFLAGS) -c uv-unix.c -o uv-unix.o uv-common.o: uv-common.c uv.h uv-unix.h $(CC) $(CPPFLAGS) $(CFLAGS) -c uv-common.c -o uv-common.o diff --git a/uv-eio.h b/uv-eio.h index 0a58b419..2f2d3486 100644 --- a/uv-eio.h +++ b/uv-eio.h @@ -1,6 +1,9 @@ /* This header is private to libuv */ #ifndef UV_EIO_H_ #define UV_EIO_H_ + +#include "eio.h" + /* * Call this function to integrate libeio into the libuv event loop. It is * safe to call more than once. diff --git a/uv-unix.c b/uv-unix.c index 31d6b44a..400197d9 100644 --- a/uv-unix.c +++ b/uv-unix.c @@ -1482,13 +1482,66 @@ void uv_ares_destroy(ares_channel channel) { } +static int uv_getaddrinfo_done(eio_req* req) { + uv_getaddrinfo_t* handle = req->data; + + uv_unref(); + + free(handle->service); + free(handle->hostname); + + if (handle->retcode != 0) { + /* TODO how to display gai error strings? */ + uv_err_new(NULL, handle->retcode); + } + + handle->cb(handle, handle->retcode, handle->res); + + freeaddrinfo(handle->res); + handle->res = NULL; + + return 0; +} + + +static int getaddrinfo_thread_proc(eio_req *req) { + uv_getaddrinfo_t* handle = req->data; + + handle->retcode = getaddrinfo(handle->hostname, + handle->service, + &handle->hints, + &handle->res); + return 0; +} + + /* stub implementation of uv_getaddrinfo */ int uv_getaddrinfo(uv_getaddrinfo_t* handle, - uv_getaddrinfo_cb getaddrinfo_cb, - const char* node, + uv_getaddrinfo_cb cb, + const char* hostname, const char* service, const struct addrinfo* hints) { uv_eio_init(); - return -1; + + memset(handle, 0, sizeof(uv_getaddrinfo_t)); + memcpy(&handle->hints, hints, sizeof(struct addrinfo)); + + /* TODO security! check lengths, check return values. */ + + handle->cb = cb; + handle->hostname = strdup(hostname); + handle->service = strdup(service); + + /* TODO check handle->hostname == NULL */ + /* TODO check handle->service == NULL */ + + eio_req* req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT, + uv_getaddrinfo_done, handle); + + /* TODO check req == NULL ? */ + + uv_ref(); + + return 0; } diff --git a/uv-unix.h b/uv-unix.h index 3020de30..55d3a1a0 100644 --- a/uv-unix.h +++ b/uv-unix.h @@ -104,6 +104,12 @@ typedef struct { ev_io read_watcher; \ ev_io write_watcher; -#define UV_GETADDRINFO_PRIVATE_FIELDS /* TODO */ +#define UV_GETADDRINFO_PRIVATE_FIELDS \ + uv_getaddrinfo_cb cb; \ + struct addrinfo hints; \ + char* hostname; \ + char* service; \ + struct addrinfo* res; \ + int retcode; #endif /* UV_UNIX_H */