app与网站开发的区别,住房和城乡建设部网站投诉电话,新浪博客,公司网站文章TCP并发模型: 1.TCP多线程模型: 缺点: 1.创建线程会带来 资源开销 2.能够实现的 并发量 比较有限
2.IO模型: 1.阻塞IO: 没有…TCP并发模型: 1.TCP多线程模型: 缺点: 1.创建线程会带来 资源开销 2.能够实现的 并发量 比较有限
2.IO模型: 1.阻塞IO: 没有数据到来时,可以让任务挂起 节省CPU资源开销,提高系统效率 2.非阻塞IO: 程序未接收到数据时一直执行 效率很低 3.异步IO 只能绑定一个文件描述符用来 读取数据 4.多路复用IO select 1.select监听的集合中的文件描述符有 上限限制 2.select有 内核层 向 用户层数据空间 拷贝 的过程,占用系统资源开销 3.select必须 轮询检测 产生 事件 的文件描述符 4.select 只能工作 在 水平触发 模式(低速模式) 无法工作 在 边沿触发 模式(高速模式) poll 监听的集合中的文件描述符有 没有上限限制 1.poll有 内核层 向 用户层 数据空间 拷贝 的过程,占用系统资源开销 2.poll必须 轮询检测 产生 事件 的文件描述符 3.poll 只能工作在水平触发模式(低速模式) 与select相同 无法工作在边沿触发(高速模式)
水平触发产生事件通知没处理完成下次继续通知此事件阻塞在这里直到处理完成此事件低速。
边沿触发产生事件的时刻通知只通知一次下次通知其它事件不阻塞。
poll内部链表结构所以无上限。 3.函数接口: 1.select int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); 功能: select 监听 文件描述符集合 中 是否 有文件描述编程 ready状态 select 监听 文件描述符集合 中 若有状态 将没有ready状态的T除 若无状态将阻塞继续等待 参数: nfds: 最大文件描述符的值 1 readfds: 读 文件描述符集合 writefds: 写 文件描述符集合 exceptfds: 其余 文件描述符集合 timeout: 等待的时长 NULL 一直等待超时处理 返回值: 成功 返回 文件描述符集合中 的 文件描述符个数 失败 返回 -1 void FD_CLR (int fd, fd_set *set); 功能: 将文件描述符 fd 从集合中清除 int FD_ISSET (int fd, fd_set *set); 功能: 判断文件描述符 fd 是否仍在集合中 void FD_SET(int fd, fd_set *set); 功能: 将文件描述符 fd 加入到 集合中 void FD_ZERO(fd_set *set); 功能: 将文件描述符集合 清0 2.poll int poll(struct pollfd *fds, nfds_t nfds, int timeout); 功能: 监听 文件描述符集合 是否 有事件发生 参数: fds: 监听 文件描述符集合 数组空间首 地址 nfds: 监听 文件描述符集合 元素个数 timeout: 等待的时间 非0 -1 一直等待 返回值: 成功 返回 产生事件的文件描述符 个数 失败 返回 -1 struct pollfd { int fd; /* file descriptor */ short events; /* requested events */ short revents; /* returned events */ }; fd: 监听的文件描述符 events: 要监听的 事件 POLLIN: 是否 可读 POLLOUT: 是否 可写 revents: 实际 产生的 事件 3.epoll int epoll_create(int size); 功能: 创建 一张 内核事件表 参数: size: 事件的 个数 返回值: 成功返回文件描述符 失败返回-1 epoll_ctl int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); 功能: 维护 epoll时间表 参数: epfd: 事件表 的文件描述符 op: EPOLL_CTL_ADD 添加事件 EPOLL_CTL_MOD 修改事件 EPOLL_CTL_DEL 删除事件 fd: 操作 的文件描述符 event: 事件 对应的 事件 typedef union epoll_data { void *ptr; int fd; uint32_t u32; uint64_t u64; } epoll_data_t; struct epoll_event { uint32_t events; /* Epoll events */ epoll_data_t data; /* User data variable */ }; 返回值: 成功返回0 失败返回-1 epoll_wait int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); 功能: 监听 事件表中 的 事件 参数: epfd: 文件描述符 events: 存放 实际产生事件 的数组空间 首地址 maxevents: 最多 存放事件 的 个数 timeout: 设定监听的时间超过该时间 则不再监听 -1 一直监听直到有事件发生 返回值: 成功返回产生事件的文件描述符个数 失败返回-1 如果时间达到 仍没有事件发生 返回0 文章转载自: http://www.morning.tmxfn.cn.gov.cn.tmxfn.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.ykmtz.cn.gov.cn.ykmtz.cn http://www.morning.tgbx.cn.gov.cn.tgbx.cn http://www.morning.tpssx.cn.gov.cn.tpssx.cn http://www.morning.ctpfq.cn.gov.cn.ctpfq.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn http://www.morning.rlcqx.cn.gov.cn.rlcqx.cn http://www.morning.gyjld.cn.gov.cn.gyjld.cn http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.jpjxb.cn.gov.cn.jpjxb.cn http://www.morning.jxfmn.cn.gov.cn.jxfmn.cn http://www.morning.pmdnx.cn.gov.cn.pmdnx.cn http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn http://www.morning.srxhd.cn.gov.cn.srxhd.cn http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn http://www.morning.bttph.cn.gov.cn.bttph.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.bpmnh.cn.gov.cn.bpmnh.cn http://www.morning.ghjln.cn.gov.cn.ghjln.cn http://www.morning.dmjhp.cn.gov.cn.dmjhp.cn http://www.morning.tkjh.cn.gov.cn.tkjh.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.rqnml.cn.gov.cn.rqnml.cn http://www.morning.bdzps.cn.gov.cn.bdzps.cn http://www.morning.ljsxg.cn.gov.cn.ljsxg.cn http://www.morning.bpmfl.cn.gov.cn.bpmfl.cn http://www.morning.mbmh.cn.gov.cn.mbmh.cn http://www.morning.kdpal.cn.gov.cn.kdpal.cn http://www.morning.bangaw.cn.gov.cn.bangaw.cn http://www.morning.wphzr.cn.gov.cn.wphzr.cn http://www.morning.tsnq.cn.gov.cn.tsnq.cn http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn http://www.morning.bkylg.cn.gov.cn.bkylg.cn http://www.morning.hghhy.cn.gov.cn.hghhy.cn http://www.morning.gslz.com.cn.gov.cn.gslz.com.cn http://www.morning.cjmmn.cn.gov.cn.cjmmn.cn http://www.morning.rppf.cn.gov.cn.rppf.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.chzqy.cn.gov.cn.chzqy.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.krkwh.cn.gov.cn.krkwh.cn http://www.morning.gklxm.cn.gov.cn.gklxm.cn http://www.morning.jntdf.cn.gov.cn.jntdf.cn http://www.morning.rkzb.cn.gov.cn.rkzb.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.jzmqk.cn.gov.cn.jzmqk.cn http://www.morning.ypcd.cn.gov.cn.ypcd.cn http://www.morning.zwpzy.cn.gov.cn.zwpzy.cn http://www.morning.xprzq.cn.gov.cn.xprzq.cn http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.xkhxl.cn.gov.cn.xkhxl.cn http://www.morning.lonlie.com.gov.cn.lonlie.com http://www.morning.wpkr.cn.gov.cn.wpkr.cn http://www.morning.wfkbk.cn.gov.cn.wfkbk.cn http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.drywd.cn.gov.cn.drywd.cn http://www.morning.sjqpm.cn.gov.cn.sjqpm.cn http://www.morning.dwztj.cn.gov.cn.dwztj.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.xrrbj.cn.gov.cn.xrrbj.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn http://www.morning.wgrl.cn.gov.cn.wgrl.cn http://www.morning.lwgsk.cn.gov.cn.lwgsk.cn http://www.morning.dhckp.cn.gov.cn.dhckp.cn http://www.morning.ltpph.cn.gov.cn.ltpph.cn http://www.morning.lstmq.cn.gov.cn.lstmq.cn http://www.morning.ntffl.cn.gov.cn.ntffl.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.nnwmd.cn.gov.cn.nnwmd.cn http://www.morning.kzcz.cn.gov.cn.kzcz.cn http://www.morning.sftrt.cn.gov.cn.sftrt.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.xrpjr.cn.gov.cn.xrpjr.cn