The LIST_LINEs are outputed by the client.
authorviric@llimona
Thu, 22 Mar 2007 00:03:41 +0100
changeset 5 bc5e251418f3
parent 4 110d7bfe2d51
child 6 8ff6b6c9d87c
The LIST_LINEs are outputed by the client.
client.c
jobs.c
main.c
main.h
msg.h
msgdump.c
server.c
--- a/client.c	Wed Mar 21 23:49:36 2007 +0100
+++ b/client.c	Thu Mar 22 00:03:41 2007 +0100
@@ -33,6 +33,32 @@
         msgdump(&m);
         if (m.type == NEWJOB_OK)
             ;
+        if (m.type == LIST_LINE)
+        {
+            printf("%s", m.u.line);
+        }
+    }
+}
+
+void c_wait_server_lines()
+{
+    struct msg m;
+    int res;
+
+    while (1)
+    {
+        res = read(server_socket, &m, sizeof(m));
+        if(res == -1)
+            perror("read");
+
+        if (res == 0)
+            break;
+        assert(res == sizeof(m));
+        msgdump(&m);
+        if (m.type == LIST_LINE)
+        {
+            printf("%s", m.u.line);
+        }
     }
 }
 
--- a/jobs.c	Wed Mar 21 23:49:36 2007 +0100
+++ b/jobs.c	Thu Mar 22 00:03:41 2007 +0100
@@ -13,20 +13,38 @@
 static struct Job *firstjob = 0;
 static jobids = 0;
 
+static void send_list_line(int s, const char * str)
+{
+    struct msg m;
+    int res;
+
+    m.type = LIST_LINE;
+
+    strcpy(m.u.line, str);
+
+    res = write(s, &m, sizeof(m));
+    if(res == -1)
+        perror("write");
+}
+
 void s_list(int s)
 {
     int i;
     struct Job *p;
+    char buffer[LINE_LEN];
 
-    printf("ID\tState\tCommand\n");
+    sprintf(buffer, "ID\tState\tCommand\n");
+    send_list_line(s,buffer);
 
     p = firstjob;
 
     while(p != 0)
     {
-        printf("%i\t", p->jobid);
-        printf("%i\t", p->state);
-        printf("%s\n", p->command);
+        sprintf(buffer, "%i\t%i\t%s\n",
+                p->jobid,
+                p->state,
+                p->command);
+        send_list_line(s,buffer);
         p = p->next;
     }
 }
--- a/main.c	Wed Mar 21 23:49:36 2007 +0100
+++ b/main.c	Thu Mar 22 00:03:41 2007 +0100
@@ -60,7 +60,10 @@
     }
 
     if (list_jobs != 0)
+    {
         c_list_jobs(new_command);
+        c_wait_server_lines();
+    }
     
     if (kill_server)
         c_shutdown_server();
--- a/main.h	Wed Mar 21 23:49:36 2007 +0100
+++ b/main.h	Thu Mar 22 00:03:41 2007 +0100
@@ -7,6 +7,7 @@
 void c_wait_server_commands();
 void c_list_jobs(const char *command);
 int c_shutdown_server();
+void c_wait_server_lines();
 
 /* jobs.c */
 void s_list(int s);
--- a/msg.h	Wed Mar 21 23:49:36 2007 +0100
+++ b/msg.h	Thu Mar 22 00:03:41 2007 +0100
@@ -2,7 +2,7 @@
 
 enum
 {
-    CMD_LEN=500
+    CMD_LEN=500,
     LINE_LEN=500
 };
 
@@ -26,7 +26,7 @@
         char command[CMD_LEN];
         int jobid;
         int errorlevel;
-        char command[LINE_LEN];
+        char line[LINE_LEN];
     } u;
 };
 
--- a/msgdump.c	Wed Mar 21 23:49:36 2007 +0100
+++ b/msgdump.c	Thu Mar 22 00:03:41 2007 +0100
@@ -4,6 +4,8 @@
 
 void msgdump(const struct msg *m)
 {
+    return;
+
     printf("msgdump:\n");
     switch(m->type)
     {
@@ -27,5 +29,9 @@
         case LIST:
             printf(" LIST\n");
             break;
+        case LIST_LINE:
+            printf(" LIST_LINE\n");
+            printf(" Line: '%s'\n", m->u.command);
+            break;
     }
 }
--- a/server.c	Wed Mar 21 23:49:36 2007 +0100
+++ b/server.c	Thu Mar 22 00:03:41 2007 +0100
@@ -171,7 +171,11 @@
     }
 
     if (m.type == LIST)
-        s_list(index);
+    {
+        s_list(client_cs[index].socket);
+        close(client_cs[index].socket);
+        remove_connection(index);
+    }
 
     return NOBREAK; /* normal */
 }