unix: initial attempt at uv_getaddrinfo
This commit is contained in:
parent
65b772a067
commit
08809b2d04
@ -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
|
||||
|
||||
3
uv-eio.h
3
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.
|
||||
|
||||
59
uv-unix.c
59
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;
|
||||
}
|
||||
|
||||
|
||||
@ -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 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user