Fossil SCM
Keep track of total network traffic for a sync and report the totals at the end of the sync.
Commit
79be9028ebdac88a1184179704d1a7549162aed4
Parent
7646ee13e34f6aa…
2 files changed
+19
-2
+5
-2
+19
-2
| --- src/http_transport.c | ||
| +++ src/http_transport.c | ||
| @@ -36,23 +36,38 @@ | ||
| 36 | 36 | int isOpen; /* True when the transport layer is open */ |
| 37 | 37 | char *pBuf; /* Buffer used to hold the reply */ |
| 38 | 38 | int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | 39 | int nUsed ; /* Space of transportBuf[] used */ |
| 40 | 40 | int iCursor; /* Next unread by in transportBuf[] */ |
| 41 | + int nSent; /* Number of bytes sent */ | |
| 42 | + int nRcvd; /* Number of bytes received */ | |
| 41 | 43 | FILE *pFile; /* File I/O for FILE: */ |
| 42 | 44 | char *zOutFile; /* Name of outbound file for FILE: */ |
| 43 | 45 | char *zInFile; /* Name of inbound file for FILE: */ |
| 44 | 46 | } transport = { |
| 45 | - 0, 0, 0, 0, 0 | |
| 47 | + 0, 0, 0, 0, 0, 0, 0 | |
| 46 | 48 | }; |
| 47 | 49 | |
| 48 | 50 | /* |
| 49 | 51 | ** Return the current transport error message. |
| 50 | 52 | */ |
| 51 | 53 | const char *transport_errmsg(void){ |
| 52 | 54 | return socket_errmsg(); |
| 53 | 55 | } |
| 56 | + | |
| 57 | +/* | |
| 58 | +** Retrieve send/receive counts from the transport layer. If "resetFlag" | |
| 59 | +** is true, then reset the counts. | |
| 60 | +*/ | |
| 61 | +void transport_stats(int *pnSent, int *pnRcvd, int resetFlag){ | |
| 62 | + if( pnSent ) *pnSent = transport.nSent; | |
| 63 | + if( pnRcvd ) *pnRcvd = transport.nRcvd; | |
| 64 | + if( resetFlag ){ | |
| 65 | + transport.nSent = 0; | |
| 66 | + transport.nRcvd = 0; | |
| 67 | + } | |
| 68 | +} | |
| 54 | 69 | |
| 55 | 70 | /* |
| 56 | 71 | ** Open a connection to the server. The server is defined by the following |
| 57 | 72 | ** global variables: |
| 58 | 73 | ** |
| @@ -120,10 +135,11 @@ | ||
| 120 | 135 | ** Send content over the wire. |
| 121 | 136 | */ |
| 122 | 137 | void transport_send(Blob *toSend){ |
| 123 | 138 | char *z = blob_buffer(toSend); |
| 124 | 139 | int n = blob_size(toSend); |
| 140 | + transport.nSent += n; | |
| 125 | 141 | if( g.urlIsHttps ){ |
| 126 | 142 | /* TBD */ |
| 127 | 143 | }else if( g.urlIsFile ){ |
| 128 | 144 | fwrite(z, 1, n, transport.pFile); |
| 129 | 145 | }else{ |
| @@ -202,11 +218,12 @@ | ||
| 202 | 218 | }else{ |
| 203 | 219 | got = socket_receive(0, zBuf, N); |
| 204 | 220 | /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */ |
| 205 | 221 | } |
| 206 | 222 | if( got>0 ){ |
| 207 | - nByte += got; | |
| 223 | + nByte += got; | |
| 224 | + transport.nRcvd += got; | |
| 208 | 225 | } |
| 209 | 226 | } |
| 210 | 227 | return nByte; |
| 211 | 228 | } |
| 212 | 229 | |
| 213 | 230 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -36,23 +36,38 @@ | |
| 36 | int isOpen; /* True when the transport layer is open */ |
| 37 | char *pBuf; /* Buffer used to hold the reply */ |
| 38 | int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | int nUsed ; /* Space of transportBuf[] used */ |
| 40 | int iCursor; /* Next unread by in transportBuf[] */ |
| 41 | FILE *pFile; /* File I/O for FILE: */ |
| 42 | char *zOutFile; /* Name of outbound file for FILE: */ |
| 43 | char *zInFile; /* Name of inbound file for FILE: */ |
| 44 | } transport = { |
| 45 | 0, 0, 0, 0, 0 |
| 46 | }; |
| 47 | |
| 48 | /* |
| 49 | ** Return the current transport error message. |
| 50 | */ |
| 51 | const char *transport_errmsg(void){ |
| 52 | return socket_errmsg(); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | ** Open a connection to the server. The server is defined by the following |
| 57 | ** global variables: |
| 58 | ** |
| @@ -120,10 +135,11 @@ | |
| 120 | ** Send content over the wire. |
| 121 | */ |
| 122 | void transport_send(Blob *toSend){ |
| 123 | char *z = blob_buffer(toSend); |
| 124 | int n = blob_size(toSend); |
| 125 | if( g.urlIsHttps ){ |
| 126 | /* TBD */ |
| 127 | }else if( g.urlIsFile ){ |
| 128 | fwrite(z, 1, n, transport.pFile); |
| 129 | }else{ |
| @@ -202,11 +218,12 @@ | |
| 202 | }else{ |
| 203 | got = socket_receive(0, zBuf, N); |
| 204 | /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */ |
| 205 | } |
| 206 | if( got>0 ){ |
| 207 | nByte += got; |
| 208 | } |
| 209 | } |
| 210 | return nByte; |
| 211 | } |
| 212 | |
| 213 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -36,23 +36,38 @@ | |
| 36 | int isOpen; /* True when the transport layer is open */ |
| 37 | char *pBuf; /* Buffer used to hold the reply */ |
| 38 | int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | int nUsed ; /* Space of transportBuf[] used */ |
| 40 | int iCursor; /* Next unread by in transportBuf[] */ |
| 41 | int nSent; /* Number of bytes sent */ |
| 42 | int nRcvd; /* Number of bytes received */ |
| 43 | FILE *pFile; /* File I/O for FILE: */ |
| 44 | char *zOutFile; /* Name of outbound file for FILE: */ |
| 45 | char *zInFile; /* Name of inbound file for FILE: */ |
| 46 | } transport = { |
| 47 | 0, 0, 0, 0, 0, 0, 0 |
| 48 | }; |
| 49 | |
| 50 | /* |
| 51 | ** Return the current transport error message. |
| 52 | */ |
| 53 | const char *transport_errmsg(void){ |
| 54 | return socket_errmsg(); |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | ** Retrieve send/receive counts from the transport layer. If "resetFlag" |
| 59 | ** is true, then reset the counts. |
| 60 | */ |
| 61 | void transport_stats(int *pnSent, int *pnRcvd, int resetFlag){ |
| 62 | if( pnSent ) *pnSent = transport.nSent; |
| 63 | if( pnRcvd ) *pnRcvd = transport.nRcvd; |
| 64 | if( resetFlag ){ |
| 65 | transport.nSent = 0; |
| 66 | transport.nRcvd = 0; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | ** Open a connection to the server. The server is defined by the following |
| 72 | ** global variables: |
| 73 | ** |
| @@ -120,10 +135,11 @@ | |
| 135 | ** Send content over the wire. |
| 136 | */ |
| 137 | void transport_send(Blob *toSend){ |
| 138 | char *z = blob_buffer(toSend); |
| 139 | int n = blob_size(toSend); |
| 140 | transport.nSent += n; |
| 141 | if( g.urlIsHttps ){ |
| 142 | /* TBD */ |
| 143 | }else if( g.urlIsFile ){ |
| 144 | fwrite(z, 1, n, transport.pFile); |
| 145 | }else{ |
| @@ -202,11 +218,12 @@ | |
| 218 | }else{ |
| 219 | got = socket_receive(0, zBuf, N); |
| 220 | /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */ |
| 221 | } |
| 222 | if( got>0 ){ |
| 223 | nByte += got; |
| 224 | transport.nRcvd += got; |
| 225 | } |
| 226 | } |
| 227 | return nByte; |
| 228 | } |
| 229 | |
| 230 |
+5
-2
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -862,16 +862,18 @@ | ||
| 862 | 862 | int nFileSend = 0; |
| 863 | 863 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 864 | 864 | int nFileRecv; /* Number of files received */ |
| 865 | 865 | int mxPhantomReq = 200; /* Max number of phantoms to request per comm */ |
| 866 | 866 | const char *zCookie; /* Server cookie */ |
| 867 | + int nSent, nRcvd; /* Bytes sent and received (after compression) */ | |
| 867 | 868 | Blob send; /* Text we are sending to the server */ |
| 868 | 869 | Blob recv; /* Reply we got back from the server */ |
| 869 | 870 | Xfer xfer; /* Transfer data */ |
| 870 | 871 | const char *zSCode = db_get("server-code", "x"); |
| 871 | 872 | const char *zPCode = db_get("project-code", 0); |
| 872 | 873 | |
| 874 | + transport_stats(0, 0, 1); | |
| 873 | 875 | socket_global_init(); |
| 874 | 876 | memset(&xfer, 0, sizeof(xfer)); |
| 875 | 877 | xfer.pIn = &recv; |
| 876 | 878 | xfer.pOut = &send; |
| 877 | 879 | xfer.mxSend = db_get_int("max-upload", 250000); |
| @@ -957,15 +959,13 @@ | ||
| 957 | 959 | } |
| 958 | 960 | configSendMask = 0; |
| 959 | 961 | } |
| 960 | 962 | |
| 961 | 963 | /* Append randomness to the end of the message */ |
| 962 | -#if 1 /* Enable this after all servers have upgraded */ | |
| 963 | 964 | zRandomness = db_text(0, "SELECT hex(randomblob(20))"); |
| 964 | 965 | blob_appendf(&send, "# %s\n", zRandomness); |
| 965 | 966 | free(zRandomness); |
| 966 | -#endif | |
| 967 | 967 | |
| 968 | 968 | /* Exchange messages with the server */ |
| 969 | 969 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 970 | 970 | printf(zValueFormat, "Send:", |
| 971 | 971 | blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, |
| @@ -1180,10 +1180,13 @@ | ||
| 1180 | 1180 | */ |
| 1181 | 1181 | if( xfer.nFileSent+xfer.nDeltaSent>0 ){ |
| 1182 | 1182 | go = 1; |
| 1183 | 1183 | } |
| 1184 | 1184 | }; |
| 1185 | + transport_stats(&nSent, &nRcvd, 1); | |
| 1186 | + printf("Total network traffic: %d bytes sent, %d bytes received\n", | |
| 1187 | + nSent, nRcvd); | |
| 1185 | 1188 | transport_close(); |
| 1186 | 1189 | socket_global_shutdown(); |
| 1187 | 1190 | db_multi_exec("DROP TABLE onremote"); |
| 1188 | 1191 | db_end_transaction(0); |
| 1189 | 1192 | } |
| 1190 | 1193 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -862,16 +862,18 @@ | |
| 862 | int nFileSend = 0; |
| 863 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 864 | int nFileRecv; /* Number of files received */ |
| 865 | int mxPhantomReq = 200; /* Max number of phantoms to request per comm */ |
| 866 | const char *zCookie; /* Server cookie */ |
| 867 | Blob send; /* Text we are sending to the server */ |
| 868 | Blob recv; /* Reply we got back from the server */ |
| 869 | Xfer xfer; /* Transfer data */ |
| 870 | const char *zSCode = db_get("server-code", "x"); |
| 871 | const char *zPCode = db_get("project-code", 0); |
| 872 | |
| 873 | socket_global_init(); |
| 874 | memset(&xfer, 0, sizeof(xfer)); |
| 875 | xfer.pIn = &recv; |
| 876 | xfer.pOut = &send; |
| 877 | xfer.mxSend = db_get_int("max-upload", 250000); |
| @@ -957,15 +959,13 @@ | |
| 957 | } |
| 958 | configSendMask = 0; |
| 959 | } |
| 960 | |
| 961 | /* Append randomness to the end of the message */ |
| 962 | #if 1 /* Enable this after all servers have upgraded */ |
| 963 | zRandomness = db_text(0, "SELECT hex(randomblob(20))"); |
| 964 | blob_appendf(&send, "# %s\n", zRandomness); |
| 965 | free(zRandomness); |
| 966 | #endif |
| 967 | |
| 968 | /* Exchange messages with the server */ |
| 969 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 970 | printf(zValueFormat, "Send:", |
| 971 | blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, |
| @@ -1180,10 +1180,13 @@ | |
| 1180 | */ |
| 1181 | if( xfer.nFileSent+xfer.nDeltaSent>0 ){ |
| 1182 | go = 1; |
| 1183 | } |
| 1184 | }; |
| 1185 | transport_close(); |
| 1186 | socket_global_shutdown(); |
| 1187 | db_multi_exec("DROP TABLE onremote"); |
| 1188 | db_end_transaction(0); |
| 1189 | } |
| 1190 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -862,16 +862,18 @@ | |
| 862 | int nFileSend = 0; |
| 863 | int origConfigRcvMask; /* Original value of configRcvMask */ |
| 864 | int nFileRecv; /* Number of files received */ |
| 865 | int mxPhantomReq = 200; /* Max number of phantoms to request per comm */ |
| 866 | const char *zCookie; /* Server cookie */ |
| 867 | int nSent, nRcvd; /* Bytes sent and received (after compression) */ |
| 868 | Blob send; /* Text we are sending to the server */ |
| 869 | Blob recv; /* Reply we got back from the server */ |
| 870 | Xfer xfer; /* Transfer data */ |
| 871 | const char *zSCode = db_get("server-code", "x"); |
| 872 | const char *zPCode = db_get("project-code", 0); |
| 873 | |
| 874 | transport_stats(0, 0, 1); |
| 875 | socket_global_init(); |
| 876 | memset(&xfer, 0, sizeof(xfer)); |
| 877 | xfer.pIn = &recv; |
| 878 | xfer.pOut = &send; |
| 879 | xfer.mxSend = db_get_int("max-upload", 250000); |
| @@ -957,15 +959,13 @@ | |
| 959 | } |
| 960 | configSendMask = 0; |
| 961 | } |
| 962 | |
| 963 | /* Append randomness to the end of the message */ |
| 964 | zRandomness = db_text(0, "SELECT hex(randomblob(20))"); |
| 965 | blob_appendf(&send, "# %s\n", zRandomness); |
| 966 | free(zRandomness); |
| 967 | |
| 968 | /* Exchange messages with the server */ |
| 969 | nFileSend = xfer.nFileSent + xfer.nDeltaSent; |
| 970 | printf(zValueFormat, "Send:", |
| 971 | blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, |
| @@ -1180,10 +1180,13 @@ | |
| 1180 | */ |
| 1181 | if( xfer.nFileSent+xfer.nDeltaSent>0 ){ |
| 1182 | go = 1; |
| 1183 | } |
| 1184 | }; |
| 1185 | transport_stats(&nSent, &nRcvd, 1); |
| 1186 | printf("Total network traffic: %d bytes sent, %d bytes received\n", |
| 1187 | nSent, nRcvd); |
| 1188 | transport_close(); |
| 1189 | socket_global_shutdown(); |
| 1190 | db_multi_exec("DROP TABLE onremote"); |
| 1191 | db_end_transaction(0); |
| 1192 | } |
| 1193 |