8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / talk / ctl_transact.c
blobf465c89ed2e801b9f652a682fd64543291883be9
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include "talk_ctl.h"
43 #include <sys/time.h>
44 #include <libintl.h>
46 #define CTL_WAIT 2
47 /* the amount of time to wait for a response, in seconds */
51 * SOCKDGRAM is unreliable, so we must repeat messages if we have
52 * not recieved an acknowledgement within a reasonable amount of time
55 void
56 ctl_transact(target, msg, type, response)
57 struct in_addr target;
58 CTL_MSG msg;
59 int type;
60 CTL_RESPONSE *response;
62 struct sockaddr junk;
63 int read_mask;
64 int ctl_mask;
65 int nready;
66 int cc;
67 socklen_t junk_size;
68 struct timeval wait;
70 wait.tv_sec = CTL_WAIT;
71 wait.tv_usec = 0;
73 msg.type = type;
75 daemon_addr.sin_addr = target;
76 daemon_addr.sin_port = daemon_port;
78 ctl_mask = 1 << ctl_sockt;
81 * keep sending the message until a response of the right
82 * type is obtained
85 do {
86 /* keep sending the message until a response is obtained */
88 do {
89 cc = sendto(ctl_sockt,
90 (char *)&msg, sizeof (CTL_MSG), 0,
91 (struct sockaddr *)&daemon_addr, sizeof (daemon_addr));
93 if (cc != sizeof (CTL_MSG)) {
94 if (errno == EINTR) {
95 /* we are returning from an interupt */
96 continue;
97 } else {
98 p_error(
99 gettext("Error on write to talk daemon"));
103 read_mask = ctl_mask;
105 while ((nready = select(32, (fd_set *)&read_mask,
106 0, 0, &wait)) < 0) {
107 if (errno == EINTR) {
108 /* we are returning from an interupt */
109 continue;
110 } else {
111 p_error(
112 gettext("Error on waiting for response from daemon"));
115 } while (nready == 0);
118 * keep reading while there are queued messages
119 * (this is not necessary, it just saves extra
120 * request/acknowledgements being sent)
123 do {
125 junk_size = (socklen_t)sizeof (junk);
126 cc = recvfrom(ctl_sockt, (char *)response,
127 sizeof (CTL_RESPONSE), 0, &junk, &junk_size);
128 if (cc < 0) {
129 if (errno == EINTR) {
130 continue;
132 p_error(gettext("Error on read from talk daemon"));
135 read_mask = ctl_mask;
137 /* an immediate poll */
139 timerclear(&wait);
140 nready = select(32, (fd_set *)&read_mask, 0, 0, &wait);
142 } while (nready > 0 && response->type != type);
144 } while (response->type != type);