1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)ctl_transact.c	5.2 (Berkeley) 3/13/86";
   9: #endif not lint
  10: 
  11: #include "talk_ctl.h"
  12: #include <sys/time.h>
  13: 
  14: #define CTL_WAIT 2  /* time to wait for a response, in seconds */
  15: 
  16: /*
  17:  * SOCKDGRAM is unreliable, so we must repeat messages if we have
  18:  * not recieved an acknowledgement within a reasonable amount
  19:  * of time
  20:  */
  21: ctl_transact(target, msg, type, rp)
  22:     struct in_addr target;
  23:     CTL_MSG msg;
  24:     int type;
  25:     CTL_RESPONSE *rp;
  26: {
  27:     long read_mask, ctl_mask;
  28:     int nready, cc;
  29:     struct timeval wait;
  30: 
  31:     msg.type = type;
  32:     daemon_addr.sin_addr = target;
  33:     daemon_addr.sin_port = daemon_port;
  34:     ctl_mask = 1L << ctl_sockt;
  35: 
  36:     /*
  37: 	 * Keep sending the message until a response of
  38: 	 * the proper type is obtained.
  39: 	 */
  40:     do {
  41:         wait.tv_sec = CTL_WAIT;
  42:         wait.tv_usec = 0;
  43:         /* resend message until a response is obtained */
  44:         do {
  45:             cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0,
  46:                 &daemon_addr, sizeof (daemon_addr));
  47:             if (cc != sizeof (msg)) {
  48:                 if (errno == EINTR)
  49:                     continue;
  50:                 p_error("Error on write to talk daemon");
  51:             }
  52:             read_mask = ctl_mask;
  53:             nready = select(32, &read_mask, (long *)0, (long *)0, &wait);
  54:             if (nready < 0) {
  55:                 if (errno == EINTR)
  56:                     continue;
  57:                 p_error("Error waiting for daemon response");
  58:             }
  59:         } while (nready == 0);
  60:         /*
  61: 		 * Keep reading while there are queued messages
  62: 		 * (this is not necessary, it just saves extra
  63: 		 * request/acknowledgements being sent)
  64: 		 */
  65:         do {
  66:             cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
  67:             if (cc < 0) {
  68:                 if (errno == EINTR)
  69:                     continue;
  70:                 p_error("Error on read from talk daemon");
  71:             }
  72:             read_mask = ctl_mask;
  73:             /* an immediate poll */
  74:             timerclear(&wait);
  75:             nready = select(32, &read_mask, (long *)0, (long *)0, &wait);
  76:         } while (nready > 0 && (rp->vers != TALK_VERSION ||
  77:             rp->type != type));
  78:     } while (rp->vers != TALK_VERSION || rp->type != type);
  79:     rp->id_num = ntohl(rp->id_num);
  80:     rp->addr.sa_family = ntohs(rp->addr.sa_family);
  81: }

Defined functions

ctl_transact defined in line 21; used 6 times

Defined variables

sccsid defined in line 8; never used

Defined macros

CTL_WAIT defined in line 14; used 1 times
  • in line 41
Last modified: 1988-06-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3228
Valid CSS Valid XHTML 1.0 Strict