int nbspqt_close(nbspqtable_t *qt, int *dberror){ int status = 0; int status1 = 0; int dberror1 = 0; int i; if(qt == NULL) return(0); if(qt->nbspq != NULL){ for(i = 0; i <= qt->n - 1; ++i){ status1 = qdb_close(qt->nbspq[i], &dberror1); if(status == 0){ status = status1; *dberror = dberror1; } } free(qt->nbspq); } free(qt); return(status); }
static void qdbhandle_dealloc(QdbHandle *self) { if (self->qdb) { qdb_close(self->qdb); self->qdb = NULL; } self->ob_type->tp_free((PyObject *)self); }
static PyObject *qdbpy_close(QdbHandle *self) { qdb_handle_t qdb = qdbhandle(self); if (!qdb) return NULL; qdb_close(qdb); self->qdb = NULL; Py_INCREF(Py_None); return Py_None; }
int main(void){ struct nbspqdb_st *nqdb; int status; status = qdb_open(&nqdb, "db.db", sizeof(struct nbspdb_prec_st)); if(status != 0) errx(1, "nbspdb_open: %d", status); print_all_records(nqdb); qdb_close(nqdb); return(0); }
static void New(const v8::FunctionCallbackInfo<v8::Value>& args) { if (args.IsConstructCall()) { MethodMan call(args); if (args.Length() != 1) { call.throwException("Wrong number of arguments"); return; } auto str = call.checkedArgString(0); if (!str.second) { call.throwException("Expected a connection string as an argument"); return; } v8::String::Utf8Value utf8str(str.first); // create and open handle qdb_handle_t h = qdb_open_tcp(); const qdb_error_t err = qdb_connect(h, *utf8str); if (err != qdb_e_ok) { qdb_close(h); call.throwException(qdb_error(err));; return; } // handle is now owned by the cluster object Cluster * cl = new Cluster(h); cl->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { v8::Isolate* isolate = v8::Isolate::GetCurrent(); // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; v8::Local<v8::Value> argv[argc] = { args[0] }; v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(isolate, constructor); args.GetReturnValue().Set(cons->NewInstance(argc, argv)); } }
virtual ~Cluster(void) { // close a nullptr handle is safe qdb_close(_handle); _handle = nullptr; }
nbspqtable_t *nbspqt_open(u_int8_t num_queues, int softlimit, int hardlimit, struct qdb_param_st *qdbparam, int *dberror){ int status = 0; int dberror_close = 0; struct nbsp_qtable_st *qt = NULL; char *dbfname = NULL; int dbfname_size = 0; struct qdb_param_st qdbparam_copy; int size; int i; int memory_based_db = 0; qt = malloc(sizeof(struct nbsp_qtable_st)); if(qt == NULL){ *dberror = errno; return(NULL); } size = num_queues * sizeof(struct nbspq_st*); qt->nbspq = malloc(size); if(qt->nbspq == NULL){ free(qt); *dberror = errno; return(NULL); } qt->n = 0; qt->softlimit = softlimit; qt->hardlimit = hardlimit; qt->reclen = qdbparam->reclen; qt->appdata = NULL; /* If the db file name is NULL or "" it is a memory based queue. */ if((qdbparam->dbname == NULL) || (qdbparam->dbname[0] == '\0')) memory_based_db = 1; if(memory_based_db == 0){ /* leave room to add one byte in hex + ".db" + '\0' */ dbfname_size = strlen(qdbparam->dbname) + 6; dbfname = malloc(dbfname_size); if(dbfname == NULL){ free(qt->nbspq); free(qt); *dberror = errno; return(NULL); } } memcpy(&qdbparam_copy, qdbparam, sizeof(qdbparam_copy)); for(i = 0; (i <= num_queues - 1) && (status == 0); ++i){ if(memory_based_db == 0){ snprintf(dbfname, dbfname_size, "%s%x.db", qdbparam->dbname, i); qdbparam_copy.dbname = dbfname; } status = qdb_open(&(qt->nbspq[i]), &qdbparam_copy, dberror); if(status == 0) ++qt->n; else break; } if(dbfname != NULL) free(dbfname); if(status != 0){ for(i = 0; i <= qt->n - 1; ++i){ qdb_close(qt->nbspq[i], &dberror_close); /* ignore any error here */ } free(qt->nbspq); free(qt); qt = NULL; } return(qt); }