FreeBSD/usr.bin/talk/ctl_transact.c
/*
 * SOCKDGRAM is unreliable, so we must repeat messages if we have
 * not received an acknowledgement within a reasonable amount
 * of time
 */
SOCKDGRAM is unreliable, so we must repeat messages if we have
not received an acknowledgement within a reasonable amount
of time
SOCKDGRAM is unreliable so we must repeat messages if we have not received an acknowledgement within a reasonable amount of time
void
ctl_transact(struct in_addr target, CTL_MSG lmsg, int type, CTL_RESPONSE *rp)
{
	struct pollfd pfd[1];
	int nready = 0, cc;
	lmsg.type = type;
	daemon_addr.sin_addr = target;
	daemon_addr.sin_port = daemon_port;
	pfd[0].fd = ctl_sockt;
	pfd[0].events = POLLIN;
	do {
		do {
			cc = sendto(ctl_sockt, (char *)&lmsg, sizeof (lmsg), 0,
			    (struct sockaddr *)&daemon_addr,
			    sizeof (daemon_addr));
			if (cc != sizeof (lmsg)) {
				if (errno == EINTR)
					continue;
				p_error("Error on write to talk daemon");
			}
			nready = poll(pfd, 1, CTL_WAIT * 1000);
			if (nready < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error waiting for daemon response");
			}
		} while (nready == 0);
		do {
			cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
			if (cc < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error on read from talk daemon");
			}
			nready = poll(pfd, 1, 0);
		} while (nready > 0 && (rp->vers != TALK_VERSION ||
		    rp->type != type));
	} while (rp->vers != TALK_VERSION || rp->type != type);
	rp->id_num = ntohl(rp->id_num);
	rp->addr.sa_family = ntohs(rp->addr.sa_family);
}
void ctl_transact ( struct in_addr target , CTL_MSG lmsg , int type , CTL_RESPONSE * rp ) { struct pollfd pfd [ 1 ] ; int nready = 0 , cc ; lmsg . type = type ; daemon_addr . sin_addr = target ; daemon_addr . sin_port = daemon_port ; pfd [ 0 ] . fd = ctl_sockt ; pfd [ 0 ] . events = POLLIN ; do { do { cc = sendto ( ctl_sockt , ( char * ) & lmsg , sizeof ( lmsg ) , 0 , ( struct sockaddr * ) & daemon_addr , sizeof ( daemon_addr ) ) ; if ( cc != sizeof ( lmsg ) ) { if ( errno == EINTR ) continue ; p_error ( " " ) ; } nready = poll ( pfd , 1 , CTL_WAIT * 1000 ) ; if ( nready < 0 ) { if ( errno == EINTR ) continue ; p_error ( " " ) ; } } while ( nready == 0 ) ; do { cc = recv ( ctl_sockt , ( char * ) rp , sizeof ( * rp ) , 0 ) ; if ( cc < 0 ) { if ( errno == EINTR ) continue ; p_error ( " " ) ; } nready = poll ( pfd , 1 , 0 ) ; } while ( nready > 0 && ( rp -> vers != TALK_VERSION || rp -> type != type ) ) ; } while ( rp -> vers != TALK_VERSION || rp -> type != type ) ; rp -> id_num = ntohl ( rp -> id_num ) ; rp -> addr . sa_family = ntohs ( rp -> addr . sa_family ) ; }
SOCKDGRAM is unreliable, so we must repeat messages if we have
 not received an acknowledgement within a reasonable amount
 of time
SOCKDGRAM is unreliable so we must repeat messages if we have not received an acknowledgement within a reasonable amount of time
/*
	 * Keep sending the message until a response of
	 * the proper type is obtained.
	 */ /* resend message until a response is obtained */ /*
		 * Keep reading while there are queued messages
		 * (this is not necessary, it just saves extra
		 * request/acknowledgements being sent)
		 */