Broken comm stuff.
[tlb/tomd.git] / src / tomc / main.c
index f766562..3dd16c1 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include "../../include/macros.h"
+#include "../../include/manifest.h"
 
 static int sfd;
 
@@ -51,6 +52,7 @@ static void init(void)
     perror("connect");
     exit(EXIT_FAILURE);
   }
+  setup_socket(sfd);
 }
 
 static char *default_name = "no_name";
@@ -111,28 +113,41 @@ static char socket_buf[100];
     int write_len = strlen(write_buf);                              \
     ssize_t wrote =                                                 \
       write(sfd, write_buf, write_len);                             \
-    tomc_p("wrote '%s' (%d)", write_buf, write_len);                \
+    /* tomc_p("wrote '%s' (%d)", write_buf, write_len);                 */ \
     if(wrote != write_len){                                         \
       perror("[tomc] write size mismatch");                         \
       exit(EXIT_FAILURE);                                           \
     }}                                                               
     
+int last_read_size = 0;
+
+static void do_read(char *line)
+{
+  printf("got %s as input.\n", line);
+  strcpy(socket_buf, line);
+  /* printf("socket_buf: %s\n", socket_buf); */
+}
 
 #define SOCK_READ {                             \
-    int size = read(sfd, socket_buf, 100);      \
-    if(read == 0) {                             \
-      tomc_p("didn't actually get anything.");  \
-      socket_buf[0] = '\0';                     \
-    }                                           \
-    socket_buf[size] = '\0';                    \
+    socket_read(do_read);                       \
   }
+  /*   int size = read(sfd, socket_buf, 100);      \ */
+  /*   if(size == 0) {                             \ */
+  /*     tomc_p("didn't actually get anything.");  \ */
+  /*     socket_buf[0] = '\0';                     \ */
+  /*   }else{                                      \ */
+  /*     tomc_p("__debug__:size=%d", size);        \ */
+  /*   }                                           \ */
+  /*   socket_buf[size] = '\0';                    \ */
+  /*   tomc_p("__debug__: '%s'", socket_buf);\ */
+  /*   last_read_size = size;\ */
+  /* } */
 #define SOCK_READ_X(X){                                                 \
     SOCK_READ;                                                          \
     if(strcmp(socket_buf, X) != 0){                                     \
       tomc_p("protocol error. instead of ACK we got '%s'", socket_buf); \
       exit(EXIT_FAILURE);                                               \
     }                                                                   \
-    tomc_p("got an ACK");                                               \
   }
 #define SOCK_ACK {SOCK_READ_X("ACK")};
 #define SOCK_REQUEST(X) {                       \
@@ -140,8 +155,6 @@ static char socket_buf[100];
     SOCK_ACK;                                   \
     SOCK_WRITE(options.name);                   \
     SOCK_ACK;                                   \
-    SOCK_READ;                                  \
-    tomc_p("tomd reports '%s'", socket_buf);    \
   }
   
 static void write_client(void)
@@ -177,6 +190,29 @@ static void write_requests(void)
   if(options.status){
     SOCK_REQUEST("status");
   }
+
+  while(1){
+    printf("looking for that last ack.\n");
+    SOCK_READ;
+    if(strcmp(socket_buf, "ACK") == 0){
+      tomc_p("got the ending ack.");
+      break;
+    }else{
+      printf("in else.\n");
+      /* int len = strlen(socket_buf); */
+      /* int total = len; */
+      /* if(last_read_size == 0){ */
+      /*   continue; */
+      /* } */
+      tomc_p(socket_buf);
+      /* while(total != last_read_size -1){ */
+      /*   tomc_p("__debug__:total=%d, size=%d", total, last_read_size); */
+      /*   char *ptr = socket_buf + total; */
+      /*   tomc_p("'%s'", ptr); */
+      /*   total += strlen(ptr); */
+      /* } */
+    }
+  }
 }
 
 int main(int argc, char **argv)
@@ -186,6 +222,8 @@ int main(int argc, char **argv)
   print_options();
   init();
   write_requests();
+
+  tomc_p("dying of our own accord.");
   
   return EXIT_SUCCESS;
 }