static int use_rs = 1;
static int use_async;
+static int poll_timeout = -1;
static int verify;
static int flags = MSG_DONTWAIT;
static int no_delay = 1;
return 0;
}
+static int do_poll(struct pollfd *fds)
+{
+ int ret;
+
+ do {
+ ret = rs_poll(&fds, 1, poll_timeout);
+ } while (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
+
+ return ret;
+}
+
static int send_xfer(int rs, int size)
{
struct pollfd fds;
for (offset = 0; offset < size; ) {
if (use_async) {
- ret = rs_poll(&fds, 1, -1);
+ ret = do_poll(&fds);
if (ret != 1)
return ret;
}
for (offset = 0; offset < size; ) {
if (use_async) {
- ret = rs_poll(&fds, 1, -1);
+ ret = do_poll(&fds);
if (ret != 1)
return ret;
}
fds.fd = lrs;
fds.events = POLLIN;
- ret = rs_poll(&fds, 1, -1);
+ ret = do_poll(&fds);
if (ret != 1) {
perror("rpoll");
goto close;
ret = rs_connect(rs, res->ai_addr, res->ai_addrlen);
if (ret && (errno != EINPROGRESS)) {
perror("rconnect");
- rs_close(rs);
- rs = ret;
+ goto err;
}
if (errno == EINPROGRESS) {
fds.fd = rs;
fds.events = POLLOUT;
- do {
- ret = rs_poll(&fds, 1, -1);
- } while (!ret);
+ ret = do_poll(&fds);
+ if (ret != 1) {
+ perror("rpoll");
+ goto err;
+ }
}
free:
freeaddrinfo(res);
return rs;
+err:
+ freeaddrinfo(res);
+ rs_close(rs);
+ return -1;
}
static int run(void)
flags |= MSG_DONTWAIT;
no_delay = 1;
break;
+ case 'p':
+ poll_timeout = 0;
+ break;
case 'v':
verify = 1;
break;
} else if (!strncasecmp("nonblock", optarg, 8)) {
flags |= MSG_DONTWAIT;
no_delay = 1;
+ } else if (!strncasecmp("poll", optarg, 4)) {
+ poll_timeout = 0;
} else if (!strncasecmp("verify", optarg, 6)) {
verify = 1;
} else {
printf("\t a|async - asynchronous operation (use poll)\n");
printf("\t b|blocking - use blocking calls\n");
printf("\t n|nonblocking - use nonblocking calls\n");
+ printf("\t p|poll - poll on asynchronous operations\n")
printf("\t v|verify - verify data\n");
exit(1);
}