互联网络程序设计.pptVIP

  1. 1、本文档共37页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
互联网络程序设计

第六章、I/O复用的服务器与客户端 I/O模型 select函数 IO复用客户端 IO复用服务器 select函数总结(poll与pselcet函数) 测试用例 1. I/O模型 I/O复用技术的引入 第3章,迭代服务器的低效率主要原因是串行执行 第4、5章,采用并行的思路来解决这个问题 从这一章开始,换一个思路 仔细分析迭代服务器模型 串行化还不是造成低效率主要原因 真正的原因是——阻塞 程序阻塞在read、accept等系统调用上,不能为其它客户端服务 串行的迭代服务器 网络操纵函数最终被抽象成文件的IO操作,着重对慢系统调用观察,会发现这些函数基本上分成两个阶段: 等待事件发生 程序与系统内核交互,获取发生的事件 根据这两个阶段的不同操作,可以分为五种IO模型 阻塞I/O 非阻塞I/O I/O复用(select、epoll、kqueue) 信号驱动I/O 异步I/O Blocking I/O Model The most prevalent I/O model 。By default, all sockets are blocking Nonblocking I/O Model When a socket is nonblocking, telling kernel: “ when an I/O operation that I request cannot be completed without putting the process th sleep, do not put the process to sleep”. It is called polling, waste of CPU time. I/O multiplexing Model When I/O multiplexing, we call select or poll and block in one of these two system call, instead of blocking in the actual I/O system call. Signal Driven I/O Model Telling the kernel to notify us with the SIGIO signal when the descriptor is ready. Advantage: process is not blocked while waiting for the datagram to arrive. Asynchronous I/O Model Asynchronous I/O tell the kernel to start the operation and to notify us when the entire operation is complete. Comparison of the I/O Model 五种IO模型回顾 同步与异步IO Posix定义这两个术语如下 同步I/O操作引起请求进程阻塞,知道I/O操作完成; 异步I/O操作不引起请求进程阻塞; IO的两个阶段都没有被阻塞,才能被称为异步IO 因此,阻塞I/O模型、非阻塞I/O模型、 I/O复用模型和信号驱动模型都是同步I/O模型;最后一种才是异步IO 实际编程中,这几种IO模型经常根据需要混用 首先要避免被阻塞,但是阻塞都不好? 在事件的检查点要阻塞 避免采用信号机制,主要原因是信号是异步的,将使程序变得很难编写。即使写成了这样的代码,也会由于引入防止异步干扰的代码,抵消掉信号带来的优势。 2. I/O Multiplexing What we need is the capability to tell the kernel that we want to be notified if one or more I/O conditions are ready (i.e., input is ready to be read, or the descriptor is capable of taking more output). This capability is called I/O multiplexing and is provided by the select and poll functions. Scenarios of I/O multiplexing When a client is handling multiple descriptors (normally interactive input and a network socket). If a TCP server h

文档评论(0)

178****9325 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档