当前位置: 首页 > news >正文

网站建设操作可行性分析百度代理公司查询

网站建设操作可行性分析,百度代理公司查询,自己用电脑做网站服务器,辽源网站优化1.框架图 被称为当前时代最好用的io多路复用方式; 核心操作:一棵树(红黑树)、一张表(内核链表)以及三个接口; 思想:(fd代表文件描述符) epoll要把检测的事件…

1.框架图

被称为当前时代最好用的io多路复用方式;

核心操作:一棵树(红黑树)、一张表(内核链表)以及三个接口;

 思想:(fd代表文件描述符)

        epoll要把检测的事件fd挂载到内核空间红黑树上,遍历红黑树,调用每个fd对应的操作方法,找到发生事件的fd,如果没有发生事件的fd,进程休眠,如果事件发生,将发生事件的fd拷贝一份放到内核链表,每个节点对应一个fd,最后把链表的节点信息传递到用户空间的数组中,用户空间无需判断事件的发生,需要判断事件类型(读写等);

 

2.代码

---pro1.c---应用程序(epoll方式)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/epoll.h>int main(int argc, const char *argv[])
{int fd1,fd2,epfd;char buf[128] = {0};struct epoll_event event;  //用于操作epollstruct epoll_event events[10];  //用户空间存放发生事件的数组//创建epoll句柄,红黑树根节点epfd = epoll_create(1);if(epfd < 0){printf("epoll_create fail\n");exit(-1);}//打开设备文件fd1 = open("/dev/input/mouse0", O_RDWR);if (fd1 < 0){printf("鼠标事件文件失败\n");exit(-1);}fd2 = open("/dev/myled0", O_RDWR);if (fd2 < 0){printf("自定义事件文件失败\n");exit(-1);}//添加准备就绪事件到epollevent.events = EPOLLIN;  //读事件event.data.fd = fd1;if((epoll_ctl(epfd,EPOLL_CTL_ADD,fd1,&event)) < 0){printf("epoll_ctl fd1 fail\n");}event.events = EPOLLIN;  //读事件event.data.fd = fd2;if((epoll_ctl(epfd,EPOLL_CTL_ADD,fd2,&event)) < 0){printf("epoll_ctl fd2 fail\n");}//监听时间是否发生while(1){//成功接收返回时间的个数,放入events数组中int ret = epoll_wait(epfd,events,10,-1);if(ret < 0){printf("epoll_wait fail\n");exit(-1);   }int i;//循环遍历数组,做事件的处理for(i=0; i<ret; i++){if(events[i].events & EPOLLIN)  //发生事件是读事件{read(events[i].data.fd,buf,sizeof(buf));printf("buf:%s\n",buf);memset(buf,0,sizeof(buf));}}}close(fd1);close(fd2);return 0;
}
---pro2.c---应用程序(模拟自定义设备数据就绪)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>int main(int argc, const char *argv[])
{char buf[128] = "hello world";int fd = open("/dev/myled0", O_RDWR);if (fd < 0){printf("打开设备文件失败\n");exit(-1);}write(fd, buf, sizeof(buf));close(fd);return 0;
}
---epoll.c---驱动程序

 

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include<linux/poll.h>char kbuf[128] = {0};
unsigned int major;
struct class *cls;
struct device *dev;
unsigned int condition = 0;// 定义一个等待队列头
wait_queue_head_t wq_head;// 封装操作方法
int mycdev_open(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}ssize_t mycdev_read(struct file *file, char *ubuf, size_t size, loff_t *lof)
{int ret;ret = copy_to_user(ubuf, kbuf, size);if (ret){printk("copy_to_ user err\n");return -EIO;}condition = 0; // 下一次硬件数据没有就绪return 0;
}
ssize_t mycdev_write(struct file *file, const char *ubuf, size_t size, loff_t *lof)
{int ret;// 从用户拷贝数据,模拟硬件数据ret = copy_from_user(kbuf, ubuf, size);if (ret){printk("copy_from_user err\n");return -EIO;}condition = 1;wake_up_interruptible(&wq_head);return 0;
}
//封装POLL方法
__poll_t mycdev_poll(struct file *file, struct poll_table_struct *wait)
{__poll_t mask = 0;//向上提交等待队列头poll_wait(file,&wq_head,wait);//根据事件是否发生给一个合适的返回值if(condition){mask = POLLIN;}return mask;
}
int mycdev_close(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}struct file_operations fops = {.open = mycdev_open,.read = mycdev_read,.poll = mycdev_poll,.write = mycdev_write,.release = mycdev_close,
};// 入口函数
static int __init mycdev_init(void)
{//初始化等待队列init_waitqueue_head(&wq_head);major = register_chrdev(0, "myled", &fops);if (major < 0){printk("字符设备驱动注册失败\n");return major;}printk("字符设备驱动注册成功:major=%d\n", major);// 向上提交目录cls = class_create(THIS_MODULE, "MYLED");if (IS_ERR(cls)){printk("向上提交目录失败\n");return -PTR_ERR(cls);}printk("向上提交目录成功\n");// 向上提交设备节点信息int i;for (i = 0; i < 3; i++){dev = device_create(cls, NULL, MKDEV(major, i), NULL, "myled%d", i);if (IS_ERR(dev)){printk("向上提交设备节点信息失败\n");return -PTR_ERR(dev);}}printk("向上提交设备节点信息成功\n");return 0;
}// 出口函数
static void __exit mycdev_exit(void)
{// 销毁设备节点信息int i;for (i = 0; i < 3; i++){device_destroy(cls, MKDEV(major, i));}// 销毁目录信息class_destroy(cls);// 字符设备驱动注销unregister_chrdev(major, "myled");
}// 声明
// 入口函数地址
module_init(mycdev_init);
// 出口函数地址
module_exit(mycdev_exit);
// 遵循的GPL协议
MODULE_LICENSE("GPL");

 

3.测试结果

 执行pro2.c,自定义事件被监听到;

 在ubuntu上动鼠标,鼠标事件被监听;

http://www.mmbaike.com/news/41633.html

相关文章:

  • 大良网站设计百度电脑版网页
  • 木樨园网站建设公司郑州技术支持seo
  • 南平网站建设百度网站大全首页
  • 网站做gzip压缩网站运营主要做什么工作
  • 网站建设资料准备标准电商网站有哪些
  • wordpress hueman关键词优化是什么意思?
  • 济南优化网站技术品牌广告和效果广告的区别
  • 佛山网站代运营准度科技有限公司推广网络营销外包公司
  • 移动网站建站系统云浮网站设计
  • 食品包装设计说明seo网站优化流程
  • 网站空间不够用百度刷排名优化软件
  • 现在有人还做网站吗seo优化是怎么回事呢
  • 网站可以做二维码导航一个新产品怎么推广
  • 同性男做的视频网站百度搜索推广登录入口
  • 企业信息查询表去哪里查资阳地seo
  • 网站专题报道怎么做百度seo指南
  • 贵州网站建设推荐广州网站优化价格
  • php建网站西安的网络优化公司
  • 做网站网上怎么挂公告自己搭建网站
  • 网站开发 案例百度论坛
  • 孟村县网站建设深圳营销型网站建设
  • 做的网站名合肥网络推广有限公司
  • 怎么自己做三个一网站百度账号快速注册入口
  • 山西太原发现1例阳性淘宝网站的推广与优化
  • 无做弊的棋牌游戏网站网上销售平台怎么做
  • php网站建设带数据库模板百度指数需求图谱
  • 英文互动网站建设各网站收录
  • 网易企业邮箱后缀是多少淄博搜索引擎优化
  • 重庆市工程建设标准化网站中国广告网
  • 音乐网站开发毕业论文seo优化的作用