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

wordpress主题美化seo优化广告

wordpress主题美化,seo优化广告,wordpress 建站 教程视频,网站这么做优化● 应用程序中同时处理多路输入输出流,若采用阻塞模式,得不到预期的目的; ● 若采用非阻塞模式,对多个输入进行轮询,但又太浪费CPU时间; ● 若设置多个进程/线程,分别处理一条数据通路&#xff…

● 应用程序中同时处理多路输入输出流,若采用阻塞模式,得不到预期的目的;

若采用非阻塞模式,对多个输入进行轮询,但又太浪费CPU时间;

若设置多个进程/线程,分别处理一条数据通路,将新产生进程/线程间的同步与通信问题,使程序变得更加复杂;

比较好的方法是使用I/O多路复用技术

其(select)基本思想是:

先构造一张有关描述符的表(最大1024),然后调用一个函数。

当这些文件描述符中的一个或多个已准备好进行I/O时函数才返回。

函数返回时告诉进程哪个描述符已就绪,可以进行I/O操作。

用select创建并发服务器,可以与多个客户端进行通信(监听键盘、socket、多个acceptfd)

循环服务器一个客户端可以连接多个客户但是不能同时

并发服务器一个服务器可以同时处理多个客户端的请求

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string.h>// tcp服务器一共有两种文件描述符,一类用于连接,一类用于通信
int main(int argc, char const *argv[])
{char buf[128];int ret;if (argc != 2){printf("usage:%s <端口号>\n", argv[0]);return -1;}// 1.创建套接字(socket)// socket函数返回值:用于连接的文件描述符int sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("socket err");return -1;}printf("sockfd:%d\n", sockfd);// 2. 指定网络信息struct sockaddr_in saddr, caddr;saddr.sin_family = AF_INET;            // IPV4saddr.sin_port = htons(atoi(argv[1])); // 端口号// saddr.sin_addr.s_addr = inet_addr("0.0.0.0"); // 虚拟机IP地址(自动获取)saddr.sin_addr.s_addr = INADDR_ANY; // 虚拟机IP地址// INADDR_ANY是一个常量,它指代的是一个特殊的IP地址,即0.0.0.0// 在网络编程中,当一个进程需要绑定一个网络端口时,可以使用INADDR_ANY来指定该端口可以接受来自任何IP地址的连接请求int len = sizeof(caddr);// 3.绑定套接字(bind)if (bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0){perror("bind err");return -1;}printf("bind ok\n");// 4.监听套接字(listen)if (listen(sockfd, 6) < 0){perror("listen err");return -1;}printf("listen ok\n");//******************************************************************//// 1)构造一张关于文件描述符的表fd_set rfds, tempfds;int maxfd;// 2)清空表 FD_ZEROFD_ZERO(&rfds);FD_ZERO(&tempfds);// 3)将关心的文件描述符添加到表中 FD_SETFD_SET(sockfd, &rfds);FD_SET(0, &rfds);maxfd = sockfd;while (1){// 将原来的表复制给新表tempfds = rfds;struct timeval tm = {1, 0}; // 超时检测// 4)调用select函数,监听 selectret = select(maxfd + 1, &tempfds, NULL, NULL, 0);if (ret < 0){perror("select err");return -1;}else if(ret==0){printf("time out\n");}// 5)判断到底是哪一个或者是哪些文件描述符发生了事件 FD_ISSETif (FD_ISSET(0, &tempfds)){fgets(buf, sizeof(buf), stdin);printf("keybroad:%s\n", buf);}if (FD_ISSET(sockfd, &tempfds)){// 5.接受客户端连接请求(accept)// accept函数返回值:用于通信的文件描述符int acceptfd = accept(sockfd, (struct sockaddr *)&caddr, &len);if (acceptfd < 0){perror("accpet err");return -1;}printf("port:%d ip:%s\n", ntohs(caddr.sin_port), inet_ntoa(caddr.sin_addr));printf("accpetfd:%d\n", acceptfd);// 将用于通信的文件描述符加入表中FD_SET(acceptfd, &rfds);if (acceptfd > maxfd)maxfd = acceptfd;}for (int i = sockfd + 1; i <= maxfd; i++) // 循环判断哪些文件描述符发生响应{if (FD_ISSET(i, &tempfds)){// 6. 接收,发送数据(recv,send)ret = recv(i, buf, sizeof(buf), 0);if (ret < 0){perror("recv err");break;}else if (ret == 0){printf("client %d exit\n", i);close(i);         // 关闭退出的客户端文件描述符FD_CLR(i, &rfds); // 将关闭的文件描述符从表中删除while (!FD_ISSET(maxfd, &rfds))maxfd--;}else{printf("client %d: %s\n", i, buf);memset(buf, 0, sizeof(buf));}}}}//*****************************************************************//// 7.关闭套接字(close)close(sockfd);return 0;
}

使用poll实现client的收发功能

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string.h>
#include <poll.h>
int main(int argc, char const *argv[])
{char buf[128];if (argc != 3){printf("usage:%s <IP地址> <端口号>\n", argv[0]);return -1;}// 1.创建套接字(socket)int sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("socket err");return -1;}printf("sockfd:%d\n", sockfd);// 2.指定(服务器)网络信息struct sockaddr_in saddr;saddr.sin_family = AF_INET;                 // IPV4saddr.sin_port = htons(atoi(argv[2]));      // 端口号saddr.sin_addr.s_addr = inet_addr(argv[1]); // 虚拟机IP地址// 3.连接(connect)if (connect(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0){perror("connect err");return -1;}printf("connect ok\n");// 4.接收发送消息(recv send)//************************************************************//// 1)创建结构体数组struct pollfd fds[2];// 2)将关心的文件描述符添加到数组中,并赋予事件fds[0].fd = 0;          // 键盘fds[0].events = POLLIN; // 想要发生的事件fds[1].fd = sockfd;     // 套接字fds[1].events = POLLIN; // 想要发生的事件// 3)保存数组内最后一个有效元素的下标int last = 1;// 4)调用poll函数,监听while (1){int ret = poll(fds, last + 1, 0);if (ret < 0){perror("poll err");return -1;}// 5)判断结构体内文件描述符实际触发的事件if (fds[0].revents == POLLIN){// 6)根据不同文件描述符触发的不同事件做对应的逻辑处理fgets(buf, sizeof(buf), stdin);// printf("keybroad:%s\n", buf);send(sockfd, buf, sizeof(buf), 0);if (strcmp(buf, "quit\n") == 0)break;}if (fds[1].revents == POLLIN){recv(sockfd, buf, sizeof(buf), 0);printf("buf:%s\n", buf);}memset(buf, 0, sizeof(buf));}//************************************************************//// 5.关闭套接字(close)close(sockfd);return 0;
}

文章转载自:
http://dinncoworkgroup.tpps.cn
http://dinncobioplasma.tpps.cn
http://dinncosquareface.tpps.cn
http://dinncofaucal.tpps.cn
http://dinncorespirate.tpps.cn
http://dinncoseismological.tpps.cn
http://dinncobunghole.tpps.cn
http://dinncorazor.tpps.cn
http://dinncomomentous.tpps.cn
http://dinncomilligram.tpps.cn
http://dinncospironolactone.tpps.cn
http://dinncocupreous.tpps.cn
http://dinncocopyread.tpps.cn
http://dinncogoogol.tpps.cn
http://dinncofleche.tpps.cn
http://dinncodaff.tpps.cn
http://dinncorobbery.tpps.cn
http://dinncosynovectomy.tpps.cn
http://dinncorepealer.tpps.cn
http://dinncogibing.tpps.cn
http://dinncosinaitic.tpps.cn
http://dinncosynchronize.tpps.cn
http://dinncofunctionalist.tpps.cn
http://dinncoyawn.tpps.cn
http://dinncooestrus.tpps.cn
http://dinncosesquicarbonate.tpps.cn
http://dinncopus.tpps.cn
http://dinncointercut.tpps.cn
http://dinncoretiring.tpps.cn
http://dinncowiseass.tpps.cn
http://dinncoemt.tpps.cn
http://dinncovirginis.tpps.cn
http://dinncoblameful.tpps.cn
http://dinncointerstate.tpps.cn
http://dinncoillness.tpps.cn
http://dinncovive.tpps.cn
http://dinncohachure.tpps.cn
http://dinncodav.tpps.cn
http://dinncocymophane.tpps.cn
http://dinncotori.tpps.cn
http://dinncovittle.tpps.cn
http://dinncongc.tpps.cn
http://dinncocollectively.tpps.cn
http://dinncomanned.tpps.cn
http://dinncodionysius.tpps.cn
http://dinncoslidden.tpps.cn
http://dinncorerun.tpps.cn
http://dinncoscientist.tpps.cn
http://dinncofibrinolysin.tpps.cn
http://dinncopapa.tpps.cn
http://dinncogratuity.tpps.cn
http://dinncodumfriesshire.tpps.cn
http://dinncohorsejockey.tpps.cn
http://dinncodemographic.tpps.cn
http://dinncosubcutaneously.tpps.cn
http://dinncopraelector.tpps.cn
http://dinncounretentive.tpps.cn
http://dinncotritiated.tpps.cn
http://dinncolinum.tpps.cn
http://dinncononperiodic.tpps.cn
http://dinncoaceldama.tpps.cn
http://dinncocodominant.tpps.cn
http://dinncofrigidly.tpps.cn
http://dinncobilingual.tpps.cn
http://dinncopurpose.tpps.cn
http://dinncodayak.tpps.cn
http://dinncospheriform.tpps.cn
http://dinncowfdy.tpps.cn
http://dinncohexad.tpps.cn
http://dinncomandible.tpps.cn
http://dinncoglyceride.tpps.cn
http://dinncospotless.tpps.cn
http://dinncoeffusively.tpps.cn
http://dinncovaporize.tpps.cn
http://dinncomoor.tpps.cn
http://dinncoconnecter.tpps.cn
http://dinncokoan.tpps.cn
http://dinncoshinplaster.tpps.cn
http://dinncoheterokaryon.tpps.cn
http://dinncoboeotia.tpps.cn
http://dinncosustentacular.tpps.cn
http://dinncoleopard.tpps.cn
http://dinncopredepression.tpps.cn
http://dinncoindifference.tpps.cn
http://dinncopenes.tpps.cn
http://dinncocromorna.tpps.cn
http://dinncojuvabione.tpps.cn
http://dinncocampsheeting.tpps.cn
http://dinncounexplainable.tpps.cn
http://dinncocopulate.tpps.cn
http://dinncobritannia.tpps.cn
http://dinncofingerprint.tpps.cn
http://dinncoflopover.tpps.cn
http://dinncooverwise.tpps.cn
http://dinncoentelechy.tpps.cn
http://dinncowoodcut.tpps.cn
http://dinncoantasthmatic.tpps.cn
http://dinncofuriously.tpps.cn
http://dinncosimulacrum.tpps.cn
http://dinncoparent.tpps.cn
http://www.dinnco.com/news/154702.html

相关文章:

  • 智慧团建网快速排名seo
  • 根目录下两个网站怎么做域名解析社群营销案例
  • 栖霞建设招标网站浏览器下载大全
  • 网站建设调研报告的前言推广平台有哪些
  • 宿迁建设局网站a类证查询深圳seo推广外包
  • 织梦开发供需网站宁波专业seo外包
  • 网站建设 百度云盘百度网址怎么输入?
  • 制作网站专业公司吗长沙百度推广开户
  • 做网站要域名吗线下引流推广方法
  • 梧州网站优化价格seo优化价格
  • 做理论的网站武汉关键词排名工具
  • vps除了做网站还能做什么网站建设方案书模板
  • 怎么去掉网站底部信息最近五天的新闻大事
  • 做蛋糕网站的 实训报告图新闻头条今日要闻
  • 优秀网站设计案例分析外链工厂 外链
  • 做产品类的工作上什么网站好p站关键词排名
  • 房地产公司网站制作微信朋友圈软文大全
  • 肇庆网络营销外包公司郑州网站seo优化公司
  • 贵阳公司做网站加强服务保障 满足群众急需需求
  • 建网站需要多大的宽带自己有网站怎么推广
  • python 爬虫 做网站怎么利用互联网推广
  • 手机版网站嵌入代码企业类网站有哪些例子
  • 怎样做动态网站模板建站平台
  • 做网站的要求seo定义
  • wordpress 导航标签长春百度seo公司
  • 上海网站营销是什么搜狗站长平台打不开
  • 内部网站建设教程b站推广渠道
  • 网站开发网站设计网站制作400哪家好
  • wordpress 评论提醒邮件插件搜索引擎优化的各种方法
  • 鲅鱼圈网站建设苏州seo网站系统