From cf6ef4d2963d047c93984a21b1b65e71044797f1 Mon Sep 17 00:00:00 2001 From: Phillip Toland Date: Wed, 10 Dec 2008 12:58:54 -0600 Subject: [PATCH] Added flags to the close_database function. --- c_src/bdberl_drv.c | 17 ++++++++++------- src/bdberl_port.erl | 9 ++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/c_src/bdberl_drv.c b/c_src/bdberl_drv.c index f1bf979..7eb75d7 100644 --- a/c_src/bdberl_drv.c +++ b/c_src/bdberl_drv.c @@ -17,8 +17,8 @@ /** * Function prototypes */ -static int open_database(const char* name, DBTYPE type, unsigned int flags, PortData* data, int* errno); -static int close_database(int dbref, PortData* data); +static int open_database(const char* name, DBTYPE type, unsigned flags, PortData* data, int* errno); +static int close_database(int dbref, unsigned flags, PortData* data); static void do_async_put(void* arg); static void do_async_put_free(void* arg); @@ -182,7 +182,7 @@ static void bdberl_drv_stop(ErlDrvData handle) // Close all the databases we previously opened while (d->dbrefs) { - close_database(d->dbrefs->dbref, d); + close_database(d->dbrefs->dbref, 0, d); } // Release the port instance data @@ -210,7 +210,7 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd, case CMD_OPEN_DB: { // Extract the type code and filename from the inbuf - // Inbuf is: <> + // Inbuf is: <> unsigned flags = (unsigned) DECODE_INT(inbuf, 0); DBTYPE type = (DBTYPE) DECODE_BYTE(inbuf, 4); char* name = DECODE_STRING(inbuf, 5); @@ -240,8 +240,11 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd, // TODO: If data is inflight, fail. Abort any open txns. // Take the provided dbref and attempt to close it + // Inbuf is: <> int dbref = DECODE_INT(inbuf, 0); - int rc = close_database(dbref, d); + unsigned flags = (unsigned) DECODE_INT(inbuf, 4); + + int rc = close_database(dbref, flags, d); // Outbuf is: <> RETURN_INT(rc, outbuf); @@ -538,7 +541,7 @@ static int open_database(const char* name, DBTYPE type, unsigned int flags, Port } } -static int close_database(int dbref, PortData* data) +static int close_database(int dbref, unsigned flags, PortData* data) { printf("Closing %d for port %p\n", dbref, data->port); @@ -562,7 +565,7 @@ static int close_database(int dbref, PortData* data) { printf("Closing actual database for dbref %d\n", dbref); // Close out the BDB handle - database->db->close(database->db, 0); + database->db->close(database->db, flags); // Remove the entry from the names map hive_hash_remove(G_DATABASES_NAMES, database->name); diff --git a/src/bdberl_port.erl b/src/bdberl_port.erl index f58f107..3a0c57c 100644 --- a/src/bdberl_port.erl +++ b/src/bdberl_port.erl @@ -36,6 +36,8 @@ -define(DB_THREAD, 16#00000004). -define(DB_TRUNCATE, 16#00008000). +-define(DB_NOSYNC, 21). + -define(STATUS_OK, 0). -define(STATUS_ERROR, 1). @@ -73,7 +75,11 @@ open_database(Port, Name, Type, Opts) -> end. close_database(Port, DbRef) -> - Cmd = <>, + close_database(Port, DbRef, []). + +close_database(Port, DbRef, Opts) -> + Flags = process_flags(Opts), + Cmd = <>, case erlang:port_control(Port, ?CMD_CLOSE_DB, Cmd) of <<0:32/native-integer>> -> {error, invalid_dbref}; @@ -165,6 +171,7 @@ flag_value(Flag) -> exclusive -> ?DB_EXCL; multiversion -> ?DB_MULTIVERSION; no_mmap -> ?DB_NOMMAP; + no_sync -> ?DB_NOSYNC; readonly -> ?DB_RDONLY; threaded -> ?DB_THREAD; truncate -> ?DB_TRUNCATE