From 332e18e7be2f9357ecf71b47a031c63d65b123f4 Mon Sep 17 00:00:00 2001 From: Phillip Toland Date: Wed, 10 Dec 2008 16:57:35 -0600 Subject: [PATCH] Added flags to get function. --- c_src/bdberl_drv.c | 12 +++++++----- src/bdberl_port.erl | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/c_src/bdberl_drv.c b/c_src/bdberl_drv.c index 81dcaa9..ee95c8b 100644 --- a/c_src/bdberl_drv.c +++ b/c_src/bdberl_drv.c @@ -618,7 +618,10 @@ static void do_async_put_free(void* arg) static void do_async_get(void* arg) { printf("do_async_get\n"); + + // Payload is: << DbRef:32, Flags:32, KeyLen:32, Key:KeyLen >> AsyncData* adata = (AsyncData*)arg; + unsigned flags = UNPACK_INT(adata->payload, 4); // Setup DBTs DBT key; @@ -627,9 +630,8 @@ static void do_async_get(void* arg) memset(&value, '\0', sizeof(DBT)); // Parse payload into DBT - // Payload is: << DbRef:32, KeyLen:32, Key:KeyLen >> - key.size = *((int*)(adata->payload + 4)); - key.data = (void*)(adata->payload + 8); + key.size = UNPACK_INT(adata->payload, 8); + key.data = UNPACK_BLOB(adata->payload, 12); // Allocate memory to hold the value -- hard code initial size to 4k // TODO: Make this smarter! @@ -637,13 +639,13 @@ static void do_async_get(void* arg) value.ulen = 4096; value.flags = DB_DBT_USERMEM; - int rc = adata->db->get(adata->db, adata->port->txn, &key, &value, 0); + int rc = adata->db->get(adata->db, adata->port->txn, &key, &value, flags); while (rc == DB_BUFFER_SMALL) { // Grow our value buffer and try again value.data = driver_realloc(value.data, value.size); value.ulen = value.size; - rc = adata->db->get(adata->db, adata->port->txn, &key, &value, 0); + rc = adata->db->get(adata->db, adata->port->txn, &key, &value, flags); } adata->payload = value.data; diff --git a/src/bdberl_port.erl b/src/bdberl_port.erl index a11ec28..2e02eda 100644 --- a/src/bdberl_port.erl +++ b/src/bdberl_port.erl @@ -337,10 +337,13 @@ put(Port, DbRef, Key, Value, Opts) -> ?ERROR_INVALID_DBREF -> {error, invalid_dbref} end. - get(Port, DbRef, Key) -> + get(Port, DbRef, Key, []). + +get(Port, DbRef, Key, Opts) -> {KeyLen, KeyBin} = to_binary(Key), - Cmd = <>, + Flags = process_flags(Opts), + Cmd = <>, <> = erlang:port_control(Port, ?CMD_GET, Cmd), case Result of ?ERROR_NONE -> @@ -365,16 +368,25 @@ process_flags([Flag|Flags]) -> flag_value(Flag) -> case Flag of - append -> ?DB_APPEND; - auto_commit -> ?DB_AUTO_COMMIT; - create -> ?DB_CREATE; - exclusive -> ?DB_EXCL; - multiversion -> ?DB_MULTIVERSION; - no_duplicate -> ?DB_NODUPDATA; - no_mmap -> ?DB_NOMMAP; - no_overwrite -> ?DB_NOOVERWRITE; - no_sync -> ?DB_NOSYNC; - readonly -> ?DB_RDONLY; - threaded -> ?DB_THREAD; - truncate -> ?DB_TRUNCATE + append -> ?DB_APPEND; + auto_commit -> ?DB_AUTO_COMMIT; + consume -> ?DB_CONSUME; + consume_wait -> ?DB_CONSUME_WAIT; + create -> ?DB_CREATE; + exclusive -> ?DB_EXCL; + get_both -> ?DB_GET_BOTH; + ignore_lease -> ?DB_IGNORE_LEASE; + multiple -> ?DB_MULTIPLE; + multiversion -> ?DB_MULTIVERSION; + no_duplicate -> ?DB_NODUPDATA; + no_mmap -> ?DB_NOMMAP; + no_overwrite -> ?DB_NOOVERWRITE; + no_sync -> ?DB_NOSYNC; + read_committed -> ?DB_READ_COMMITTED; + read_uncommitted -> ?DB_READ_UNCOMMITTED; + readonly -> ?DB_RDONLY; + rmw -> ?DB_RMW; + set_recno -> ?DB_SET_RECNO; + threaded -> ?DB_THREAD; + truncate -> ?DB_TRUNCATE end.