io.h 1.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*  Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
14
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
15 16 17 18 19
 */

#pragma once

#include <uv.h>
20
#include <libknot/packet/pkt.h>
21 22 23 24 25 26 27 28
#include "lib/generic/array.h"

struct qr_task;

/* Per-session (TCP or UDP) persistent structure,
 * that exists between remote counterpart and a local socket.
 */
struct session {
29
	bool outgoing;
30 31 32 33 34 35 36 37
    bool throttled;
    uv_timer_t timeout;
    struct qr_task *buffering;
	array_t(struct qr_task *) tasks;
};

void session_free(struct session *s);
struct session *session_new(void);
38

39
int udp_bind(uv_udp_t *handle, struct sockaddr *addr);
40
int udp_bindfd(uv_udp_t *handle, int fd);
41
int tcp_bind(uv_tcp_t *handle, struct sockaddr *addr);
42
int tcp_bindfd(uv_tcp_t *handle, int fd);
43

44
void io_create(uv_loop_t *loop, uv_handle_t *handle, int type);
45 46 47
void io_deinit(uv_handle_t *handle);
void io_free(uv_handle_t *handle);

48
int io_start_read(uv_handle_t *handle);
49
int io_stop_read(uv_handle_t *handle);