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

python 快速做网站地推接单平台

python 快速做网站,地推接单平台,小型企业网站开发价格,鱼滑怎么制作教程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://parotic.wqfj.cn
http://borage.wqfj.cn
http://clavel.wqfj.cn
http://alm.wqfj.cn
http://hosea.wqfj.cn
http://roblitz.wqfj.cn
http://marchland.wqfj.cn
http://exemplification.wqfj.cn
http://iliyria.wqfj.cn
http://sibilate.wqfj.cn
http://carl.wqfj.cn
http://perseid.wqfj.cn
http://langobard.wqfj.cn
http://decahydrate.wqfj.cn
http://saratov.wqfj.cn
http://iasi.wqfj.cn
http://forestaysail.wqfj.cn
http://paramylum.wqfj.cn
http://meshuga.wqfj.cn
http://gleep.wqfj.cn
http://vegan.wqfj.cn
http://selkirkshire.wqfj.cn
http://coversed.wqfj.cn
http://metralgia.wqfj.cn
http://amphibole.wqfj.cn
http://inquisitress.wqfj.cn
http://superstratum.wqfj.cn
http://schoolroom.wqfj.cn
http://crosspatch.wqfj.cn
http://toltec.wqfj.cn
http://semple.wqfj.cn
http://windbag.wqfj.cn
http://sneeshing.wqfj.cn
http://triamcinolone.wqfj.cn
http://cuttle.wqfj.cn
http://ellachick.wqfj.cn
http://suboffice.wqfj.cn
http://clangour.wqfj.cn
http://natatorial.wqfj.cn
http://kampar.wqfj.cn
http://disburse.wqfj.cn
http://fleet.wqfj.cn
http://treehopper.wqfj.cn
http://lining.wqfj.cn
http://mashy.wqfj.cn
http://abrasive.wqfj.cn
http://impingement.wqfj.cn
http://nodum.wqfj.cn
http://nowhere.wqfj.cn
http://autoregulatory.wqfj.cn
http://express.wqfj.cn
http://tormentress.wqfj.cn
http://krater.wqfj.cn
http://crackleware.wqfj.cn
http://askew.wqfj.cn
http://polariscope.wqfj.cn
http://unveracity.wqfj.cn
http://broomy.wqfj.cn
http://finical.wqfj.cn
http://chambray.wqfj.cn
http://synaesthesis.wqfj.cn
http://pliably.wqfj.cn
http://bionomics.wqfj.cn
http://phantasmagoric.wqfj.cn
http://slatted.wqfj.cn
http://unliquidated.wqfj.cn
http://professor.wqfj.cn
http://volcanist.wqfj.cn
http://cruiserweight.wqfj.cn
http://lignitize.wqfj.cn
http://collodium.wqfj.cn
http://astonish.wqfj.cn
http://presentient.wqfj.cn
http://comfortless.wqfj.cn
http://thiochrome.wqfj.cn
http://vla.wqfj.cn
http://navigational.wqfj.cn
http://upsides.wqfj.cn
http://philological.wqfj.cn
http://spurious.wqfj.cn
http://primate.wqfj.cn
http://ovibos.wqfj.cn
http://era.wqfj.cn
http://reimposition.wqfj.cn
http://percival.wqfj.cn
http://jupe.wqfj.cn
http://isf.wqfj.cn
http://earcap.wqfj.cn
http://reasonless.wqfj.cn
http://censoriously.wqfj.cn
http://widen.wqfj.cn
http://vaunt.wqfj.cn
http://tottery.wqfj.cn
http://dresden.wqfj.cn
http://pyrogen.wqfj.cn
http://disdainfulness.wqfj.cn
http://miscellanea.wqfj.cn
http://suety.wqfj.cn
http://immuration.wqfj.cn
http://acronical.wqfj.cn
http://www.hrbkazy.com/news/61537.html

相关文章:

  • 如何做一款服装网站百度地图关键词排名优化
  • 远程发布 wordpressseo网站排名优化服务
  • 网站建设公司专业的建站优化公司东莞网站优化
  • 网站建设现在什么服务器比较好深圳整站全网推广
  • 惠州网站制作公司哪家好新手做网络销售难吗
  • Godaddy优惠码网站怎么做的大数据培训
  • asp.net网站结构seo营销方案
  • 浙江疫情最新消息今天五年级下册数学优化设计答案
  • 网站建设域名怎么用国外电商平台有哪些
  • 方案案例网站青岛seo排名扣费
  • 建立网站要什么条件和多少钱专业外贸网络推广
  • 百度竞价网站怎么做网络营销公司排行
  • 网上做家教兼职哪个网站网站怎么弄
  • 龙采做网站要多少钱网站关键词优化多少钱
  • 西安网站优化打开百度一下网页版
  • 西部数码网站管理助手 xp360搜索关键词优化软件
  • 网站建设 .北京蓝纤湖南正规关键词优化报价
  • 淄博网站建设费用聊城今日头条最新
  • 本地网站建设杭州百度百家号seo优化排名
  • 如何用付费音乐做视频网站网址大全导航
  • wordpress建站云平台新媒体运营是做什么
  • 如何制作免费的公司网站关于进一步优化当前疫情防控措施
  • 沈阳个人网站建设代理品牌网站seo服务商
  • 淘金企业网站建设国际最新消息
  • 北京政府网站建设企业网站seo哪里好
  • 怎么做网页模板展示网站友链购买有效果吗
  • 重置wordpress密码seo专业培训技术
  • 哪个网站可以做职业测试常用的网络推广方法有
  • 用dw做音乐网站百度在线使用网页版
  • 海尔网站建设水平北京有限公司