utils/examples: avoid busy waiting on wait for reconnect
Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
@@ -377,6 +378,11 @@ int main(int argc, char *argv[])
|
||||
pfd[1].fd = iscsi_get_fd(client.dst_iscsi);
|
||||
pfd[1].events = iscsi_which_events(client.dst_iscsi);
|
||||
|
||||
if (!pfd[0].events && !pfd[1].events) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (poll(&pfd[0], 2, -1) < 0) {
|
||||
printf("Poll failed");
|
||||
exit(10);
|
||||
|
||||
@@ -47,6 +47,7 @@ WSADATA wsaData;
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
@@ -176,6 +177,11 @@ reconnect_event_loop(struct iscsi_context *iscsi, struct iscsi_sync_state *state
|
||||
pfd.fd = iscsi_get_fd(iscsi);
|
||||
pfd.events = iscsi_which_events(iscsi);
|
||||
|
||||
if (!pfd.events) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ret = poll(&pfd, 1, 1000)) < 0) {
|
||||
iscsi_set_error(iscsi, "Poll failed");
|
||||
state->status = -1;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
@@ -54,21 +55,26 @@ struct client_state {
|
||||
|
||||
void event_loop(struct iscsi_context *iscsi, struct client_state *state)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
struct pollfd pfd;
|
||||
|
||||
while (state->finished == 0) {
|
||||
pfd.fd = iscsi_get_fd(iscsi);
|
||||
pfd.events = iscsi_which_events(iscsi);
|
||||
while (state->finished == 0) {
|
||||
pfd.fd = iscsi_get_fd(iscsi);
|
||||
pfd.events = iscsi_which_events(iscsi);
|
||||
|
||||
if (poll(&pfd, 1, -1) < 0) {
|
||||
fprintf(stderr, "Poll failed");
|
||||
exit(10);
|
||||
}
|
||||
if (iscsi_service(iscsi, pfd.revents) < 0) {
|
||||
fprintf(stderr, "iscsi_service failed with : %s\n", iscsi_get_error(iscsi));
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
if (!pfd.events) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (poll(&pfd, 1, -1) < 0) {
|
||||
fprintf(stderr, "Poll failed");
|
||||
exit(10);
|
||||
}
|
||||
if (iscsi_service(iscsi, pfd.revents) < 0) {
|
||||
fprintf(stderr, "iscsi_service failed with : %s\n", iscsi_get_error(iscsi));
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void show_lun(struct iscsi_context *iscsi, int lun)
|
||||
|
||||
@@ -395,6 +395,7 @@ int main(int argc, char *argv[])
|
||||
while (client.in_flight && !client.err_cnt && finished < 2) {
|
||||
pfd[0].fd = iscsi_get_fd(client.iscsi);
|
||||
pfd[0].events = iscsi_which_events(client.iscsi);
|
||||
|
||||
if (proc_alarm) {
|
||||
if (iscsi_get_nops_in_flight(client.iscsi) > MAX_NOP_FAILURES) {
|
||||
iscsi_reconnect(client.iscsi);
|
||||
@@ -407,6 +408,11 @@ int main(int argc, char *argv[])
|
||||
proc_alarm = 0;
|
||||
}
|
||||
|
||||
if (!pfd[0].events) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (poll(&pfd[0], 1, -1) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user