Added flags to get function.
This commit is contained in:
parent
13d1174bb5
commit
332e18e7be
2 changed files with 33 additions and 19 deletions
|
@ -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;
|
||||
|
|
|
@ -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 = <<DbRef:32/native, KeyLen:32/native, KeyBin/bytes>>,
|
||||
Flags = process_flags(Opts),
|
||||
Cmd = <<DbRef:32/native, Flags:32/unsigned-native, KeyLen:32/native, KeyBin/bytes>>,
|
||||
<<Result:32/native>> = 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.
|
||||
|
|
Loading…
Reference in a new issue