Update socket
authorJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 24 Jan 2020 13:59:07 +0000 (14:59 +0100)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 24 Jan 2020 13:59:07 +0000 (14:59 +0100)
src/siri/db/tee.c

index 47d04269dc6df8ccfaae8f8650348230460a5cc7..f40630b11081acfd4792f3e934a48cb872fb0633 100644 (file)
@@ -49,6 +49,7 @@ void siridb_tee_free(siridb_tee_t * tee)
 
 int siridb_tee_connect(siridb_tee_t * tee)
 {
+    LOGC("TEE CONNECT0");
     uv_connect_t * req = malloc(sizeof(uv_connect_t));
     if (req == NULL)
     {
@@ -65,11 +66,13 @@ int siridb_tee_connect(siridb_tee_t * tee)
     tee->pipe.data = tee;
 
     uv_pipe_connect(req, &tee->pipe, tee->pipe_name_, tee__on_connect);
+    LOGC("TEE CONNECT2");
     return 0;
 }
 
 int siridb_tee_set_pipe_name(siridb_tee_t * tee, const char * pipe_name)
 {
+    LOGC("SET NAME0");
     free(tee->pipe_name_);
     free(tee->err_msg_);
     tee->err_msg_ = NULL;
@@ -98,17 +101,20 @@ int siridb_tee_set_pipe_name(siridb_tee_t * tee, const char * pipe_name)
     {
         tee__runtime_init(&tee->pipe);
     }
+    LOGC("SET NAME5");
     return 0;
 }
 
 void siridb_tee_write(siridb_tee_t * tee, sirinet_promise_t * promise)
 {
+    LOGC("TEE_WRITE0");
     uv_write_t * req = malloc(sizeof(uv_write_t));
     if (!req)
     {
         log_error("Cannot allocate memory for tee request");
         return;
     }
+    LOGC("TEE_WRITE1");
 
     req->data = promise;
     sirinet_promise_incref(promise);
@@ -122,6 +128,7 @@ void siridb_tee_write(siridb_tee_t * tee, sirinet_promise_t * promise)
         log_error("Cannot write to tee");
         sirinet_promise_decref(promise);
     }
+    LOGC("TEE_WRITE2");
 }
 
 const char * tee_str(siridb_tee_t * tee)
@@ -140,6 +147,7 @@ const char * tee_str(siridb_tee_t * tee)
 
 static void tee__runtime_init(uv_pipe_t * pipe)
 {
+    LOGC("ON_INIT0");
     siridb_tee_t * tee = pipe->data;
 
     tee->flags &= ~SIRIDB_TEE_FLAG_INIT;
@@ -149,29 +157,37 @@ static void tee__runtime_init(uv_pipe_t * pipe)
      {
          log_error("Could not connect to tee at runtime");
      }
+     LOGC("ON_INIT2");
 }
 
 static void tee__close_cb(uv_pipe_t * pipe)
 {
+    LOGC("ONCLOSE0");
     siridb_tee_t * tee = pipe->data;
 
+    LOGC("ONCLOSE1");
     tee->flags &= ~SIRIDB_TEE_FLAG_INIT;
     tee->flags &= ~SIRIDB_TEE_FLAG_CONNECTED;
+    LOGC("ONCLOSE2");
 }
 
 static void tee__write_cb(uv_write_t * req, int status)
 {
+    LOGC("ON_WRITE0");
     sirinet_promise_t * promise = req->data;
     sirinet_promise_decref(promise);
+    LOGC("ON_WRITE1");
     if (status)
     {
         log_error("Socket (tee) write error: %s", uv_strerror(status));
     }
     free(req);
+    LOGC("ON_WRITE2");
 }
 
 static void tee__on_connect(uv_connect_t * req, int status)
 {
+    LOGC("ON_CONN0");
     siridb_tee_t * tee = req->data;
 
     if (status == 0)
@@ -191,6 +207,7 @@ static void tee__on_connect(uv_connect_t * req, int status)
         tee->flags |= SIRIDB_TEE_FLAG_CONNECTED;
         goto done;
     }
+    LOGC("ON_CONN1");
 
     free(tee->err_msg_);
     tee->err_msg_ = NULL;
@@ -203,11 +220,14 @@ static void tee__on_connect(uv_connect_t * req, int status)
     {
         log_warning(tee->err_msg_);
     }
+    LOGC("HERE0");
 
 fail:
     uv_close((uv_handle_t *) req->handle, (uv_close_cb) tee__close_cb);
+    LOGC("HERE0.1");
 done:
     free(req);
+    LOGC("HERE1");
 }
 
 static void tee__alloc_buffer(
@@ -215,8 +235,10 @@ static void tee__alloc_buffer(
     size_t suggsz __attribute__((unused)),
     uv_buf_t * buf)
 {
+    LOGC("ALLOC0");
     buf->base = tee__buf;
     buf->len = TEE__BUF_SZ;
+    LOGC("ALLOC1");
 }
 
 
@@ -226,6 +248,7 @@ static void tee__on_data(
     ssize_t nread,
     const uv_buf_t * buf __attribute__((unused)))
 {
+    LOGC("ON_DATA0");
     if (nread < 0)
     {
         if (nread != UV_EOF)
@@ -237,9 +260,12 @@ static void tee__on_data(
         log_info("Disconnected from tee");
         uv_close((uv_handle_t *) client, (uv_close_cb) tee__close_cb);
     }
+    LOGC("ON_DATA1");
 
     if (nread > 0)
     {
         log_debug("Got %zd bytes on tee which will be ignored", nread);
     }
+
+    LOGC("ON_DATA2");
 }