[patch] increased verbosity setting

Evan Martin martine@danga.com
Sun, 10 Aug 2003 11:50:46 -0700


--Apple-Mail-6-629867428
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

This patch lets you add multiple -v flags.  Now -vv will dump the 
client commands/responses as they come in.

(Someone on the list remarked that the -v output doesn't really show 
anything, but looking at the source indicates it shows errors.  I was 
also surprised by seeing nothing when I added -v.
Perhaps it would be better to show errors by default, use -v for this 
functionality I added, and either add a -q (quiet) or just suggest 
piping to /dev/null if you want no output.)



--Apple-Mail-6-629867428
Content-Disposition: attachment;
	filename=memcached-verbose.patch
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="memcached-verbose.patch"

--- memcached/memcached.c	Sun Aug 10 11:30:49 2003
+++ memcached-bsd/memcached.c	Sun Aug 10 11:00:06 2003
@@ -208,6 +208,9 @@
 void out_string(conn *c, char *str) {
     int len;
 
+    if (settings.verbose > 1)
+        fprintf(stderr, ">%d %s\n", c->sfd, str);
+
     len = strlen(str);
     if (len + 2 > c->wsize) {
         /* ought to be always enough. just fail for simplicity */
@@ -458,6 +461,9 @@
      * directly into it, then continue in nread_complete().
      */ 
 
+    if (settings.verbose > 1)
+        fprintf(stderr, "<%d %s\n", c->sfd, command);
+
     if ((strncmp(command, "add ", 4) == 0 && (comm = NREAD_ADD)) || 
         (strncmp(command, "set ", 4) == 0 && (comm = NREAD_SET)) ||
         (strncmp(command, "replace ", 8) == 0 && (comm = NREAD_REPLACE))) {
@@ -708,7 +714,7 @@
         if (c->rbytes >= c->rsize) {
             char *new_rbuf = realloc(c->rbuf, c->rsize*2);
             if (!new_rbuf) {
-                if(settings.verbose)
+                if (settings.verbose > 0)
                     fprintf(stderr, "Couldn't realloc input buffer\n");
                 c->rbytes = 0; /* ignore what we read */
                 out_string(c, "SERVER_ERROR out of memory");
@@ -738,6 +744,7 @@
 }
 
 int update_event(conn *c, int new_flags) {
+    printf("update_event %x %x\n", c->ev_flags, new_flags);
     if (c->ev_flags == new_flags)
         return 1;
     if (event_del(&c->event) == -1) return 0;
@@ -757,7 +764,7 @@
     int res;
 
     while (!exit) {
-      /*printf("state %d\n", c->state); */
+        /* printf("state %d\n", c->state);*/
         switch(c->state) {
         case conn_listening:
             addrlen = sizeof(addr);
@@ -777,7 +784,7 @@
             }            
             newc = conn_new(sfd, conn_read, EV_READ | EV_PERSIST);
             if (!newc) {
-                if(settings.verbose)
+                if (settings.verbose > 0)
                     fprintf(stderr, "couldn't create new connection\n");
                 close(sfd);
                 return;
@@ -794,7 +801,7 @@
             }
             /* we have no command line and no data to read from network */
             if (!update_event(c, EV_READ | EV_PERSIST)) {
-                if(settings.verbose)
+                if (settings.verbose > 0)
                     fprintf(stderr, "Couldn't update event\n");
                 c->state = conn_closing;
                 break;
@@ -835,7 +842,7 @@
             }
             if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                 if (!update_event(c, EV_READ | EV_PERSIST)) {
-                    if(settings.verbose) 
+                    if (settings.verbose > 0) 
                         fprintf(stderr, "Couldn't update event\n");
                     c->state = conn_closing;
                     break;
@@ -844,7 +851,7 @@
                 break;
             }
             /* otherwise we have a real error, on which we close the connection */
-            if(settings.verbose)
+            if (settings.verbose > 0)
                 fprintf(stderr, "Failed to read, and not due to blocking\n");
             c->state = conn_closing;
             break;
@@ -880,7 +887,7 @@
             }
             if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                 if (!update_event(c, EV_READ | EV_PERSIST)) {
-                    if(settings.verbose)
+                    if (settings.verbose > 0)
                         fprintf(stderr, "Couldn't update event\n");
                     c->state = conn_closing;
                     break;
@@ -889,7 +896,7 @@
                 break;
             }
             /* otherwise we have a real error, on which we close the connection */
-            if(settings.verbose)
+            if (settings.verbose > 0)
                 fprintf(stderr, "Failed to read, and not due to blocking\n");
             c->state = conn_closing;
             break;
@@ -913,7 +920,7 @@
             }
             if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                 if (!update_event(c, EV_WRITE | EV_PERSIST)) {
-                    if(settings.verbose)
+                    if (settings.verbose > 0)
                         fprintf(stderr, "Couldn't update event\n");
                     c->state = conn_closing;
                     break;
@@ -923,7 +930,7 @@
             }
             /* if res==0 or res==-1 and error is not EAGAIN or EWOULDBLOCK,
                we have a real error, on which we close the connection */
-            if(settings.verbose)
+            if (settings.verbose > 0)
                 fprintf(stderr, "Failed to write, and not due to blocking\n");
             c->state = conn_closing;
             break;
@@ -947,7 +954,7 @@
                 }
                 if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                     if (!update_event(c, EV_WRITE | EV_PERSIST)) {
-                        if(settings.verbose)
+                        if (settings.verbose > 0)
                             fprintf(stderr, "Couldn't update event\n");
                         c->state = conn_closing;
                         break;
@@ -957,7 +964,7 @@
                 }
                 /* if res==0 or res==-1 and error is not EAGAIN or EWOULDBLOCK,
                    we have a real error, on which we close the connection */
-                if(settings.verbose)
+                if (settings.verbose > 0)
                     fprintf(stderr, "Failed to write, and not due to blocking\n");
                 c->state = conn_closing;
                 break;
@@ -1016,9 +1023,10 @@
     c = (conn *)arg;
     c->which = which;
 
+    printf("event_handler %d\n", fd);
     /* sanity */
     if (fd != c->sfd) {
-        if(settings.verbose)
+        if (settings.verbose > 0)
             fprintf(stderr, "Catastrophic: event fd doesn't match conn fd!\n");
         conn_close(c);
         return;
@@ -1126,6 +1134,7 @@
     printf("-c <num>      max simultaneous connections, default is 1024\n");
     printf("-k            lock down all paged memory\n");
     printf("-v            verbose (print errors/warnings while in event loop)\n");
+    printf("-vv           more verbose (also print client commands/reponses)\n");
     printf("-h            print this help and exit\n");
     printf("-i            print memcached and libevent license\n");
     return;
@@ -1236,7 +1245,7 @@
             lock_memory = 1;
             break;
         case 'v':
-            settings.verbose = 1;
+            settings.verbose++;
             break;
         case 'l':
             if (!inet_aton(optarg, &addr)) {

--Apple-Mail-6-629867428--