zoukankan      html  css  js  c++  java
  • linxu select 返回值

    曾经写过如上这样的代码,执行时怎么也得不到预想的结果!
    后来,仔细看man select
    On success, select() and pselect() return the number of file descriptors contained in the three returned descriptor sets(that  is,  the  total  number  of  bits  that are set in readfds, writefds, exceptfds) which may be zero if the timeout expires before anything interesting happens.  On error, -1 is returned, and errno is set appropriately;  the  sets  and timeout become undefined, so do not rely on their contents after an error.
    原来第一次select的时候出错了,导致rd_fd和tm(主要是rd_fd)的值 become undefined,进而导致以后的select调用的失败!
    解决办法:
    在1处(while循环内的开头),添加如下代码:
    FD_ZERO(&rd_fd);
    FD_SET(sockfd, &rd_fd);
    tm.tv_sec = 1;
    tm.tv_usec = 0;

  • 相关阅读:
    网页的资源加载优化
    Object.prototype.toString的应用
    判断一个字符串中出现次数最多的字符,并统计字数
    toString()和toLocaleString()有什么区别
    响应式网站布局要适应的当下主流手机屏幕的各个版本的分辨率有哪些(media query)
    handlebars用法
    算符优先分析及其简单代码实现
    OpenGL:使用顶点数组法绘制正六面体
    算法设计:两种快速排序代码实现
    c#简易学生信息管理系统
  • 原文地址:https://www.cnblogs.com/hjslovewcl/p/2314332.html
Copyright © 2011-2022 走看看