diff seobeo/s_linux_network.c @ 96:70401cf61e97

[Seobeo] Added logging.
author June Park <parkjune1995@gmail.com>
date Fri, 02 Jan 2026 19:16:17 -0800
parents 75de5903355c
children
line wrap: on
line diff
--- a/seobeo/s_linux_network.c	Fri Jan 02 19:11:35 2026 -0800
+++ b/seobeo/s_linux_network.c	Fri Jan 02 19:16:17 2026 -0800
@@ -45,7 +45,7 @@
 
   if (listen(socket_fd, 16) != 0)
   { 
-    printf("Closing: %d\n", socket_fd);
+    Seobeo_Log(SEOBEO_DEBUG, "Closing socket: %d\n", socket_fd);
     perror("listen"); close(socket_fd); return NULL; 
   }
 
@@ -73,7 +73,7 @@
   p_handle->write_buffer_capacity = INITIAL_BUFFER_CAPACITY;
   p_handle->write_buffer_len = 0;
 
-  p_handle->destroyed = false;
+  p_handle->destroyed = FALSE;
 
   return p_handle;
 }
@@ -117,7 +117,7 @@
       return NULL;
     }
   }
-  p_handle->connected = true;
+  p_handle->connected = TRUE;
 
   p_handle->host = host != NULL ? strdup(host) : "localhost";
   p_handle->port = strdup(port);
@@ -130,7 +130,7 @@
   p_handle->write_buffer_capacity = INITIAL_BUFFER_CAPACITY;
   p_handle->write_buffer_len = 0;
 
-  p_handle->destroyed = false;
+  p_handle->destroyed = FALSE;
 
   return p_handle;
 }
@@ -159,7 +159,7 @@
 
   p_client_handle->socket               = client_fd;
   p_client_handle->type                 = SEOBEO_STREAM_TYPE_CLIENT;
-  p_client_handle->connected            = true;
+  p_client_handle->connected            = TRUE;
 
   // TODO: support SSL in the future.
   p_client_handle->ssl_ctx              = NULL;
@@ -180,7 +180,7 @@
   p_client_handle->file                  = NULL;
   p_client_handle->text_copy             = NULL;
   p_client_handle->file_name             = NULL;
-  p_client_handle->destroyed             = false;
+  p_client_handle->destroyed             = FALSE;
 
   return p_client_handle;
 }
@@ -189,9 +189,9 @@
 {
   if (!p_handle) return;
 
-  bool expected = false;
+  boolean expected = FALSE;
   // Need to check
-  if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, true))
+  if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, TRUE))
   {
     return;
   }
@@ -202,7 +202,7 @@
   Seobeo_SSL_Cleanup(p_handle);
 
   if (p_handle->socket) {
-    printf("Closing: %d\n", p_handle->socket);
+    Seobeo_Log(SEOBEO_DEBUG, "Closing handle socket: %d\n", p_handle->socket);
     close(p_handle->socket);
   }
 
@@ -218,7 +218,7 @@
   uint32 total = p_handle->write_buffer_len;
   uint32 sent  = 0;
 
-  printf("Total: %d\n\n", p_handle->write_buffer_len);
+  Seobeo_Log(SEOBEO_DEBUG, "Write buffer total: %d\n", p_handle->write_buffer_len);
 
   while (sent < total)
   {
@@ -230,7 +230,7 @@
       sent += (uint32)n;
     }else
     {
-      printf("socket: %d\n", p_handle->socket);
+      Seobeo_Log(SEOBEO_DEBUG, "Flushing socket: %d\n", p_handle->socket);
       ssize_t n = write(
         p_handle->socket,
         p_handle->write_buffer + sent,
@@ -269,7 +269,7 @@
       if (n==0)
       {
         // DEBUG
-        printf("NONE %d\n", offset);
+        Seobeo_Log(SEOBEO_DEBUG, "Write offset: %d\n", offset);
         break;
       }
       if (n < 0)
@@ -285,27 +285,27 @@
       }
       offset += (uint32)n;
       // DEBUG
-      printf("\n\noffset: %d data_size: %d\n\n", offset, data_size);
+      Seobeo_Log(SEOBEO_DEBUG, "Write completed - offset: %d, data_size: %d\n", offset, data_size);
     }
     // DEBUG
-    printf("\n\nTotal: %d\n", offset);
+    Seobeo_Log(SEOBEO_DEBUG, "Total bytes written: %d\n", offset);
     return 0;
   }
 
   if (!p_handle)
   {
-    printf("[ERROR] p_handle is NULL before memcpy\n");
+    Seobeo_Log(SEOBEO_ERROR, "p_handle is NULL before memcpy\n");
     return -1;
   }
   
   if (!p_handle->write_buffer)
   {
-    printf("[ERROR] p_handle->write_buffer is NULL (len=%zu, size=%zu)\n",
+    Seobeo_Log(SEOBEO_ERROR, "p_handle->write_buffer is NULL (len=%u, size=%u)\n",
             p_handle->write_buffer_len, data_size);
     return -1;
   }
   
-  printf("[DEBUG] memcpy -> dest=%p (write_buffer=%p + offset=%zu), src=%p, size=%zu\n",
+  Seobeo_Log(SEOBEO_DEBUG, "memcpy -> dest=%p (write_buffer=%p + offset=%u), src=%p, size=%u\n",
           p_handle->write_buffer + p_handle->write_buffer_len,
           p_handle->write_buffer,
           p_handle->write_buffer_len,