X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/98a3f706175de88b2c9f0729b405330457ae680b..e576be5096ae358bebe2e9b6ad07c49f74aef616:/src/event.c diff --git a/src/event.c b/src/event.c index 9ddf4c7..dcf0adb 100644 --- a/src/event.c +++ b/src/event.c @@ -1,4 +1,26 @@ -/**/ +/* + * event.c + * - event loop core + * - TCP connection management + * - user-visible check/wait and event-loop-related functions + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * + * 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 2, 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 + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include #include @@ -17,7 +39,7 @@ void adns__tcp_broken(adns_state ads, const char *what, const char *why) { assert(ads->tcpstate == server_connecting || ads->tcpstate == server_ok); serv= ads->tcpserver; - adns__warn(ads,serv,"TCP connection lost: %s: %s",what,why); + adns__warn(ads,serv,0,"TCP connection lost: %s: %s",what,why); close(ads->tcpsocket); ads->tcpstate= server_disconnected; @@ -40,7 +62,7 @@ void adns__tcp_broken(adns_state ads, const char *what, const char *why) { static void tcp_connected(adns_state ads, struct timeval now) { adns_query qu, nqu; - adns__debug(ads,ads->tcpserver,"TCP connected"); + adns__debug(ads,ads->tcpserver,0,"TCP connected"); ads->tcpstate= server_ok; for (qu= ads->timew.head; qu; qu= nqu) { nqu= qu->next; @@ -63,15 +85,15 @@ void adns__tcp_tryconnect(adns_state ads, struct timeval now) { assert(!ads->tcprecv.used); proto= getprotobyname("tcp"); - if (!proto) { adns__diag(ads,-1,"unable to find protocol no. for TCP !"); return; } + if (!proto) { adns__diag(ads,-1,0,"unable to find protocol no. for TCP !"); return; } fd= socket(AF_INET,SOCK_STREAM,proto->p_proto); if (fd<0) { - adns__diag(ads,-1,"cannot create TCP socket: %s",strerror(errno)); + adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno)); return; } r= adns__setnonblock(ads,fd); if (r) { - adns__diag(ads,-1,"cannot make TCP socket nonblocking: %s",strerror(r)); + adns__diag(ads,-1,0,"cannot make TCP socket nonblocking: %s",strerror(r)); close(fd); return; } @@ -159,7 +181,8 @@ fprintf(stderr,"adns_interest\n"); r= gettimeofday(&now,0); if (r) { - adns__warn(ads,-1,"gettimeofday failed - will sleep for a bit: %s",strerror(errno)); + adns__warn(ads,-1,0,"gettimeofday failed - will sleep for a bit: %s", + strerror(errno)); timerclear(&tvto_lr); timevaladd(&tvto_lr,LOCALRESOURCEMS); inter_maxto(tv_io, tvbuf, tvto_lr); } else { @@ -281,21 +304,21 @@ static int internal_callback(adns_state ads, int maxfd, if (r<0) { if (!(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ENOMEM || errno == ENOBUFS)) - adns__warn(ads,-1,"datagram receive error: %s",strerror(errno)); + adns__warn(ads,-1,0,"datagram receive error: %s",strerror(errno)); break; } if (udpaddrlen != sizeof(udpaddr)) { - adns__diag(ads,-1,"datagram received with wrong address length %d (expected %d)", - udpaddrlen,sizeof(udpaddr)); + adns__diag(ads,-1,0,"datagram received with wrong address length %d" + " (expected %d)", udpaddrlen,sizeof(udpaddr)); continue; } if (udpaddr.sin_family != AF_INET) { - adns__diag(ads,-1,"datagram received with wrong protocol family" + adns__diag(ads,-1,0,"datagram received with wrong protocol family" " %u (expected %u)",udpaddr.sin_family,AF_INET); continue; } if (ntohs(udpaddr.sin_port) != DNS_PORT) { - adns__diag(ads,-1,"datagram received from wrong port %u (expected %u)", + adns__diag(ads,-1,0,"datagram received from wrong port %u (expected %u)", ntohs(udpaddr.sin_port),DNS_PORT); continue; } @@ -304,7 +327,7 @@ static int internal_callback(adns_state ads, int maxfd, ads->servers[serv].addr.s_addr != udpaddr.sin_addr.s_addr; serv++); if (serv >= ads->nservers) { - adns__warn(ads,-1,"datagram received from unknown nameserver %s", + adns__warn(ads,-1,0,"datagram received from unknown nameserver %s", inet_ntoa(udpaddr.sin_addr)); continue; } @@ -346,7 +369,7 @@ static int internal_check(adns_state ads, if (qu->id>=0) return EWOULDBLOCK; } LIST_UNLINK(ads->output,qu); - *answer= (adns_answer*)qu->ans.buf; + *answer= qu->answer; if (context_r) *context_r= qu->context.ext; free(qu); return 0;