From: Jens Axboe Date: Fri, 30 Sep 2011 00:27:02 +0000 (-0600) Subject: Use poll() for connect loop X-Git-Tag: fio-1.99~89 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=009b1be41b32bf7e32b441c6a22e3ae628ec9b89;ds=sidebyside Use poll() for connect loop So we can exit nicely when asked to. Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index 5e4d0e60..a15080b4 100644 --- a/fio.c +++ b/fio.c @@ -46,6 +46,7 @@ #include "profile.h" #include "lib/rand.h" #include "memalign.h" +#include "server.h" unsigned long page_mask; unsigned long page_size; @@ -122,6 +123,7 @@ static void sig_int(int sig) { if (threads) { log_info("\nfio: terminating on signal %d\n", sig); + exit_backend = 1; fflush(stdout); exit_value = 128; terminate_threads(TERMINATE_ALL); diff --git a/server.c b/server.c index 541216ca..38f690bd 100644 --- a/server.c +++ b/server.c @@ -21,13 +21,38 @@ static int net_port = 8765; +int exit_backend = 0; + static int accept_loop(int listen_sk) { struct sockaddr addr; unsigned int len = sizeof(addr); - int sk, do_exit = 0; + struct pollfd pfd; + int ret, sk, flags; + flags = fcntl(listen_sk, F_GETFL); + flags |= O_NONBLOCK; + fcntl(listen_sk, F_SETFL, flags); again: + pfd.fd = listen_sk; + pfd.events = POLLIN; + do { + ret = poll(&pfd, 1, 100); + if (ret < 0) { + if (errno == EINTR) + break; + perror("poll"); + goto out; + } else if (!ret) + continue; + + if (pfd.revents & POLLIN) + break; + } while (!exit_backend); + + if (exit_backend) + goto out; + sk = accept(listen_sk, &addr, &len); if (sk < 0) { log_err("fio: accept failed\n"); @@ -35,14 +60,13 @@ again: } /* read forever */ - while (!do_exit) { + while (!exit_backend) { char buf[131072]; - int ret; ret = recv(sk, buf, 4096, 0); if (ret > 0) { if (!strncmp("FIO_QUIT", buf, 8)) { - do_exit = 1; + exit_backend = 1; break; } parse_jobs_ini(buf, 1, 0); @@ -58,9 +82,10 @@ again: close(sk); - if (!do_exit) + if (!exit_backend) goto again; +out: return 0; } diff --git a/server.h b/server.h index 879faaba..aed61b2c 100644 --- a/server.h +++ b/server.h @@ -2,5 +2,6 @@ #define FIO_SERVER_H extern int fio_server(void); +extern int exit_backend; #endif