version 1.8, 2003/06/03 02:56:17 |
version 1.9, 2003/08/11 21:10:54 |
|
|
#include <sys/time.h> |
#include <sys/time.h> |
#include <errno.h> |
#include <errno.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <poll.h> |
#include "talk_ctl.h" |
#include "talk_ctl.h" |
|
|
#define CTL_WAIT 2 /* time to wait for a response, in seconds */ |
#define CTL_WAIT 2 /* time to wait for a response, in seconds */ |
|
|
int type; |
int type; |
CTL_RESPONSE *rp; |
CTL_RESPONSE *rp; |
{ |
{ |
fd_set read_mask, ctl_mask; |
struct pollfd pfd[1]; |
int nready, cc; |
int nready, cc; |
struct timeval wait; |
|
|
|
msg.type = type; |
msg.type = type; |
daemon_addr.sin_addr = target; |
daemon_addr.sin_addr = target; |
daemon_addr.sin_port = daemon_port; |
daemon_addr.sin_port = daemon_port; |
FD_ZERO(&ctl_mask); |
pfd[0].fd = ctl_sockt; |
FD_SET(ctl_sockt, &ctl_mask); |
pfd[0].events = POLLIN; |
|
|
/* |
/* |
* Keep sending the message until a response of |
* Keep sending the message until a response of |
* the proper type is obtained. |
* the proper type is obtained. |
*/ |
*/ |
do { |
do { |
wait.tv_sec = CTL_WAIT; |
|
wait.tv_usec = 0; |
|
/* resend message until a response is obtained */ |
/* resend message until a response is obtained */ |
do { |
do { |
cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0, |
cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0, |
|
|
continue; |
continue; |
quit("Error on write to talk daemon", 1); |
quit("Error on write to talk daemon", 1); |
} |
} |
read_mask = ctl_mask; |
nready = poll(pfd, 1, CTL_WAIT * 1000); |
nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); |
|
if (nready < 0) { |
if (nready < 0) { |
if (errno == EINTR) |
if (errno == EINTR) |
continue; |
continue; |
|
|
continue; |
continue; |
quit("Error on read from talk daemon", 1); |
quit("Error on read from talk daemon", 1); |
} |
} |
read_mask = ctl_mask; |
nready = poll(pfd, 1, 0); |
/* an immediate poll */ |
|
timerclear(&wait); |
|
nready = select(ctl_sockt + 1, &read_mask, 0, 0, &wait); |
|
} while (nready > 0 && (rp->vers != TALK_VERSION || |
} while (nready > 0 && (rp->vers != TALK_VERSION || |
rp->type != type)); |
rp->type != type)); |
} while (rp->vers != TALK_VERSION || rp->type != type); |
} while (rp->vers != TALK_VERSION || rp->type != type); |