资源简介
FIFO配合管道PIPE,实现FIFO传递数据,PIPE触发epoll,异步IO效果
代码片段和文件信息
#include “stdafx.h“
#include
#include
#include “fifo.h“
static int sl_fifo_Cnt = 0;
C_fifo::C_fifo()
{
m_Capacity = 0;
m_NodeSize = 0;
m_Fd = -1;
m_Head = NULL;
m_Tail = NULL;
m_p_NodeList = NULL;
m_p_pipe = NULL;
m_Node.p_next = NULL;
m_Node.p_data = NULL;
m_Node.v_size = 0;
}
C_fifo::~C_fifo()
{
uninit();
if (NULL != m_p_pipe)
{
delete m_p_pipe;
m_p_pipe = NULL;
}
}
int C_fifo::init(unsigned int vp_MaxNode unsigned int vp_NodeSize const char* pp_PipeName)
{
char al_fifoname[64];
char* pl_fifoname = NULL;
unsigned int i;
unsigned int vl_OldCapacity;
vl_OldCapacity = m_Capacity;
m_Capacity = vp_MaxNode;
m_NodeSize = vp_NodeSize;
m_Fd = 0;
if(NULL != m_p_NodeList)
{
for (i = 0; i < vl_OldCapacity + 1; i++)
{
if(NULL != m_p_NodeList[i].p_data)
{
delete m_p_NodeList[i].p_data;
}
}
delete m_p_NodeList;
m_p_NodeList = NULL;
}
if(NULL != m_Node.p_data)
{
delete m_Node.p_data;
m_Node.p_data = NULL;
}
m_p_NodeList = new FifoNode[m_Capacity + 1];
if (NULL == m_p_NodeList)
{
printf(“new fifo node fail\n“);
return -1;
}
for (i = 0; i < m_Capacity + 1; i++)
{
m_p_NodeList[i].v_size = 0;
m_p_NodeList[i].p_data = ( char* )new char[m_NodeSize];
if (NULL == m_p_NodeList[i].p_data)
{
printf(“new fifo node data fail\n“);
return -1;
}
if (i < m_Capacity)
{
m_p_NodeList[i].p_next = &m_p_NodeList[i + 1];
}
else
{
m_p_NodeList[m_Capacity].p_next = &m_p_NodeList[0];
}
}
m_Node.p_data = ( char* )new char[m_NodeSize];
if (NULL == m_Node.p_data)
{
printf(“new fifo data node fail\n“);
return -1;
}
m_Head = &m_p_NodeList[0];
m_Tail = &m_p_NodeList[0];
if (NULL == pp_PipeName)
{
sprintf(al_fifoname “/tmp/fifo%d“ sl_fifo_Cnt);
pl_fifoname = al_fifoname;
}
else
{
pl_fifoname = (char*)pp_PipeName;
}
m_p_pipe = new C_pipe(pl_fifoname);
if (NULL == m_p_pipe)
{
printf(“new pipe fail\n“);
return -1;
}
return 0;
}
int C_fifo::uninit()
{
unsigned int i;
for (i = 0; i < m_Capacity + 1; i++)
{
if (m_p_NodeList != NULL)
{
if (m_p_NodeList[i].p_data != NULL)
{
delete m_p_NodeList[i].p_data;
m_p_NodeList[i].p_data = NULL;
}
}
}
if (m_p_NodeList != NULL)
{
delete m_p_NodeList;
m_p_NodeList = NULL;
}
if (m_Node.p_data != NULL)
{
delete m_Node.p_data;
m_Node.p_data = NULL;
}
m_Capacity = 0;
m_NodeSize = 0;
m_Head = NULL;
m_Tail = NULL;
return 0;
}
void C_fifo::print_node()
{
unsigned int i = 0;
printf(“---node: %p---\n“ m_p_NodeList);
printf(“---pipe: %p---\n“ m_p_pipe);
if (NULL != m_p_NodeList)
{
for (i = 0; i < m_Capacity + 1; i++)
{
//printf(“node[%d]: %p “ i m_p_NodeList[i].p_data);
}
}
}
int C_fifo::get_fd()
{
int vl_ret = -1;
if (NULL != m_p_p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6968 2016-10-09 14:37 fifo\fifo.cpp
文件 1050 2016-03-31 18:32 fifo\fifo.h
文件 2688 2016-10-09 14:37 fifo\pipe.cpp
文件 956 2016-10-09 14:37 fifo\pipe.h
目录 0 2016-10-09 14:37 fifo
----------- --------- ---------- ----- ----
11662 5
- 上一篇:OAF 客户化开发之FTP服务器文件开发
- 下一篇:组态王工程-PID控件例程
相关资源
- 操作系统 课程设计 页面置换算法FI
- OV7670+FIFO
- 先进先出FIFO页面置换算法
- 异步FIFO IP核
- FIFO代码以及对应的testbench
- FIFO基本原理及verilog代码
- STM32 IIC 状态机 DMA 控制MPU60x0和burst读
- 异步fifo跨时钟域处理
- DDR/DDR2接口的FIFO设计
- FIFO 乒乓操作 低速到高速
- Linux + C + Epoll实现高并发服务器(线程
- FPGA VHDL FIFO 源代码
- VHDL -FIFO
- SCI串口通信例程 FIFO+中断
- ov7670摄像头模块不带fifo用stm32f207实现
- 先进先出84位FIFO存储器设计课设及源
- epoll服务器、客户端模型
- FT2232H 中文手册 480Mb/s 双通道USB FIF
- STM32进阶之串口环形缓冲区实现 FIF
- DSP320F28035的SCI驱动源码,详细注释
- libevent for qt网络模块直接替换qt的se
- Verilog实现的异步FIFO
- fifo读写的verilog代码
- 异步FIFO Verilog源码与testbench
- 同步FIFO代码和testbench
- epoll封装与测试代码
- 操作系统实训——模拟页面置换OPT、
- 页面置换算法FIFO LRU OPT
- 操作系统 程实现请求分页存储管理页
评论
共有 条评论