fixed one bug in dbuf; add dbuf samples

This commit is contained in:
ubuntu14 2015-11-12 06:24:05 -08:00
parent ed2e304caf
commit 40f6ebb275
20 changed files with 106 additions and 15 deletions

View File

@ -4,6 +4,7 @@
374) 2015.11.12
374.1) feature: http_request_manager 的构造函数增加了连接 http 服务器的超时时间
及 IO 读写超时时间
374.2) bugfix: 修复了 dbuf_obj 构造函数中的 BUG应该首先将 nrefer_ 初始化为 0
373) 2015.11.11
373.1) bugfix: mail_message 类中的 append_addrs 方法存在一处指针溢出的 BUG

View File

@ -45,6 +45,7 @@ all:
@(cd socket; make)
@(cd db; make)
@(cd redis; make)
@(cd dbuf; make)
clean:
@(cd string; make clean)
@ -93,5 +94,6 @@ clean:
@(cd socket; make clean)
@(cd db; make clean)
@(cd redis; make clean)
@(cd dbuf; make clean)
rebuild rb: clean all

View File

@ -1,5 +1,11 @@
UTIL = $(wildcard ../*.cpp)
base_path = ../..
PROG = dbuf
CFLAGS += -I../
include ../Makefile.in
.PHONY = all clean
all:
@(cd dbuf1; make)
@(cd dbuf2; make)
@(cd dbuf3; make)
clean:
@(cd dbuf1; make clean)
@(cd dbuf2; make clean)
@(cd dbuf3; make clean)

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = dbuf
include ../../Makefile.in

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = dbuf
include ../../Makefile.in

View File

@ -0,0 +1,58 @@
// xml.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <sys/time.h>
class myobj : public acl::dbuf_obj
{
public:
myobj(acl::dbuf_guard* guard) : dbuf_obj(guard)
{
ptr_ = strdup("hello");
}
void run()
{
printf("----> hello world <-----\r\n");
}
private:
char* ptr_;
~myobj()
{
free(ptr_);
printf("----> myobj destroied <-----\r\n");
}
};
int main(void)
{
acl::log::stdout_open(true);
acl::dbuf_guard dbuf;
for (int i = 0; i < 102400; i++)
dbuf.dbuf_alloc(10);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(2048);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(1024);
dbuf.dbuf_alloc(10240);
for (int i = 0; i < 10; i++)
{
myobj* obj = new (dbuf.dbuf_alloc(sizeof(myobj))) myobj(&dbuf);
obj->run();
}
return 0;
}

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./dbuf

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = dbuf
include ../../Makefile.in

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// xml.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View File

@ -0,0 +1,13 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"

View File

@ -1,5 +0,0 @@
UTIL = $(wildcard ../*.cpp)
base_path = ../..
PROG = dbuf
CFLAGS += -I../
include ../Makefile.in

View File

@ -89,14 +89,10 @@ bool dbuf_pool::dbuf_unkeep(const void* addr)
//////////////////////////////////////////////////////////////////////////////
dbuf_obj::dbuf_obj(dbuf_guard* guard /* = NULL */)
: nrefer_(0)
{
if (guard)
{
nrefer_ = 1;
guard->push_back(this);
}
else
nrefer_ = 0;
}
dbuf_guard::dbuf_guard(acl::dbuf_pool* dbuf /* = NULL */, size_t nblock /* = 2 */)