From f6ae1381a6504c7188fd699fa76da1d8dd500e68 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 22 Jan 2007 15:23:29 +0000 Subject: [PATCH] Header file for network access points. git-svn-id: file:///svn/unbound/trunk@24 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 3 ++ util/netevent.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 util/netevent.h diff --git a/doc/Changelog b/doc/Changelog index a4b8afeee..5049a9666 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +22 January 2007: Wouter + - Designed header file for network communication. + 16 January 2007: Wouter - added readme.svn and readme.tests. diff --git a/util/netevent.h b/util/netevent.h new file mode 100644 index 000000000..198ab0d54 --- /dev/null +++ b/util/netevent.h @@ -0,0 +1,95 @@ +/* + * util/netevent.h - event notification + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. + * + */ + +/** + * \file + * + * This file contains event notification functions. + * + * There are three types of communication points + * o UDP socket - perthread buffer. + * o TCP-accept socket - array of TCP-sockets, socketcount. + * o TCP socket - own buffer, parent-TCPaccept, read/write state, + * number of bytes read/written, timeout. + * + * There are sockets aimed towards our clients and towards the internet. + * o frontside - aimed towards our clients, queries come in, answers back. + * o behind - aimed towards internet, to the authoritative DNS servers. + * + */ + +#ifndef NET_EVENT_H +#define NET_EVENT_H + +#include "config.h" +struct buffer; + +/** internal event notification data storage structure. */ +struct internal_event; + +/** Communication point to the network */ +struct comm_point { + /** behind the scenes structure, with say libevent info. alloced. */ + struct internal_event* ev; + + /** file descriptor for communication point */ + int fd; + + /** timeout (NULL if it does not). Malloced. */ + struct timeval *timeout; + + /** buffer pointer. Either to perthread, or own buffer or NULL */ + struct buffer *buffer; + + /* -------- TCP Handler -------- */ + /** Read/Write state for TCP */ + int tcp_is_reading; + /** The current read/write count for TCP */ + size_t tcp_byte_count; + /** parent communication point (for TCP sockets) */ + struct comm_point tcp_parent; + + /* -------- TCP Accept -------- */ + /** current and max number of TCP connections on this socket */ + int cur_tcp_count, max_tcp_count; + /** malloced array of tcp handlers for a tcp-accept, + of size max_tcp_count. */ + struct comm_point *tcp_handlers; + /** linked list of free tcp_handlers to use for new queries. + For tcp_accept the first entry, for tcp_handlers the next one. */ + struct comm_point *tcp_free; + + /** is this a UDP, TCP-accept or TCP socket. */ + enum comm_point_type {comm_udp, comm_tcp_accept, comm_tcp} type; + + /** what to do when read/write is done. + + For a query this means it is read in and ready to be processed. + After that the buffer will be sent back to client. + tcp_accept does not get called back, is NULL then. + + udp frontside: called after readdone. sendafter. + tcp frontside: called readdone, sendafter. close. + udp behind: called after readdone. No send after. + tcp behind: write done, read done, then called. No send after. + + declare as: + int my_callback(struct comm_point*, void* cb_arg, int timeout); + + if the routine returns 0, no answer is sent back. + For TCP handlers after the answer is sent back the fd is closed. + If a timeout happens, TCP handler is closed, and callback with + timeout=1 is called. + */ + int (*)(struct comm_point*, void*) callback; + /** argument to pass to callback. */ + void *cb_arg; +}; + +#endif /* NET_EVENT_H */ -- 2.47.2