Switch to omap
authorJeroen van der Heijden <jeroen@cesbit.com>
Wed, 9 Feb 2022 10:00:11 +0000 (11:00 +0100)
committerJeroen van der Heijden <jeroen@cesbit.com>
Wed, 9 Feb 2022 10:00:11 +0000 (11:00 +0100)
include/siri/db/server.h
include/siri/version.h
src/siri/db/server.c
src/siri/db/servers.c

index ae188b8d64d6aa8cd492cd1188773eeddf1b51ea..6a6afdf27c29e03abc1b56e073bac84ceecb9e8b 100644 (file)
@@ -80,7 +80,7 @@ typedef struct siridb_server_async_s siridb_server_async_t;
 #include <uuid/uuid.h>
 #include <stdint.h>
 #include <siri/db/db.h>
-#include <imap/imap.h>
+#include <omap/omap.h>
 #include <cexpr/cexpr.h>
 #include <uv.h>
 #include <siri/net/promise.h>
@@ -149,7 +149,7 @@ struct siridb_server_s
     uint8_t id; /* set when added to a pool to either 0 or 1 */
     char * name; /* this is a format for address:port but we use it a lot */
     char * address;
-    imap_t * promises;
+    omap_t * promises;
     sirinet_stream_t * client;
     uint16_t pid;
     /* fixed server properties */
index 3e8d3e30fa947c1f94210331224be0a862569988..b1fa8e006efbb4643ce91c8a839ce17a4a6d3ffa 100644 (file)
@@ -15,7 +15,7 @@
  * Note that debian alpha packages should use versions like this:
  *   2.0.34-0alpha0
  */
-#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0"
+#define SIRIDB_VERSION_PRE_RELEASE "-alpha-1"
 
 #ifndef NDEBUG
 #define SIRIDB_VERSION_BUILD_RELEASE "+debug"
index 9fb96015695a16569c248eefc0b113662ac3ef1c..7b4299223676b1ed692e7e997c7dcc6e9b929450 100644 (file)
@@ -174,15 +174,15 @@ int siridb_server_send_pkg(
          * might still be in use and we should try another pid.
          */
         promise->pid = server->pid++;
-        rc = imap_add(server->promises, promise->pid, promise);
+        rc = omap_add(server->promises, promise->pid, promise);
 
-        if (rc == 0)
+        if (rc == OMAP_SUCCESS)
         {
             SERVER_upd_flag_queue_full(server);
             break;
         }
 
-        if (rc == -1)
+        if (rc == OMAP_ERR_ALLOC)
         {
             /* memory allocation error */
             free(promise->timer);
@@ -192,7 +192,7 @@ int siridb_server_send_pkg(
             return -1;
         }
 
-        /* rc == -2, pid in use, try next pid */
+        /* rc == OMAP_ERR_EXIST, pid in use, try next pid */
     }
 
     if (!n)
@@ -281,7 +281,7 @@ siridb_server_t * siridb_server_register(
 
         if (server != NULL)
         {
-            if (    (server->promises = imap_new()) == NULL ||
+            if (    (server->promises = omap_create()) == NULL ||
                     siridb_servers_register(siridb, server))
             {
                 siridb__server_free(server);
@@ -580,7 +580,7 @@ static void SERVER_on_resolved(
  */
 static void SERVER_upd_flag_queue_full(siridb_server_t * server)
 {
-    if (server->promises->len >= SIRIDB_SERVER_PROMISES_QUEUE_SIZE)
+    if (server->promises->n >= SIRIDB_SERVER_PROMISES_QUEUE_SIZE)
     {
         server->flags |= SERVER_FLAG_QUEUE_FULL;
     }
@@ -605,7 +605,7 @@ static void SERVER_write_cb(uv_write_t * req, int status)
             promise->pid,
             uv_strerror(status));
 
-        if (imap_pop(promise->server->promises, promise->pid) == NULL)
+        if (omap_rm(promise->server->promises, promise->pid) == NULL)
         {
             log_critical(
                     "Got a socket error but the promise is not found. "
@@ -634,7 +634,7 @@ static void SERVER_timeout_pkg(uv_timer_t * handle)
 {
     sirinet_promise_t * promise = handle->data;
 
-    if (imap_pop(promise->server->promises, promise->pid) == NULL)
+    if (omap_rm(promise->server->promises, promise->pid) == NULL)
     {
         log_critical(
                 "Timeout task is called on package (PID %" PRIu16
@@ -741,7 +741,7 @@ static void SERVER_on_connect(uv_connect_t * req, int status)
 static void SERVER_on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg)
 {
     siridb_server_t * server = client->origin;
-    sirinet_promise_t * promise = imap_pop(server->promises, pkg->pid);
+    sirinet_promise_t * promise = omap_rm(server->promises, pkg->pid);
 
     log_debug(
             "Response received (pid: %" PRIu16
@@ -937,7 +937,7 @@ void siridb__server_free(siridb_server_t * server)
      */
     if (server->promises != NULL)
     {
-        imap_free(server->promises, (imap_free_cb) SERVER_cancel_promise);
+        omap_destroy(server->promises, (omap_destroy_cb) SERVER_cancel_promise);
     }
     free(server->name);
     free(server->address);
index 15c2b0d5ed86a5b539b24a4532bffed5436a2760..f4bebd05607abdcff8f95d44dbb4499836c01846 100644 (file)
@@ -136,7 +136,7 @@ int siridb_servers_load(siridb_t * siridb)
             else
             {
                 /* if this is not me, create promises */
-                server->promises = imap_new();
+                server->promises = omap_create();
                 if (server->promises == NULL)
                 {
                     log_critical("Memory allocation error");