server: return real error from fio_send_data()
[fio.git] / gfio.c
diff --git a/gfio.c b/gfio.c
index 1555dcfb65cecc8b0ec270c137a9ec5a0a4f110c..b0cab29a4839ee6287fa67529ae673451807d0f9 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -35,7 +35,6 @@
 static int gfio_server_running;
 static const char *gfio_graph_font;
 
-static void gfio_update_thread_status(char *status_message, double perc);
 static void view_log(GtkWidget *w, gpointer data);
 
 #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
@@ -119,6 +118,9 @@ struct gui {
        struct eta_widget eta;
        pthread_t server_t;
 
+       pthread_t t;
+       int handler_running;
+
        struct flist_head list;
 } main_ui;
 
@@ -151,7 +153,6 @@ struct gui_entry {
        GtkWidget *page_label;
        gint page_num;
        int connected;
-       pthread_t t;
 
        struct gfio_client *client;
        int nr_job_files;
@@ -168,6 +169,9 @@ struct gfio_client {
        struct thread_options o;
 };
 
+static void gfio_update_thread_status(struct gui_entry *ge, char *status_message, double perc);
+static void gfio_update_thread_status_all(char *status_message, double perc);
+
 static struct graph *setup_iops_graph(void)
 {
        struct graph *g;
@@ -1198,7 +1202,7 @@ static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *j
                sprintf(dst, " - %s", eta_str);
        }
                
-       gfio_update_thread_status(output, perc);
+       gfio_update_thread_status(ge, output, perc);
        gdk_threads_leave();
 }
 
@@ -1284,7 +1288,7 @@ static void gfio_update_all_eta(struct jobs_eta *je)
                sprintf(dst, " - %s", eta_str);
        }
                
-       gfio_update_thread_status(output, perc);
+       gfio_update_thread_status_all(output, perc);
        gdk_threads_leave();
 }
 
@@ -1320,7 +1324,19 @@ static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
        gdk_threads_leave();
 }
 
-static void gfio_update_thread_status(char *status_message, double perc)
+static void gfio_update_thread_status(struct gui_entry *ge,
+                                     char *status_message, double perc)
+{
+       static char message[100];
+       const char *m = message;
+
+       strncpy(message, status_message, sizeof(message) - 1);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), m);
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), perc / 100.0);
+       gtk_widget_queue_draw(main_ui.window);
+}
+
+static void gfio_update_thread_status_all(char *status_message, double perc)
 {
        struct gui *ui = &main_ui;
        static char message[100];
@@ -1436,16 +1452,21 @@ static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
 
 static void *job_thread(void *arg)
 {
+       struct gui *ui = arg;
+
+       ui->handler_running = 1;
        fio_handle_clients(&gfio_client_ops);
+       ui->handler_running = 0;
        return NULL;
 }
 
 static int send_job_files(struct gui_entry *ge)
 {
+       struct gfio_client *gc = ge->client;
        int i, ret = 0;
 
        for (i = 0; i < ge->nr_job_files; i++) {
-               ret = fio_clients_send_ini(ge->job_files[i]);
+               ret = fio_client_send_ini(gc->client, ge->job_files[i]);
                if (ret)
                        break;
 
@@ -1507,7 +1528,8 @@ static void connect_clicked(GtkWidget *widget, gpointer data)
                gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), "No jobs running");
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), 0.0);
                if (!fio_client_connect(gc->client)) {
-                       pthread_create(&ge->t, NULL, job_thread, NULL);
+                       if (!ge->ui->handler_running)
+                               pthread_create(&ge->ui->t, NULL, job_thread, ge->ui);
                        gtk_widget_set_sensitive(ge->button[CONNECT_BUTTON], 0);
                        gtk_widget_set_sensitive(ge->button[SEND_BUTTON], 1);
                }