mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 10:57:34 +08:00
fixed one bug in dbuf; add dbuf samples
This commit is contained in:
parent
ed2e304caf
commit
40f6ebb275
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
3
lib_acl_cpp/samples/dbuf/dbuf1/Makefile
Normal file
3
lib_acl_cpp/samples/dbuf/dbuf1/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
base_path = ../../..
|
||||
PROG = dbuf
|
||||
include ../../Makefile.in
|
3
lib_acl_cpp/samples/dbuf/dbuf2/Makefile
Normal file
3
lib_acl_cpp/samples/dbuf/dbuf2/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
base_path = ../../..
|
||||
PROG = dbuf
|
||||
include ../../Makefile.in
|
58
lib_acl_cpp/samples/dbuf/dbuf2/main.cpp
Normal file
58
lib_acl_cpp/samples/dbuf/dbuf2/main.cpp
Normal 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;
|
||||
}
|
3
lib_acl_cpp/samples/dbuf/dbuf2/valgrind.sh
Normal file
3
lib_acl_cpp/samples/dbuf/dbuf2/valgrind.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./dbuf
|
3
lib_acl_cpp/samples/dbuf/dbuf3/Makefile
Normal file
3
lib_acl_cpp/samples/dbuf/dbuf3/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
base_path = ../../..
|
||||
PROG = dbuf
|
||||
include ../../Makefile.in
|
8
lib_acl_cpp/samples/dbuf/dbuf3/stdafx.cpp
Normal file
8
lib_acl_cpp/samples/dbuf/dbuf3/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// xml.pch 将成为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
//引用任何所需的附加头文件,而不是在此文件中引用
|
13
lib_acl_cpp/samples/dbuf/dbuf3/stdafx.h
Normal file
13
lib_acl_cpp/samples/dbuf/dbuf3/stdafx.h
Normal 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"
|
@ -1,5 +0,0 @@
|
||||
UTIL = $(wildcard ../*.cpp)
|
||||
base_path = ../..
|
||||
PROG = dbuf
|
||||
CFLAGS += -I../
|
||||
include ../Makefile.in
|
@ -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 */)
|
||||
|
Loading…
Reference in New Issue
Block a user