From 193ff884bb0a258ecdaaaf6b450f34c4b5dbf829 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 5 Feb 2007 14:25:07 +0000 Subject: [PATCH] Constants for netevent callback error value. git-svn-id: file:///svn/unbound/trunk@66 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + services/outside_network.c | 8 ++++---- util/netevent.c | 2 +- util/netevent.h | 14 +++++++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index ec1484515..d85b6677d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 5 February 2007: Wouter - Picked up stdc99 and other define tests from ldns. Improved POSIX define test to include getaddrinfo. + - defined constants for netevent callback error code. 2 February 2007: Wouter - Created udp4 and udp6 port arrays to provide service for both diff --git a/services/outside_network.c b/services/outside_network.c index d2ef6e9e2..ea4255278 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -107,7 +107,7 @@ static int outnet_udp_cb(struct comm_point* c, void* arg, int error, } comm_timer_disable(p->timer); log_info("outnet handle udp reply"); - (void)(*p->cb)(p->c, p->cb_arg, 0, NULL); + (void)(*p->cb)(p->c, p->cb_arg, NETEVENT_NOERROR, NULL); return 0; } @@ -227,7 +227,7 @@ static void pending_udp_timer_cb(void *arg) struct pending* p = (struct pending*)arg; /* it timed out */ log_info("timeout udp"); - (void)(*p->cb)(p->c, p->cb_arg, -2, NULL); + (void)(*p->cb)(p->c, p->cb_arg, NETEVENT_TIMEOUT, NULL); } struct outside_network* @@ -448,7 +448,7 @@ void pending_udp_query(struct outside_network* outnet, ldns_buffer* packet, /* create pending struct (and possibly change ID to be unique) */ if(!(pend=new_pending(outnet, packet, addr, addrlen, cb, cb_arg))) { /* callback user for the error */ - (void)(*cb)(NULL, cb_arg, -1, NULL); + (void)(*cb)(NULL, cb_arg, NETEVENT_CLOSED, NULL); return; } select_port(outnet, pend); @@ -459,7 +459,7 @@ void pending_udp_query(struct outside_network* outnet, ldns_buffer* packet, /* error, call error callback function */ pending_delete(outnet, pend); /* callback user for the error */ - (void)(*pend->cb)(pend->c, pend->cb_arg, -1, NULL); + (void)(*pend->cb)(pend->c, pend->cb_arg, NETEVENT_CLOSED, NULL); return; } diff --git a/util/netevent.c b/util/netevent.c index 17db720b6..1067b7330 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -209,7 +209,7 @@ comm_point_udp_callback(int fd, short event, void* arg) } ldns_buffer_skip(rep.c->buffer, recv); ldns_buffer_flip(rep.c->buffer); - if((*rep.c->callback)(rep.c, rep.c->cb_arg, 0, &rep)) { + if((*rep.c->callback)(rep.c, rep.c->cb_arg, NETEVENT_NOERROR, &rep)) { /* send back immediate reply */ (void)comm_point_send_udp_msg(rep.c, rep.c->buffer, (struct sockaddr*)&rep.addr, rep.addrlen); diff --git a/util/netevent.h b/util/netevent.h index a47a9dd7c..02ae94b10 100644 --- a/util/netevent.h +++ b/util/netevent.h @@ -66,6 +66,13 @@ struct internal_timer; typedef int comm_point_callback_t(struct comm_point*, void*, int, struct comm_reply*); +/** to pass no_error to callback function */ +#define NETEVENT_NOERROR 0 +/** to pass closed connection to callback function */ +#define NETEVENT_CLOSED -1 +/** to pass timeout happened to callback function */ +#define NETEVENT_TIMEOUT -2 + /** * A communication point dispatcher. Thread specific. */ @@ -142,10 +149,11 @@ struct comm_point { tcp_accept does not get called back, is NULL then. If a timeout happens, callback with timeout=1 is called. If an error happens, callback is called with error set - nonzero. If nonzero, it is an errno value. + nonzero. If not NETEVENT_NOERROR, it is an errno value. If the connection is closed (by remote end) then the - callback is called with error set to -1. - If a timeout happens on the connection, the error is set to -2. + callback is called with error set to NETEVENT_CLOSED=-1. + If a timeout happens on the connection, the error is set to + NETEVENT_TIMEOUT=-2. The reply_info can be copied if the reply needs to happen at a later time. It consists of a struct with commpoint and address. It can be passed to a msg send routine some time later. -- 2.47.2