|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that the above copyright notice and this paragraph are ! 7: * duplicated in all such forms and that any documentation, ! 8: * advertising materials, and other materials related to such ! 9: * distribution and use acknowledge that the software was developed ! 10: * by the University of California, Berkeley. The name of the ! 11: * University may not be used to endorse or promote products derived ! 12: * from this software without specific prior written permission. ! 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 16: */ ! 17: ! 18: #ifndef lint ! 19: static char sccsid[] = "@(#)ctl_transact.c 5.4 (Berkeley) 6/29/88"; ! 20: #endif /* not lint */ ! 21: ! 22: #include "talk_ctl.h" ! 23: #include <sys/time.h> ! 24: ! 25: #define CTL_WAIT 2 /* time to wait for a response, in seconds */ ! 26: ! 27: /* ! 28: * SOCKDGRAM is unreliable, so we must repeat messages if we have ! 29: * not recieved an acknowledgement within a reasonable amount ! 30: * of time ! 31: */ ! 32: ctl_transact(target, msg, type, rp) ! 33: struct in_addr target; ! 34: CTL_MSG msg; ! 35: int type; ! 36: CTL_RESPONSE *rp; ! 37: { ! 38: int read_mask, ctl_mask, nready, cc; ! 39: struct timeval wait; ! 40: ! 41: msg.type = type; ! 42: daemon_addr.sin_addr = target; ! 43: daemon_addr.sin_port = daemon_port; ! 44: ctl_mask = 1 << ctl_sockt; ! 45: ! 46: /* ! 47: * Keep sending the message until a response of ! 48: * the proper type is obtained. ! 49: */ ! 50: do { ! 51: wait.tv_sec = CTL_WAIT; ! 52: wait.tv_usec = 0; ! 53: /* resend message until a response is obtained */ ! 54: do { ! 55: cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0, ! 56: &daemon_addr, sizeof (daemon_addr)); ! 57: if (cc != sizeof (msg)) { ! 58: if (errno == EINTR) ! 59: continue; ! 60: p_error("Error on write to talk daemon"); ! 61: } ! 62: read_mask = ctl_mask; ! 63: nready = select(32, &read_mask, 0, 0, &wait); ! 64: if (nready < 0) { ! 65: if (errno == EINTR) ! 66: continue; ! 67: p_error("Error waiting for daemon response"); ! 68: } ! 69: } while (nready == 0); ! 70: /* ! 71: * Keep reading while there are queued messages ! 72: * (this is not necessary, it just saves extra ! 73: * request/acknowledgements being sent) ! 74: */ ! 75: do { ! 76: cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0); ! 77: if (cc < 0) { ! 78: if (errno == EINTR) ! 79: continue; ! 80: p_error("Error on read from talk daemon"); ! 81: } ! 82: read_mask = ctl_mask; ! 83: /* an immediate poll */ ! 84: timerclear(&wait); ! 85: nready = select(32, &read_mask, 0, 0, &wait); ! 86: } while (nready > 0 && (rp->vers != TALK_VERSION || ! 87: rp->type != type)); ! 88: } while (rp->vers != TALK_VERSION || rp->type != type); ! 89: rp->id_num = ntohl(rp->id_num); ! 90: rp->addr.sa_family = ntohs(rp->addr.sa_family); ! 91: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.