patx/mrhttp-asgi

tmp debug

Commit 896358a · Mark Reed · 2024-03-20T15:21:56-07:00

Changeset
896358a65f61c7b6e0b41c966d2f027a159f4547
Parents
d15a66e44cbf4ff002519719b476026351f93514

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/src/mrhttp/internals/common.h b/src/mrhttp/internals/common.h
index 38cd661..77270ec 100644
--- a/src/mrhttp/internals/common.h
+++ b/src/mrhttp/internals/common.h
@@ -6,7 +6,7 @@
 #define DBG_RESP if(0)
 
 #define DBG_MEMCAC if(0) 
-#define DBG_MRQ if(0) 
+#define DBG_MRQ if(1) 
 
 #define likely(x)       __builtin_expect(!!(x), 1)
 #define unlikely(x)     __builtin_expect(!!(x), 0)
diff --git a/src/mrhttp/internals/mrqprotocol.c b/src/mrhttp/internals/mrqprotocol.c
index 666f862..e3adba8 100644
--- a/src/mrhttp/internals/mrqprotocol.c
+++ b/src/mrhttp/internals/mrqprotocol.c
@@ -322,15 +322,13 @@ int MrqProtocol_push(MrqProtocol* self, char *d, int dsz) {
   }
 
   self->b[1] = 0x1;
-  //self->b[2] = topic;  
-  //self->b[3] = topic;  
 
   //int *p_len = (int*)(self->bp4);
   *self->bp4 = dsz;
   memcpy(self->bb, d, dsz);
 
   PyObject *bytes = PyBytes_FromStringAndSize(self->b, dsz + 6);
-  //printf("mrq push buytes:\n"); PyObject_Print(bytes, stdout,0); printf("\n"); //DELME
+  DBG_MRQ { printf("mrq push buytes:\n"); PyObject_Print(bytes, stdout,0); printf("\n"); } 
   if(!PyObject_CallFunctionObjArgs(self->write, bytes, NULL)) { Py_XDECREF(bytes); return 1; }
   Py_DECREF(bytes);
 
diff --git a/src/mrhttp/internals/protocol.c b/src/mrhttp/internals/protocol.c
index d2df6e1..379e432 100644
--- a/src/mrhttp/internals/protocol.c
+++ b/src/mrhttp/internals/protocol.c
@@ -341,6 +341,7 @@ void Protocol_on_memcached_reply( SessionCallbackData *scd, char *data, int data
         char *p = req->args[0];
         while (len--) slot = (slot * 10) + (*p++ - '0');
         slot &= 0xff;
+        DBG_MRQ printf(" mrq slot found in arg: %d\n",slot);
       } else {
         // The slot is the user id embedded in the session key
         unsigned char *p = (unsigned char*)req->session_id;
@@ -361,6 +362,7 @@ void Protocol_on_memcached_reply( SessionCallbackData *scd, char *data, int data
 
         // push [ user, json ] if append_user is set
         if ( r->append_user ) {
+          DBG_MRQ printf(" mrq appending user data\n");
           // TODO Test using a static buffer
 
           //int rc = MrqClient_push( (MrqClient*)self->app->py_mrq, slot, tmp, (int)(p-tmp) );
@@ -381,7 +383,6 @@ void Protocol_on_memcached_reply( SessionCallbackData *scd, char *data, int data
             rc = MrqClient_pushj( py_mrq, slot, tmp, (int)(p-tmp) );
             free(tmp);
           } else {
-
             char *tmp = malloc( req->body_len + data_sz + 16 ); // TODO avoid malloc with static buffer
             tmp[0] = 0x42;
             char *p = tmp+1;
@@ -389,6 +390,9 @@ void Protocol_on_memcached_reply( SessionCallbackData *scd, char *data, int data
             p += req->body_len;
             memcpy(p, data, data_sz);
             p += data_sz;
+            DBG_MRQ printf(" DELME push to workserver:\n");
+            DBG_MRQ printf(" >%.*s<\n", (int)(p-tmp),tmp);
+            DBG_MRQ print_buffer(tmp, (int)(p-tmp));
             rc = MrqClient_push ( py_mrq, slot, tmp, (int)(p-tmp) );
             free(tmp);
           }
@@ -401,40 +405,12 @@ void Protocol_on_memcached_reply( SessionCallbackData *scd, char *data, int data
 
         }
 
-  // TODO Delete the below and just keep append user? This pulls a user defined key from the json and sends that object
-        /*
-        else if ( r->user_key ) { 
-          //request.user has a dict and we need r->user_key key
-          // TODO or we search for "key": in the char* 
-          PyObject *user = PyObject_GetAttrString((PyObject*)req, "user"  );
-          if ( user ) {
-            PyObject *tmp = PyDict_GetItem( user, r->user_key );
-            // TODO This object could be a long or unicode
-            if ( PyLong_Check(tmp) ) {
-              long v = PyLong_AsLong(tmp);
-              //We want [ 12345, {msg} ]
-              char *tmp = malloc( req->body_len + 32 );
-              tmp[0] = '[';
-              char *s = tmp + 1;
-              do *s++ = (char)(48 + (v % 10ULL)); while(v /= 10ULL);
-              reverse( tmp+1, s-1 );
-              *s = ',';
-              strncpy(s, req->body, req->body_len);
-              s += req->body_len;
-              *s++ = ']';
-              MrqClient_push( (MrqClient*)self->app->py_mrq, slot, tmp, (int)(s-tmp) );
-              free(tmp);
-            }
-  
-          } else {
-            MrqClient_push( (MrqClient*)self->app->py_mrq, slot, req->body, req->body_len );
-          }
-        */  
         else {
           // Send body to mrq
           if ( req->py_mrpack == NULL ) {
             MrqClient_pushj( py_mrq, slot, req->body, req->body_len );
           } else {
+            DBG_MRQ printf(" DELME push to workserver\n");
             MrqClient_push ( py_mrq, slot, req->body, req->body_len );
           }
         }