mirror of https://github.com/getdnsapi/getdns.git
commit
56810e21c8
|
@ -44,7 +44,6 @@
|
|||
struct getdns_libuv_data {
|
||||
uv_loop_t* loop;
|
||||
uv_poll_t* poll_handle;
|
||||
uint8_t polling;
|
||||
};
|
||||
|
||||
static void request_count_changed(uint32_t request_count, struct getdns_libuv_data *uv_data);
|
||||
|
@ -65,12 +64,10 @@ getdns_libuv_cb(uv_poll_t* handle, int status, int events) {
|
|||
|
||||
static void
|
||||
request_count_changed(uint32_t request_count, struct getdns_libuv_data *uv_data) {
|
||||
if (request_count > 0 && uv_data->polling == 0) {
|
||||
if (request_count > 0 && !uv_is_active((uv_handle_t*) uv_data->poll_handle)) {
|
||||
uv_poll_start(uv_data->poll_handle, UV_READABLE, getdns_libuv_cb);
|
||||
uv_data->polling = 1;
|
||||
} else if (request_count == 0 && uv_data->polling == 1) {
|
||||
} else if (request_count == 0 && uv_is_active((uv_handle_t*) uv_data->poll_handle)) {
|
||||
uv_poll_stop(uv_data->poll_handle);
|
||||
uv_data->polling = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,9 +83,7 @@ getdns_libuv_timeout_cb(uv_timer_t* handle, int status) {
|
|||
|
||||
static void
|
||||
getdns_libuv_close_cb(uv_handle_t* handle) {
|
||||
if (handle) {
|
||||
free(handle);
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
|
||||
/* getdns extension functions */
|
||||
|
@ -166,9 +161,12 @@ getdns_extension_set_libuv_loop(struct getdns_context *context,
|
|||
}
|
||||
int fd = getdns_context_fd(context);
|
||||
uv_data->poll_handle = (uv_poll_t*) malloc(sizeof(uv_poll_t));
|
||||
if (!uv_data->poll_handle) {
|
||||
free(uv_data);
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
uv_poll_init(uv_loop, uv_data->poll_handle, fd);
|
||||
uv_data->poll_handle->data = context;
|
||||
uv_data->loop = uv_loop;
|
||||
uv_data->polling = 0;
|
||||
return getdns_extension_set_eventloop(context, &LIBUV_EXT, uv_data);
|
||||
} /* getdns_extension_set_libuv_loop */
|
||||
|
|
Loading…
Reference in New Issue