Check-in [4ee118a6b4]
Not logged in
Overview

SHA1 Hash:4ee118a6b4a48494736426fbb4b693de28c26acc
Date: 2007-07-23 20:40:16
User: drh
Comment:More improvements to network sync.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/xfer.c from [72dbb42503] to [9cb0ca67df].

@@ -483,13 +483,13 @@
 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
   int go = 1;        /* Loop until zero */
   int nToken;
   const char *zSCode = db_get("server-code", "x");
   const char *zPCode = db_get("project-code", 0);
-  int nSent = 0;
-  int nRcvd = 0;
-  int nCycle = 0;
+  int nFile = 0;
+  int nMsg = 0;
+  int nReq = 0;
   Blob send;        /* Text we are sending to the server */
   Blob recv;        /* Reply we got back from the server */
   Blob line;        /* A single line of the reply */
   Blob aToken[5];   /* A tokenization of line */
   Blob errmsg;      /* Error message */
@@ -510,23 +510,28 @@
   blob_zero(&errmsg);
 
 
   while( go ){
     go = 0;
+    nFile = nReq = nMsg = 0;
 
     /* Generate a request to be sent to the server.
     ** Always begin with a clone, pull, or push message
     */
+
     if( cloneFlag ){
       blob_appendf(&send, "clone\n");
       pushFlag = 0;
       pullFlag = 0;
+      nMsg++;
     }else if( pullFlag ){
       blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
+      nMsg++;
     }
     if( pushFlag ){
       blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
+      nMsg++;
     }
 
     if( pullFlag ){
       /* Send gimme message for every phantom that we hold.
       */
@@ -533,17 +538,18 @@
       Stmt q;
       db_prepare(&q, "SELECT uuid FROM blob WHERE size<0");
       while( db_step(&q)==SQLITE_ROW ){
         const char *zUuid = db_column_text(&q, 0);
         blob_appendf(&send,"gimme %s\n", zUuid);
+        nReq++;
       }
       db_finalize(&q);
     }
 
     if( pushFlag ){
       /* Send the server any files that the server has requested */
-      nSent += send_all_pending(&send);
+      nFile += send_all_pending(&send);
     }
 
     if( pullFlag || pushFlag ){
       /* Always send our leaves */
       Stmt q;
@@ -552,16 +558,19 @@
          "  (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)"
       );
       while( db_step(&q)==SQLITE_ROW ){
         const char *zUuid = db_column_text(&q, 0);
         blob_appendf(&send, "leaf %s\n", zUuid);
+        nMsg++;
       }
       db_finalize(&q);
     }
 
     /* Exchange messages with the server */
-    printf("Sending %d files to server\n", nSent);
+    printf("Send:      %d files, %d requests, %d other messages\n",
+            nFile, nReq, nMsg);
+    nFile = nReq = nMsg = 0;
     http_exchange(&send, &recv);
     blob_reset(&send);
 
     /* Process the reply that came back from the server */
     while( blob_line(&recv, &line) ){
@@ -572,19 +581,20 @@
       **
       ** Receive a file transmitted from the other side
       */
       if( blob_eq(&aToken[0],"file") ){
         xfer_accept_file(&recv, aToken, nToken, &errmsg);
-        nRcvd++;
+        nFile++;
       }else
 
       /*   gimme UUID
       **
       ** Server is requesting a file
       */
       if( blob_eq(&aToken[0], "gimme") && nToken==2
                && blob_is_uuid(&aToken[1]) ){
+        nReq++;
         if( pushFlag ){
           db_multi_exec(
             "INSERT OR IGNORE INTO pending(rid) "
             "SELECT rid FROM blob WHERE uuid=%B AND size>=0", &aToken[1]
           );
@@ -600,10 +610,11 @@
       */
       if( nToken==2
               && (blob_eq(&aToken[0], "igot") || blob_eq(&aToken[0], "leaf"))
               && blob_is_uuid(&aToken[1]) ){
         int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &aToken[1]);
+        nMsg++;
         if( rid>0 ){
           db_multi_exec(
             "INSERT OR IGNORE INTO onremote(rid) VALUES(%d)", rid
           );
           /* Add to the pending set all children of the server's leaves */
@@ -632,10 +643,11 @@
               && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
 
         if( blob_eq_str(&aToken[1], zSCode, -1) ){
           fossil_fatal("server loop");
         }
+        nMsg++;
         if( zPCode==0 ){
           zPCode = mprintf("%b", &aToken[2]);
           db_set("project-code", zPCode);
         }
         cloneFlag = 0;
@@ -661,15 +673,16 @@
         fossil_fatal("%b", &errmsg);
       }
       blobarray_reset(aToken, nToken);
     }
     blob_reset(&recv);
-    printf("Received %d files from server\n", nRcvd);
-    nSent = nRcvd = 0;
+    printf("Received:  %d files, %d requests, %d other messages\n",
+            nFile, nReq, nMsg);
+    nFile = nReq = nMsg = 0;
   };
   http_close();
   db_end_transaction(0);
   db_multi_exec(
     "DROP TABLE onremote;"
     "DROP TABLE pending;"
   );
 }