资源简介
使用c++语言实现linux操作系统下的基础库开发,主要有多线程,锁,异步通信,信号等类封装。在今后的linux下c++开发提供基础库的支持,只需完成业务需求即可。附有异步通信测试程序。本基础库还有不完善的地方,大家的意见可以邮件给我,在此不胜感激。

代码片段和文件信息
/***********************************************************************
* Module: AsynSocketService.cpp 异步通讯类
* Author: bz
* Modified: 2008-08-18
* Version: 1.1.1000
***********************************************************************/
#include “AsynSocket.h“
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace BZ;
/*****BMemoryBuffer*******/
BMemoryBuffer::BMemoryBuffer(int size):_pos(0)_cap(0)_mark(-1)_limit(0)_Buffer(NULL) {
this->Init(NULLsize);
}
BMemoryBuffer::BMemoryBuffer(const char *srcint len):_pos(0)_cap(0)_mark(-1)_limit(0)_Buffer(NULL) {
this->Init(srclen);
}
BMemoryBuffer::~BMemoryBuffer() {
if (this->_Buffer != NULL) {
delete[] this->_Buffer;
}
}
BMemoryBuffer* BMemoryBuffer::Clone() {
BMemoryBuffer* temp = new BMemoryBuffer(this->GetCapacity());
this->Put(*temp);
return temp;
}
void BMemoryBuffer::Init(const char *srcint size) {
if (size <= 0) return;
//1.分配内存
this->_Buffer = new char[size + 1];
memset(this->_Buffer0(size + 1));
//2.设置相关参数
this->_cap = size;
this->_limit = this->_cap;
//将数据拷贝到缓冲中
if (src != NULL) {
memcpy(this->_Buffersrcsize);
this->_pos += size;
}
}
void BMemoryBuffer::Clear() {
memset(this->_Buffer0this->_cap + 1);
this->_pos = 0;
this->_limit = this->_cap;
this->_mark = -1;
}
void BMemoryBuffer::Flip() {
this->_limit = this->_pos;
this->_pos = 0;
this->_mark = -1;
}
void BMemoryBuffer::Mark() {
this->_mark = this->_pos;
}
void BMemoryBuffer::Reset() {
if (this->_mark != -1) {
this->_pos = this->_mark;
}
}
void BMemoryBuffer::Rewind() {
this->_pos = 0;
this->_mark = -1;
}
int BMemoryBuffer::SetPos(int pos) {
if (pos < 0 || pos > this->_limit) return -1;
if (this->_mark != -1 && this->_mark > pos) this->_mark = -1;
this->_pos = pos;
return 0;
}
int BMemoryBuffer::SetLimit(int limit) {
if (limit < 0 || limit > this->_cap) return -1;
this->_limit = limit;
if (this->_mark != -1 && this->_mark > this->_limit) this->_mark = -1;
if (this->_pos > this->_limit) {
this->_pos = this->_limit;
}
return 0;
}
int BMemoryBuffer::GetCapacity() const {
return this->_cap;
}
int BMemoryBuffer::GetPos() const {
return this->_pos;
}
int BMemoryBuffer::GetLimit() const {
return this->_limit;
}
int BMemoryBuffer::GetRemaining() const {
return (this->_limit - this->_pos);
}
bool BMemoryBuffer::IsRemaining() {
if (this->GetRemaining()) return true;
else return false;
}
int BMemoryBuffer::CopyTo(char *destint len) {
if (len <= 0 || len > this->GetRemaining()) return -1;
memcpy(destthis->_Buffer + this->_poslen);
this->_pos += len;
return 0;
}
int BMemoryBuffer::CopyTo(char *destint offsetint len) {
if (len <= 0 || len > t
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 21232 2010-02-10 14:06 C++-Wrapper\src\AsynSocket.h
文件 56793 2010-02-10 14:18 C++-Wrapper\src\AsynSocketService.cpp
文件 8547 2010-02-10 13:35 C++-Wrapper\src\CommThread.cpp
文件 3683 2009-06-25 14:45 C++-Wrapper\src\Component.cpp
文件 2392 2010-02-09 16:37 C++-Wrapper\src\Component.h
文件 4288 2009-12-30 13:46 C++-Wrapper\src\DBPool.h
文件 17511 2009-12-11 13:23 C++-Wrapper\src\Des.cpp
文件 3940 2010-02-09 17:02 C++-Wrapper\src\Job.cpp
文件 15843 2010-02-09 11:12 C++-Wrapper\src\LogFile.cpp
文件 11394 2010-02-09 10:50 C++-Wrapper\src\LogFile.h
文件 1584 2010-01-04 09:56 C++-Wrapper\src\Makefile
文件 14363 2009-12-11 12:40 C++-Wrapper\src\MD5.cpp
文件 3708 2010-02-09 16:36 C++-Wrapper\src\Mysqldb.h
文件 12167 2010-02-09 16:35 C++-Wrapper\src\MysqlDBPool.cpp
文件 3340 2009-12-11 12:47 C++-Wrapper\src\Security.h
文件 16478 2010-02-09 16:25 C++-Wrapper\src\SocketSet.cpp
文件 10790 2010-02-09 16:24 C++-Wrapper\src\SocketSet.h
文件 9672 2010-02-10 12:25 C++-Wrapper\src\SynchSet.cpp
文件 8426 2010-02-10 11:42 C++-Wrapper\src\SynchSet.h
文件 18966 2010-02-10 13:52 C++-Wrapper\src\ThreadPool.h
文件 7958 2010-02-10 13:49 C++-Wrapper\src\TimerThreadPool.cpp
文件 27130 2010-02-10 13:44 C++-Wrapper\src\WorkThreadPool.cpp
目录 0 2010-01-04 10:13 C++-Wrapper\src
文件 250 2009-01-15 16:21 C++-Wrapper\test\Makefile.AS
文件 13472 2010-01-20 14:02 C++-Wrapper\test\TestAsynService.cpp
文件 2651 2009-05-12 13:27 C++-Wrapper\test\TestAsynService.h
目录 0 2010-01-19 17:21 C++-Wrapper\test
目录 0 2010-01-01 12:56 C++-Wrapper
----------- --------- ---------- ----- ----
296578 28
............此处省略1个文件信息
- 上一篇:车票班次管理系统C语言含报告
- 下一篇:C语言实现连连看游戏
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- LINUX下命令行界面的C语言细胞游戏
- 尚观培训linux许巍老师关于c语言的课
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- 《Linux程序设计》第四版pdf高清电子版
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- linux 0.11内核代码
- linux ac108多麦方案驱动(ac108.c)
- 共享内存 读写
- 简易web服务器的设计与实现
- 《LINUX C编程从初学到精通》光盘源码
- 嵌入式QtC++编程课件
评论
共有 条评论