uv_ares utility methods put into new uv-common.c file
This commit is contained in:
parent
fa514948fc
commit
5785961893
51
uv-common.c
51
uv-common.c
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "uv.h"
|
||||
#include "uv-common.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h> /* NULL */
|
||||
@ -29,6 +30,9 @@
|
||||
#include "ares_config.h"
|
||||
#include "c-ares/inet_net_pton.h"
|
||||
|
||||
/* list used for ares task handles */
|
||||
static uv_ares_task_t* uv_ares_handles_ = NULL;
|
||||
|
||||
|
||||
static uv_counters_t counters;
|
||||
|
||||
@ -106,3 +110,50 @@ struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
/* find matching ares handle in list */
|
||||
void uv_add_ares_handle(uv_ares_task_t* handle) {
|
||||
handle->ares_next = uv_ares_handles_;
|
||||
handle->ares_prev = NULL;
|
||||
|
||||
if (uv_ares_handles_) {
|
||||
uv_ares_handles_->ares_prev = handle;
|
||||
}
|
||||
uv_ares_handles_ = handle;
|
||||
}
|
||||
|
||||
/* find matching ares handle in list */
|
||||
/* TODO: faster lookup */
|
||||
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) {
|
||||
uv_ares_task_t* handle = uv_ares_handles_;
|
||||
while (handle != NULL) {
|
||||
if (handle->sock == sock) {
|
||||
break;
|
||||
}
|
||||
handle = handle->ares_next;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* remove ares handle in list */
|
||||
void uv_remove_ares_handle(uv_ares_task_t* handle) {
|
||||
if (handle == uv_ares_handles_) {
|
||||
uv_ares_handles_ = handle->ares_next;
|
||||
}
|
||||
|
||||
if (handle->ares_next) {
|
||||
handle->ares_next->ares_prev = handle->ares_prev;
|
||||
}
|
||||
|
||||
if (handle->ares_prev) {
|
||||
handle->ares_prev->ares_next = handle->ares_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */
|
||||
int uv_ares_handles_empty() {
|
||||
return uv_ares_handles_ ? 0 : 1;
|
||||
}
|
||||
|
||||
51
uv-common.h
Normal file
51
uv-common.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is private to libuv. It provides common functionality to both
|
||||
* Windows and Unix backends.
|
||||
*/
|
||||
|
||||
#ifndef UV_COMMON_H_
|
||||
#define UV_COMMON_H_
|
||||
|
||||
#include "uv.h"
|
||||
|
||||
/*
|
||||
* Subclass of uv_handle_t. Used for integration of c-ares.
|
||||
*/
|
||||
typedef struct uv_ares_task_s uv_ares_task_t;
|
||||
|
||||
struct uv_ares_task_s {
|
||||
UV_HANDLE_FIELDS
|
||||
UV_ARES_TASK_PRIVATE_FIELDS
|
||||
uv_ares_task_t* ares_prev;
|
||||
uv_ares_task_t* ares_next;
|
||||
};
|
||||
|
||||
|
||||
void uv_remove_ares_handle(uv_ares_task_t* handle);
|
||||
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock);
|
||||
void uv_add_ares_handle(uv_ares_task_t* handle);
|
||||
int uv_ares_handles_empty();
|
||||
|
||||
|
||||
#endif /* UV_COMMON_H_ */
|
||||
43
uv-win.c
43
uv-win.c
@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "uv.h"
|
||||
#include "uv-common.h"
|
||||
#include "tree.h"
|
||||
|
||||
/*
|
||||
@ -216,9 +217,6 @@ static char uv_zero_[] = "";
|
||||
void uv_ares_process(uv_ares_action_t* handle, uv_req_t* req);
|
||||
void uv_ares_task_cleanup(uv_ares_task_t* handle, uv_req_t* req);
|
||||
|
||||
/* list used for ares task handles */
|
||||
static uv_ares_task_t* uv_ares_handles_ = NULL;
|
||||
|
||||
/* memory used per ares_channel */
|
||||
struct uv_ares_channel_s {
|
||||
ares_channel channel;
|
||||
@ -1795,45 +1793,6 @@ uint64_t uv_hrtime(void) {
|
||||
assert(0 && "implement me");
|
||||
}
|
||||
|
||||
/* find matching ares handle in list */
|
||||
void uv_add_ares_handle(uv_ares_task_t* handle) {
|
||||
handle->ares_next = uv_ares_handles_;
|
||||
handle->ares_prev = NULL;
|
||||
|
||||
if (uv_ares_handles_) {
|
||||
uv_ares_handles_->ares_prev = handle;
|
||||
}
|
||||
uv_ares_handles_ = handle;
|
||||
}
|
||||
|
||||
/* find matching ares handle in list */
|
||||
/* TODO: faster lookup */
|
||||
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) {
|
||||
uv_ares_task_t* handle = uv_ares_handles_;
|
||||
while (handle != NULL) {
|
||||
if (handle->sock == sock) {
|
||||
break;
|
||||
}
|
||||
handle = handle->ares_next;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* remove ares handle in list */
|
||||
void uv_remove_ares_handle(uv_ares_task_t* handle) {
|
||||
if (handle == uv_ares_handles_) {
|
||||
uv_ares_handles_ = handle->ares_next;
|
||||
}
|
||||
|
||||
if (handle->ares_next) {
|
||||
handle->ares_next->ares_prev = handle->ares_prev;
|
||||
}
|
||||
|
||||
if (handle->ares_prev) {
|
||||
handle->ares_prev->ares_next = handle->ares_next;
|
||||
}
|
||||
}
|
||||
|
||||
/* thread pool callback when socket is signalled */
|
||||
VOID CALLBACK uv_ares_socksignal_tp(void* parameter, BOOLEAN timerfired) {
|
||||
|
||||
19
uv-win.h
19
uv-win.h
@ -107,15 +107,8 @@ typedef struct uv_buf_t {
|
||||
unsigned int flags; \
|
||||
uv_err_t error;
|
||||
|
||||
#define UV_ARES_ACTION_PRIVATE_FIELDS \
|
||||
struct uv_req_s ares_req; \
|
||||
SOCKET sock; \
|
||||
int read; \
|
||||
int write;
|
||||
|
||||
#define UV_ARES_TASK_PRIVATE_FIELDS \
|
||||
uv_ares_task_t* ares_prev; \
|
||||
uv_ares_task_t* ares_next; \
|
||||
struct uv_req_s ares_req; \
|
||||
SOCKET sock; \
|
||||
HANDLE h_wait; \
|
||||
@ -132,6 +125,18 @@ typedef struct uv_buf_t {
|
||||
struct addrinfoW* res; \
|
||||
int retcode;
|
||||
|
||||
/*
|
||||
* Subclass of uv_handle_t. Used for integration of c-ares.
|
||||
*/
|
||||
typedef struct uv_ares_action_s uv_ares_action_t;
|
||||
|
||||
struct uv_ares_action_s {
|
||||
UV_HANDLE_FIELDS
|
||||
struct uv_req_s ares_req;
|
||||
SOCKET sock;
|
||||
int read;
|
||||
int write;
|
||||
};
|
||||
|
||||
int uv_utf16_to_utf8(wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size);
|
||||
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size);
|
||||
|
||||
25
uv.h
25
uv.h
@ -48,10 +48,6 @@ typedef struct uv_check_s uv_check_t;
|
||||
typedef struct uv_idle_s uv_idle_t;
|
||||
typedef struct uv_req_s uv_req_t;
|
||||
typedef struct uv_async_s uv_async_t;
|
||||
/* TODO: make private */
|
||||
typedef struct uv_ares_task_s uv_ares_task_t;
|
||||
/* TODO: make private */
|
||||
typedef struct uv_ares_action_s uv_ares_action_t;
|
||||
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
|
||||
|
||||
|
||||
@ -379,25 +375,6 @@ void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat);
|
||||
int64_t uv_timer_get_repeat(uv_timer_t* timer);
|
||||
|
||||
|
||||
/*
|
||||
* Subclass of uv_handle_t. Used for integration of c-ares.
|
||||
* TODO: make private
|
||||
*/
|
||||
struct uv_ares_task_s {
|
||||
UV_HANDLE_FIELDS
|
||||
UV_ARES_TASK_PRIVATE_FIELDS
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Subclass of uv_handle_t. Used for integration of c-ares.
|
||||
* TODO: make private
|
||||
*/
|
||||
struct uv_ares_action_s {
|
||||
UV_HANDLE_FIELDS
|
||||
UV_ARES_ACTION_PRIVATE_FIELDS
|
||||
};
|
||||
|
||||
/* c-ares integration initialize and terminate */
|
||||
int uv_ares_init_options(ares_channel *channelptr,
|
||||
struct ares_options *options,
|
||||
@ -479,8 +456,6 @@ union uv_any_handle {
|
||||
uv_idle_t idle;
|
||||
uv_async_t async;
|
||||
uv_timer_t timer;
|
||||
uv_ares_task_t arest;
|
||||
uv_ares_action_t aresa;
|
||||
uv_getaddrinfo_t getaddrinfo;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user