Commit 10103e6e authored by Marek Vavruša's avatar Marek Vavruša

daemon: cleanup worker

parent a1846a76
......@@ -17,11 +17,8 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <uv.h>
#include <libknot/internal/sockaddr.h>
#include <libknot/errcode.h>
#include "lib/defines.h"
#include "lib/resolve.h"
......@@ -47,15 +44,14 @@ static void tty_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
}
static void tty_alloc(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) {
buf->len = suggested;
buf->base = malloc(suggested);
buf->len = suggested;
buf->base = malloc(suggested);
}
void signal_handler(uv_signal_t *handle, int signum)
{
uv_stop(uv_default_loop());
uv_signal_stop(handle);
exit(1);
}
static void help(int argc, char *argv[])
......
......@@ -23,14 +23,14 @@
static void buf_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{
struct worker_ctx *worker = handle->data;
buf->base = mm_alloc(worker->pool, suggested_size);
buf->base = mm_alloc(worker->mm, suggested_size);
buf->len = suggested_size;
}
static void buf_free(uv_handle_t* handle, const uv_buf_t* buf)
{
struct worker_ctx *worker = handle->data;
mm_free(worker->pool, buf->base);
mm_free(worker->mm, buf->base);
}
static void tcp_send(uv_handle_t *handle, const knot_pkt_t *answer)
......@@ -49,10 +49,9 @@ static void tcp_send(uv_handle_t *handle, const knot_pkt_t *answer)
static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
{
struct worker_ctx *worker = handle->data;
assert(worker->pool);
/* Check the incoming wire length (malformed, EOF or error). */
if (nread < sizeof(uint16_t)) {
if (nread < (ssize_t) sizeof(uint16_t)) {
buf_free((uv_handle_t *)handle, buf);
tcp_unbind((uv_handle_t *)handle);
free(handle);
......@@ -63,8 +62,8 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
nread = wire_read_u16((const uint8_t *)buf->base);
/* Create packets */
knot_pkt_t *query = knot_pkt_new(buf->base + sizeof(uint16_t), nread, worker->pool);
knot_pkt_t *answer = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, worker->pool);
knot_pkt_t *query = knot_pkt_new(buf->base + sizeof(uint16_t), nread, worker->mm);
knot_pkt_t *answer = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, worker->mm);
/* Resolve */
int ret = worker_exec(worker, answer, query);
......
......@@ -22,14 +22,14 @@
static void buf_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{
struct worker_ctx *worker = handle->data;
buf->base = mm_alloc(worker->pool, suggested_size);
buf->base = mm_alloc(worker->mm, suggested_size);
buf->len = suggested_size;
}
static void buf_free(uv_handle_t* handle, const uv_buf_t* buf)
{
struct worker_ctx *worker = handle->data;
mm_free(worker->pool, buf->base);
mm_free(worker->mm, buf->base);
}
static void udp_send(uv_udp_t *handle, knot_pkt_t *answer, const struct sockaddr *addr)
......@@ -42,7 +42,6 @@ static void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf,
const struct sockaddr *addr, unsigned flags)
{
struct worker_ctx *worker = handle->data;
assert(worker->pool);
/* Check the incoming wire length. */
if (nread < KNOT_WIRE_HEADER_SIZE) {
......@@ -51,8 +50,8 @@ static void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf,
}
/* Create packets */
knot_pkt_t *query = knot_pkt_new(buf->base, nread, worker->pool);
knot_pkt_t *answer = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, worker->pool);
knot_pkt_t *query = knot_pkt_new(buf->base, nread, worker->mm);
knot_pkt_t *answer = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, worker->mm);
/* Resolve */
int ret = worker_exec(worker, answer, query);
......
......@@ -26,7 +26,7 @@
*/
struct worker_ctx {
struct kr_context resolve;
mm_ctx_t *pool;
mm_ctx_t *mm;
};
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment