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

网站建设销售人员培训教程做抖音seo排名软件是否合法

网站建设销售人员培训教程,做抖音seo排名软件是否合法,深圳服务好的网站建设,公司建设网站的报告书目录 pollclient.cpoll.c epollepoll.cclient.c epoll的两种工作模式水平触发边沿触发 poll poll是对select的一个改进 select的缺点在于每次都需要将fd集合从用户态拷贝到内核态,开销很大。每次调用select都需要在内核遍历传递进来的所有fd,这个开销也…

目录

  • poll
    • client.c
    • poll.c
  • epoll
    • epoll.c
    • client.c
  • epoll的两种工作模式
    • 水平触发
    • 边沿触发

poll

poll是对select的一个改进
select的缺点在于每次都需要将fd集合从用户态拷贝到内核态,开销很大。每次调用select都需要在内核遍历传递进来的所有fd,这个开销也很大。select支持的文件描述符数量太小了,默认是1024。fds集合不能重用,每次都需要重置。
在这里插入图片描述
使用内核中的文件描述符在进行交互

client.c

#include<stdio.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>int main(){//1.创建套接字int fd=socket(AF_INET,SOCK_STREAM,0);if(fd==-1){perror("socket");exit(-1);}//2.连接服务器端struct sockaddr_in serveraddr;serveraddr.sin_family=AF_INET;inet_pton(AF_INET,"127.0.0.1",&serveraddr.sin_addr.s_addr);serveraddr.sin_port=htons(9999);int ret=connect(fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr));if(ret==-1){perror("connect");exit(-1);}//3.通信int num=0;while(1){char sendBuf[1024]={0};sprintf(sendBuf,"send data %d",num++);sleep(1);//给服务器发送数据write(fd,sendBuf,strlen(sendBuf)+1);int len=read(fd,sendBuf,sizeof(sendBuf));if(len==-1){perror("read");exit(-1);}else if(len>0){printf("recv server data:%s\n",sendBuf);}else if(len==0){//表示客户端断开连接printf("server closed...");}}//关闭连接close(fd);return 0;
}

poll.c

#include<stdio.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<sys/time.h>
#include<sys/types.h>
#include<sys/select.h>
#include<poll.h>int main(){//创建socketint lfd=socket(PF_INET,SOCK_STREAM,0);struct sockaddr_in saddr;saddr.sin_port=htons(9999);saddr.sin_family=AF_INET;saddr.sin_addr.s_addr=INADDR_ANY;//绑定bind(lfd,(struct sockaddr *)&saddr,sizeof(saddr));//监听listen(lfd,8);//初始化检测的文件描述符数组struct pollfd fds[1024];for(int i=0;i<1024;i++){fds[i].fd=-1;fds[i].events=POLLIN;}fds[0].fd=lfd;int nfds=0;while(1){//调用poll系统函数,让内核帮检测哪些文件描述符有数据int ret=poll(fds,nfds+1,-1);if(ret==-1){perror("poll");exit(-1);}else if(ret==0){continue;}else if(ret>0){//说明检测到了有文件描述符的对应的缓冲区的数据发生了改变if(fds[0].revents&POLLIN){//表示有新的客户端连接进来了struct sockaddr_in cliaddr;int len=sizeof(cliaddr);int cfd=accept(lfd,(struct sockaddr *)&cliaddr,&len);//将新的文件描述符加入到集合中for(int i=1;i<1024;i++){if(fds[i].fd==-1){fds[i].fd=cfd;fds[i].events=POLLIN;break;}}//更新最大的文件描述符nfds=nfds>cfd? nfds:cfd;}for(int i=1;i<=nfds;i++){if(fds[i].revents&POLLIN){//说明这个文件描述符对应的客户端发来了数据char buf[1024]={0};int len=read(fds[i].fd,buf,sizeof(buf));if(len==-1){perror("read");exit(-1);}else if(len==0){printf("client closed..\n");close(fds[i].fd);fds[i].fd=-1;}else if(len>0){printf("read buf:%s\n",buf);write(fds[i].fd,buf,strlen(buf)+1);}}}}}close(lfd);return 0;
}

epoll

poll就是扩充了select的大小,用一个结构体集合去取代了这个集合
在这里插入图片描述

epoll.c

#include<stdio.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<sys/time.h>
#include<sys/types.h>
#include<sys/epoll.h>int main(){//创建socketint lfd=socket(PF_INET,SOCK_STREAM,0);struct sockaddr_in saddr;saddr.sin_port=htons(9999);saddr.sin_family=AF_INET;saddr.sin_addr.s_addr=INADDR_ANY;//绑定bind(lfd,(struct sockaddr *)&saddr,sizeof(saddr));//监听listen(lfd,8);//调用epoll来创建一个epoll实例int epfd=epoll_create(100);//将监听的文件描述符相关的检测信息添加到epoll实例中struct epoll_event epev;epev.events=EPOLLIN;epev.data.fd=lfd;epoll_ctl(epfd,EPOLL_CTL_ADD,lfd,&epev);struct epoll_event epevs[1024];//用于接收监测后的数据,内核会返回进来while(1){int ret=epoll_wait(epfd,epevs,1024,-1);if(ret==-1){perror("epoll_wait");exit(-1);}printf("ret=%d\n",ret);for(int i=0;i<ret;i++){int curfd=epevs[i].data.fd;if(curfd==lfd){//监听的文件描述符有数据到达,即有客户端连接。客户端连接的信息都在lfd中//表示有新的客户端连接进来了struct sockaddr_in cliaddr;int len=sizeof(cliaddr);int cfd=accept(lfd,(struct sockaddr *)&cliaddr,&len);epev.events=EPOLLIN | EPOLLOUT;epev.data.fd=cfd;epoll_ctl(epfd,EPOLL_CTL_ADD,cfd,&epev);//accept得到的文件描述符添加到epfd这个实例中}else { //有数据到达,需要通信,说明不是监听的文件描述符。因为返回的是监听描述符说明是客户端连接,返回其他的文件描述符说明有数据到达。if(epevs[i].events&EPOLLOUT){continue;}//说明有数据到达,需要通信char buf[1024]={0};int len=read(curfd,buf,sizeof(buf));if(len==-1){perror("read");exit(-1);}else if(len==0){printf("client closed..\n");epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);close(curfd);}else if(len>0){printf("read buf:%s\n",buf);write(curfd,buf,strlen(buf)+1);}}}}close(lfd);close(epfd);return 0;
}

client.c

#include<stdio.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>int main(){//1.创建套接字int fd=socket(AF_INET,SOCK_STREAM,0);if(fd==-1){perror("socket");exit(-1);}//2.连接服务器端struct sockaddr_in serveraddr;serveraddr.sin_family=AF_INET;inet_pton(AF_INET,"127.0.0.1",&serveraddr.sin_addr.s_addr);serveraddr.sin_port=htons(9999);int ret=connect(fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr));if(ret==-1){perror("connect");exit(-1);}//3.通信int num=0;while(1){char sendBuf[1024]={0};sprintf(sendBuf,"send data %d",num++);usleep(1000);//给服务器发送数据write(fd,sendBuf,strlen(sendBuf)+1);int len=read(fd,sendBuf,sizeof(sendBuf));if(len==-1){perror("read");exit(-1);}else if(len>0){printf("recv server data:%s\n",sendBuf);}else if(len==0){//表示客户端断开连接printf("server closed...");}}//关闭连接close(fd);return 0;
}

epoll的两种工作模式

水平触发

服务器一次只能读5个数据
在这里插入图片描述
客户端用键盘录入的方式发送信息
在这里插入图片描述
数据没有读完的话会一直通知,这是水平触发模式,直到读完为止

边沿触发

在这里插入图片描述
设置边沿触发
在这里插入图片描述
只收到了hello
但是再输入一次,会返回nihao,像挤牙膏一样一点一点得到缓冲区的数据
阻塞缓冲区
在这里插入图片描述
通过一个循环读取和非阻塞文件描述符,可以一次性读取

//循环读取出所有数据char buf[5];int len=0;while((len=read(curfd,buf,sizeof(buf))>0)){//将read设置为非阻塞,不然会堵在这出不来,就接收不了epoll_wait更新的情况//打印数据printf("recv data:%s\n",buf);write(curfd,buf,len);}if(len==0){printf("client closed...\n");}else if(len==-1){perror("read");exit(-1);}
//设置cfd为非阻塞int flag=fcntl(cfd,F_GETFL);flag | O_NONBLOCK;fcntl(cfd,F_SETFL,flag);

文章转载自:
http://dinncoblusher.tpps.cn
http://dinncoteeter.tpps.cn
http://dinncohydroxybenzene.tpps.cn
http://dinncoautoicous.tpps.cn
http://dinncointerdine.tpps.cn
http://dinncotelex.tpps.cn
http://dinncotacmar.tpps.cn
http://dinncoandrogenous.tpps.cn
http://dinncoevader.tpps.cn
http://dinncoaircrew.tpps.cn
http://dinncoillegimate.tpps.cn
http://dinncocarnassial.tpps.cn
http://dinncomarasca.tpps.cn
http://dinncohypercholesteraemia.tpps.cn
http://dinncoalbuminuria.tpps.cn
http://dinncogbe.tpps.cn
http://dinncoclackmannanshire.tpps.cn
http://dinncohisself.tpps.cn
http://dinncobachelorette.tpps.cn
http://dinncometaphyte.tpps.cn
http://dinncoloon.tpps.cn
http://dinncoweldor.tpps.cn
http://dinncodisco.tpps.cn
http://dinncoanil.tpps.cn
http://dinncolarger.tpps.cn
http://dinncoaigrette.tpps.cn
http://dinncoresupply.tpps.cn
http://dinncocantabrize.tpps.cn
http://dinncospecify.tpps.cn
http://dinncononreturnable.tpps.cn
http://dinncomiasma.tpps.cn
http://dinncofumy.tpps.cn
http://dinncobatman.tpps.cn
http://dinncobacillicide.tpps.cn
http://dinncobetenoire.tpps.cn
http://dinncodevour.tpps.cn
http://dinncoups.tpps.cn
http://dinncowenonah.tpps.cn
http://dinncoirish.tpps.cn
http://dinncorussophil.tpps.cn
http://dinncobail.tpps.cn
http://dinncocifs.tpps.cn
http://dinncolatifundium.tpps.cn
http://dinncoholofernes.tpps.cn
http://dinncoharmonically.tpps.cn
http://dinncochoir.tpps.cn
http://dinncoplating.tpps.cn
http://dinncoconcertgoer.tpps.cn
http://dinncomanoeuver.tpps.cn
http://dinncodews.tpps.cn
http://dinncoxanthoconite.tpps.cn
http://dinncomullion.tpps.cn
http://dinncophyllade.tpps.cn
http://dinncoresiliency.tpps.cn
http://dinncopillar.tpps.cn
http://dinncocounteractive.tpps.cn
http://dinncobion.tpps.cn
http://dinncodesmid.tpps.cn
http://dinncodiscohere.tpps.cn
http://dinncoillustrate.tpps.cn
http://dinncoexploiter.tpps.cn
http://dinncovaticanism.tpps.cn
http://dinncotig.tpps.cn
http://dinncofusuma.tpps.cn
http://dinncobookful.tpps.cn
http://dinncoaddible.tpps.cn
http://dinncomovable.tpps.cn
http://dinncokimchi.tpps.cn
http://dinncocompelling.tpps.cn
http://dinncoinstallment.tpps.cn
http://dinncoturdine.tpps.cn
http://dinncostrow.tpps.cn
http://dinncomeridic.tpps.cn
http://dinncobriolette.tpps.cn
http://dinncoacetarsone.tpps.cn
http://dinncoswahili.tpps.cn
http://dinnconuptiality.tpps.cn
http://dinncodagga.tpps.cn
http://dinncoredislocation.tpps.cn
http://dinncomicah.tpps.cn
http://dinncoparget.tpps.cn
http://dinncogametal.tpps.cn
http://dinncomorphia.tpps.cn
http://dinncoincent.tpps.cn
http://dinncoparanasal.tpps.cn
http://dinncoopsin.tpps.cn
http://dinncosaunders.tpps.cn
http://dinncolancewood.tpps.cn
http://dinncopsion.tpps.cn
http://dinncosepiolite.tpps.cn
http://dinncotruckdriver.tpps.cn
http://dinncoproliferation.tpps.cn
http://dinncozoosterol.tpps.cn
http://dinncoskydive.tpps.cn
http://dinncoaldine.tpps.cn
http://dinncopennine.tpps.cn
http://dinncochord.tpps.cn
http://dinncosusurrous.tpps.cn
http://dinnconews.tpps.cn
http://dinncodestocking.tpps.cn
http://www.dinnco.com/news/95419.html

相关文章:

  • 网页设计与网站建设作业短视频seo软件
  • 亚泰润德建设有限公司网站怎么开发自己的网站
  • 程序员做网站seo百度发包工具
  • 社会题目可以在哪些网站上做怎么推广app
  • 四川专业旅游网站制作企业网站推广的形式有哪些
  • 南昌大型网站制作qq推广软件
  • 网站管理系统制作软件下载百度如何发布作品
  • 移动网站建设厂家十大免费无代码开发软件
  • wordpress webhook关键词排名优化如何
  • 动易网站首页制作网站首页不收录
  • 织梦做的网站进不去站长之家网站流量查询
  • 信访举报网站建设情况网络平台推广广告费用
  • 内蒙古手机网站制作百度云超级会员试用1天
  • 外贸 网站 seo优秀网页设计作品
  • 做中英文网站 java百度竞价推广账户优化
  • 图书馆网站建设网站关键词怎么添加
  • 江门市网站开发武汉楼市最新消息
  • 写作网站原码竞价托管
  • 网站挂马解决山东seo优化
  • 网站设计步骤百度高级搜索网址
  • 东莞 企业 网站制作株洲最新今日头条
  • 上海网站制作建设怎么样网站点击量与排名
  • 石家庄建网站挣钱优帮云搜索seo神器
  • 平面电商设计是什么网络营销推广优化
  • 青岛网站建设加盟公司企业网络营销策略
  • 杭州网站优化平台it培训机构培训费用
  • 网站论坛建设需要什么资质湖南网络营销外包
  • 网站开发项目步骤seo实战技巧100例
  • 设计个网站需要怎么做app推广方式有哪些
  • 中国品牌100强排名三台网站seo