]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/ctl_transact.c
Nuke `extern int errno;' in code we compile with -Wstrict-prototypes. We get
[bsdgames-darwin.git] / hunt / huntd / ctl_transact.c
1 /* $NetBSD: ctl_transact.c,v 1.3 1997/10/20 00:37:16 lukem Exp $ */
2 /*
3 * Copyright (c) 1983 Regents of the University of California.
4 * All rights reserved. The Berkeley software License Agreement
5 * specifies the terms and conditions for redistribution.
6 */
7
8 #include "bsd.h"
9
10 #if defined(TALK_43) || defined(TALK_42)
11
12 #include <sys/cdefs.h>
13 #ifndef lint
14 #if 0
15 static char sccsid[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
16 #else
17 __RCSID("$NetBSD: ctl_transact.c,v 1.3 1997/10/20 00:37:16 lukem Exp $");
18 #endif
19 #endif /* not lint */
20
21 #include <sys/time.h>
22 #include <unistd.h>
23 #include "hunt.h"
24 #include "talk_ctl.h"
25
26 #define CTL_WAIT 2 /* time to wait for a response, in seconds */
27 #define MAX_RETRY 5
28
29 /*
30 * SOCKDGRAM is unreliable, so we must repeat messages if we have
31 * not recieved an acknowledgement within a reasonable amount
32 * of time
33 */
34 void
35 ctl_transact(target, msg, type, rp)
36 struct in_addr target;
37 CTL_MSG msg;
38 int type;
39 CTL_RESPONSE *rp;
40 {
41 fd_set read_mask, ctl_mask;
42 int nready, cc, retries;
43 struct timeval wait;
44
45 nready = 0;
46 msg.type = type;
47 daemon_addr.sin_addr = target;
48 daemon_addr.sin_port = daemon_port;
49 FD_ZERO(&ctl_mask);
50 FD_SET(ctl_sockt, &ctl_mask);
51
52 /*
53 * Keep sending the message until a response of
54 * the proper type is obtained.
55 */
56 do {
57 wait.tv_sec = CTL_WAIT;
58 wait.tv_usec = 0;
59 /* resend message until a response is obtained */
60 for (retries = MAX_RETRY; retries > 0; retries -= 1) {
61 cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0,
62 (struct sockaddr *)&daemon_addr, sizeof (daemon_addr));
63 if (cc != sizeof (msg)) {
64 if (errno == EINTR)
65 continue;
66 p_error("Error on write to talk daemon");
67 }
68 read_mask = ctl_mask;
69 nready = select(32, &read_mask, 0, 0, &wait);
70 if (nready < 0) {
71 if (errno == EINTR)
72 continue;
73 p_error("Error waiting for daemon response");
74 }
75 if (nready != 0)
76 break;
77 }
78 if (retries <= 0)
79 break;
80 /*
81 * Keep reading while there are queued messages
82 * (this is not necessary, it just saves extra
83 * request/acknowledgements being sent)
84 */
85 do {
86 cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
87 if (cc < 0) {
88 if (errno == EINTR)
89 continue;
90 p_error("Error on read from talk daemon");
91 }
92 read_mask = ctl_mask;
93 /* an immediate poll */
94 timerclear(&wait);
95 nready = select(32, &read_mask, 0, 0, &wait);
96 } while (nready > 0 && (
97 #ifdef TALK_43
98 rp->vers != TALK_VERSION ||
99 #endif
100 rp->type != type));
101 } while (
102 #ifdef TALK_43
103 rp->vers != TALK_VERSION ||
104 #endif
105 rp->type != type);
106 rp->id_num = ntohl(rp->id_num);
107 #ifdef TALK_43
108 rp->addr.sa_family = ntohs(rp->addr.sa_family);
109 # else
110 rp->addr.sin_family = ntohs(rp->addr.sin_family);
111 # endif
112 }
113 #endif