chiark / gitweb /
Include <sys/times.h> in a few more files. Include <unistd.h> and
[adns.git] / src / event.c
index 19fa62068fef48f48bfb29db23eb1092c836def5..154a9b8f5c2dd3c62849b1e06ce8a16b4ecc7936 100644 (file)
@@ -5,7 +5,7 @@
  * - user-visible check/wait and event-loop-related functions
  */
 /*
- *  This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
+ *  This file is part of adns, which is Copyright (C) 1997-1999 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
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <unistd.h>
 
+#include <sys/types.h>
+#include <sys/time.h>
 #include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 
 #include "internal.h"
@@ -100,7 +105,7 @@ void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
     addr.sin_family= AF_INET;
     addr.sin_port= htons(DNS_PORT);
     addr.sin_addr= ads->servers[ads->tcpserver].addr;
-    r= connect(fd,&addr,sizeof(addr));
+    r= connect(fd,(const struct sockaddr*)&addr,sizeof(addr));
     ads->tcpsocket= fd;
     ads->tcpstate= server_connecting;
     if (r==0) { tcp_connected(ads,now); continue; }
@@ -284,7 +289,9 @@ static int internal_callback(adns_state ads, int maxfd,
     } else if (callb_checkfd(maxfd,exceptfds,ads->tcpsocket)) {
       adns__tcp_broken(ads,"select","exceptional condition detected");
     } else if (ads->tcpsend.used && callb_checkfd(maxfd,writefds,ads->tcpsocket)) {
+      adns__sigpipe_protect(ads);
       r= write(ads->tcpsocket,ads->tcpsend.buf,ads->tcpsend.used);
+      adns__sigpipe_unprotect(ads);
       if (r<0) {
        if (errno!=EAGAIN && errno!=EWOULDBLOCK && errno!=ENOMEM && errno!=EINTR) {
          adns__tcp_broken(ads,"write",strerror(errno));
@@ -303,7 +310,8 @@ static int internal_callback(adns_state ads, int maxfd,
     count++;
     for (;;) {
       udpaddrlen= sizeof(udpaddr);
-      r= recvfrom(ads->udpsocket,udpbuf,sizeof(udpbuf),0,&udpaddr,&udpaddrlen);
+      r= recvfrom(ads->udpsocket,udpbuf,sizeof(udpbuf),0,
+                 (struct sockaddr*)&udpaddr,&udpaddrlen);
       if (r<0) {
        if (!(errno == EAGAIN || errno == EWOULDBLOCK ||
              errno == EINTR || errno == ENOMEM || errno == ENOBUFS))