select 应用,加入队列
来源:互联网 发布:北京租房软件 编辑:程序博客网 时间:2024/06/05 06:39
#include "listenhtmldata_thread.h"
#include "listenhtmldata_thread.h"
#include <QDebug>
#include <stdio.h>
#include <malloc.h>
#include "string.h"
#include "queue.h"
Queue *queue_headpointer;//定义顺序栈的指针
#define HtmlSetParaDataFIFO "/web/HtmlSetParaDataFIFO" //html data ,write to FIFO
int htmldatafifo_fd=0;
#define QUEUESTRSIZE 512//
listenHtmldata_thread::listenHtmldata_thread()
{
//#define HtmlSetParaDataFIFO"/web/HtmlSetParaDataFIFO"//html data ,write to FIFO
unlink(HtmlSetParaDataFIFO);//delelte fifo
mkfifo(HtmlSetParaDataFIFO,0666);//creat fifo
htmldatafifo_fd=::open(HtmlSetParaDataFIFO,O_RDONLY|O_NONBLOCK ,0);//O_RDONLY,O_WRONLY,O_NONBLOCK
if(htmldatafifo_fd<0)
{
// perror("open fifo error");
qDebug()<<"open fifo error";
//exit(1);
return ;
}
else
qDebug()<<"open fifo success**********************************";
queue_headpointer=(Queue*)malloc(sizeof(Queue));
if(queue_headpointer==NULL)
printf("malloc memeory is faiure!\n");
// printf("Test the Queue is or is not good ?\n press 'q' is quit\n");
InitQueue(queue_headpointer);
printf("InitQueue over\n");
if(EmptyQueue(queue_headpointer))
printf("the Queue is empty\n");
else
printf("the Queue is not empty\n");
}
void listenHtmldata_thread::run()
{
char item[QUEUESTRSIZE];//=line.toLatin1().data();
int nread=0;
printf("\n listenHtmldata_thread listenHtmldata_thread::run() ------......\n");
memset(item,0,sizeof(item));
while(1)
{
fd_set rset;
FD_ZERO(&rset);
FD_SET(htmldatafifo_fd,&rset);
struct timeval tv;
tv.tv_sec=5;//5s
tv.tv_usec=0;
int ret=0;
// memset(item,NULL,sizeof(item));in main not is null
qDebug()<<"select go**********************************************";
ret=select(htmldatafifo_fd+1,&rset,NULL,NULL,&tv);
qDebug()<<"select end**********************************************";
if(ret<0)
{
// perror("select error");
qDebug()<<"select error**********************************************";
//return ;
}
else if(ret==0)
{
qDebug()<<"select time out**********************************************";
//return ;
}
else if(FD_ISSET(htmldatafifo_fd,&rset))//fd is ready
{
if((nread=read(htmldatafifo_fd,item,sizeof(item)))==-1)
{
if(errno==EAGAIN)
{
printf("THE fifo has not data yet.please try again later\n");
}
}
else //success read from fifo
{
qDebug()<<"nread is "<<nread;
//PUSH QUEUE
printf("read fifo data is %s\n",item);
//read fifo data is Sv=40&P=15&Ti=3&Td=0.0&Tf=0.0&Gate=0.0&delay=0.0&group1=remote&group2=manualset&Submit=%CC%E1%BD%BB
qDebug()<<"the item PUSH to the Queue :\n";
EnterQueue(item,queue_headpointer);
}
//OutQueue
qDebug()<<"the item POP from the Queue :\n";
while(!EmptyQueue(queue_headpointer))
{
OutQueue(item,queue_headpointer);
send_htmldata_signal(item);
}
}
sleep(1);
}
}
- select 应用,加入队列
- update中加入select
- 打卡加入研究队列
- json数据加入 select 中
- select 应用
- select 应用
- 加入app应用
- 队列应用
- update中加入select 完成查询更新
- html的select加入可输入文本
- DECLARE_WAITQUEUE 将进程加入等待队列
- DECLARE_WAITQUEUE 将进程加入等待队列
- android 应用中加入cnzz
- Yii2加入新的应用
- linux工作队列 - 把work_struct加入工作队列
- select的应用
- select模型应用
- select模型的应用
- c plus plus socket 编程
- rails Eager loading
- SQLite清空表并将自增列归零
- android json解析及简单例子
- 嵌入式软件工程师应该具备怎么样的素质
- select 应用,加入队列
- xml中的约束
- Ehcache详细解读
- Android intent
- 高手分享:巧设提高U盘数据传输速度——系统收藏
- 福州大学第十届校赛 & fzu 2127养鸡场
- Android MediaPlayer的生命周期
- 经典的20道AJAX面试题
- 每日一题(8) - 求链表的中间结点