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

刚察县公司网站建设深圳华企立方

刚察县公司网站建设,深圳华企立方,采集1024图片到wordpress,静态网站开发课程模板可以在管道上进行非阻塞I / O吗#xff1f; fcntl无法设置O_NONBLOCK. Linux编程接口的页面918包括一个表’从管道读取n个字节或FIFO(p)’的语义.此表列出了管道和FIFO的行为,其中一列标题为O_NONBLOCK已启用#xff1f;这意味着您可以在管道上设置O_NONBLOCK标志.它是否正确…可以在管道上进行非阻塞I / O吗 fcntl无法设置O_NONBLOCK. Linux编程接口的页面918包括一个表’从管道读取n个字节或FIFO(p)’的语义.此表列出了管道和FIFO的行为,其中一列标题为O_NONBLOCK已启用这意味着您可以在管道上设置O_NONBLOCK标志.它是否正确以下代码无法设置标志,但fcntl(2)不报告错误.#include #include #include #include #include #define SLEEP 1intmain(int argc, char *argv[]) {pid_t childPid;int pfd[2];int nread, flags;int c a;setbuf(stdout, NULL);if (pipe(pfd) -1) {printf(error: pipe);exit(EXIT_FAILURE);}switch (childPid fork()) {case -1:printf(error: fork);exit(EXIT_FAILURE);case 0: /* child */if (close(pfd[0]) -1) {printf(child: close pfd read);exit(EXIT_FAILURE);}sleep(SLEEP);_exit(EXIT_SUCCESS);default:break;/* parent falls through */}if (close(pfd[1]) -1) {printf(parent: close pipe write);exit(EXIT_FAILURE);}flags fcntl(pfd[0], F_GETFD);flags | O_NONBLOCK;if (fcntl(pfd[0], F_SETFD, flags))perror(fcntl);/* verify flags set correctly */flags fcntl(pfd[0], F_GETFD);if (!(flags O_NONBLOCK)) {printf(failed to set O_NONBLOCK\n);exit(EXIT_FAILURE);}wait(NULL);exit(EXIT_SUCCESS);}解决方法:管道和O_NONBLOCK没有什么特别之处.以下示例按预期工作.我没有检查每次调用的每个retval,以使示例更具可读性.真实世界的应用程序必须进行检查.#include #include #include #include int main(){int fds[2];pid_t pid;char buf[100];pipe(fds);pid fork();if ( pid ){while (1 ){memcpy( buf, abcdefghi\0,10);write( fds[1], buf, 10);sleep(2);}}else{int retval fcntl( fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);printf(Ret from fcntl: %d\n, retval);while (1){ssize_t rread( fds[0], buf, 10 );printf(read: %d\n, r);if ( r 0 ){printf(Buffer: %s\n, buf);}else{printf(Read nothing\n);perror(Error was);sleep(1);}}}}写完我的例子后,我检查你的代码,发现flags fcntl(pfd[0], F_GETFD);flags | O_NONBLOCK;if (fcntl(pfd[0], F_SETFD, flags))请将F_SETFD更改为F_SETFL以及get操作.您不会更改文件描述符标志,但文件描述符状态标志:-)来自man 3 fcntlFile descriptor flagsThe following commands manipulate the flags associated with a filedescriptor. Currently, only one such flag is defined: FD_CLOEXEC, theclose-on-exec flag. If the FD_CLOEXEC bit is 0, the file descriptorwill remain open across an execve(2), otherwise it will be closed.File status flagsEach open file description has certain associated status flags, ini‐tialized by open(2) and possibly modified by fcntl(). Duplicated filedescriptors (made with dup(2), fcntl(F_DUPFD), fork(2), etc.) refer tothe same open file description, and thus share the same file statusflags.F_SETFL (int)Set the file status flags to the value specified by arg. Fileaccess mode (O_RDONLY, O_WRONLY, O_RDWR) and file creation flags(i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are ignored.On Linux this command can change only the O_APPEND, O_ASYNC,O_DIRECT, O_NOATIME, and O_NONBLOCK flags. It is not possibleto change the O_DSYNC and O_SYNC flags; see BUGS, below.标签linux,pipe,glibc来源 https://codeday.me/bug/20190727/1555320.html
http://www.yutouwan.com/news/412132/

相关文章:

  • 网站后台 语言潍坊网站建设推广公司
  • 国外html5网站建设研究现状完整网站开发看什么书
  • 河南app网站建设wordpress博客主题下载
  • 网站开发实训周报贷款类网站怎样做
  • 甘孜州住房城乡建设局网站wordpress 文章自定义排序
  • 外贸建站上海内丘网站
  • 云南专业网站建站建设仿xss网站搭建
  • 全国知名网站排名河东做网站
  • 电商网站开源授权二次开发网站建设销售是什么
  • 创意 wordpress新乡网站seo优化
  • 外贸网站模板大全网站描述怎样写
  • 为什么做企业网站千图网免费海报素材图库
  • 惠州品牌网站建设公司哪里有南宁网站建设网站推广
  • 影视传媒网站源码绍兴建设公司网站
  • 深圳分销网站设计价格门户网站内容维护流程
  • 靖江网站建设公司简述网站推广的五要素
  • 北京蓝杉网站建设公司建设厅官方网站
  • 企业网站名备案字母logo设计网站
  • 嘉兴网站建设模板网站重庆城市建设网站
  • 网站建设全过程wordpress怎么导入织梦
  • 怎么做服务器当网站服务器短链接生成器在线生成
  • 设计网站案例asp做网站得多长时间
  • 旅游网站建设备案微网站 方案
  • 自动登录网站的小程序境外建设网站贴吧
  • 运动网站建设主题影视网站搭建平台
  • 个人网站模板大全甘肃网站开发企业
  • 网站建设案例查询广告设计公司如何找业务
  • 有那些专门做职业统计的网站国际化网站
  • 上海网站排名公司什么软件能搜索关键词能快速找到
  • 河南城乡和住房建设厅网站必应搜索引擎怎么样