/* * BT_CLOSE -- Close a btree. * * Parameters: * dbp: pointer to access method * * Returns: * RET_ERROR, RET_SUCCESS */ int __bt_close(DB *dbp) { BTREE *t; int fd; t = dbp->internal; /* Toss any page pinned across calls. */ if (t->bt_pinned != NULL) { mpool_put(t->bt_mp, t->bt_pinned, 0); t->bt_pinned = NULL; } /* Sync the tree. */ if (__bt_sync(dbp, 0) == RET_ERROR) return (RET_ERROR); /* Close the memory pool. */ if (mpool_close(t->bt_mp) == RET_ERROR) return (RET_ERROR); /* Free random memory. */ if (t->bt_cursor.key.data != NULL) { free(t->bt_cursor.key.data); t->bt_cursor.key.size = 0; t->bt_cursor.key.data = NULL; } if (t->bt_rkey.data) { free(t->bt_rkey.data); t->bt_rkey.size = 0; t->bt_rkey.data = NULL; } if (t->bt_rdata.data) { free(t->bt_rdata.data); t->bt_rdata.size = 0; t->bt_rdata.data = NULL; } fd = t->bt_fd; free(t); free(dbp); return (_close(fd) ? RET_ERROR : RET_SUCCESS); }
int main(int argc, char **argv) { mpool_t *pool; int err = 0; char *str = NULL; int x = 0; int bytes = 1024; if (argc > 1) { int tmp = atoi(argv[1]); if (tmp > 0) { bytes = tmp; } else { fprintf(stderr, "INVALID\n"); exit(255); } } pool = mpool_open(MPOOL_FLAG_ANONYMOUS, 0, NULL, &err); if (!pool || err != MPOOL_ERROR_NONE) { fprintf(stderr, "ERR: %d [%s]\n", err, mpool_strerror(err)); exit(255); } str = mpool_alloc(pool, bytes, &err); memset(str+x, '.', bytes -1); *(str+(bytes-1)) = '\0'; printf("%s\n", str); //mpool_clear(pool); err = mpool_close(pool); if (err != MPOOL_ERROR_NONE) { fprintf(stderr, "ERR: [%s]\n", mpool_strerror(err)); exit(255); } exit(0); }
int main() { // daemonize(); int rv; net_server_t *ns; ns_arg_t sinfo; sinfo.data_func = NULL; strcpy(sinfo.ip,"127.0.0.1"); sinfo.port = 8899; sinfo.max_peers = 1000; sinfo.msg_func = msg_process_func; ns_start_daemon(&ns,&sinfo); void *msg; uint32_t len; char buf[64]; memset(buf,0,sizeof(buf)); int count = 0; //init mem db int fd = open("msg.mdb",O_CREAT|O_RDWR|O_LARGEFILE,0600); MPOOL *mp = mpool_open(NULL,fd,3000,2000); mpool_stat(mp); pgno_t pgno; //process signal struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = handler; sigaction(SIGINT, &sa, NULL); //start check-thread struct thread_info *tinfo; tinfo = calloc(1, sizeof(struct thread_info)); tinfo->mpool = mp; pthread_t thread_id; pthread_mutex_init(&mutex, NULL); pthread_attr_t attr; pthread_attr_init(&attr); pthread_create(&thread_id, &attr, thread_start, tinfo); pthread_attr_destroy(&attr); uint64_t peer_id; while(!stop_daemon) { // rv = ns_recvmsg(ns,&msg,&len,&peer_id,1000000); // rv = ns_tryrecvmsg(ns,&msg,&len,&peer_id); // if(rv == 0) // { /* pthread_mutex_lock(&mutex); void *page = mpool_new(mp,&pgno); memcpy(page,msg,len); mpool_put(mp,page,MPOOL_DIRTY); pthread_mutex_unlock(&mutex); */ // memcpy(buf,(char *)msg,len); // ns_sendmsg(ns,peer_id,buf,len); //ns_disconnect(ns,peer_id); //++count; //printf("count:%d,%u\n",count,time(NULL)); // ns_free(ns,msg); // } //printf("time:%d\n",time(NULL)); sleep(1); } ns_stop_daemon(ns); //tell check data thread to exit pthread_kill(thread_id,SIGINT); pthread_join(thread_id,NULL); pthread_mutex_destroy(&mutex); mpool_close(mp); printf("Normal exit!\n"); return 0; }