zoukankan      html  css  js  c++  java
  • 使用Select的3个注意事项

    #include <sys/select.h>

    int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

    int pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask);

     

    FD_CLR(int fd, fd_set *set);

    FD_ISSET(int fd, fd_set *set);

    FD_SET(int fd, fd_set *set);

    FD_ZERO(fd_set *set);

    注意事项:

    1 每次调用前,重新设置所关心的描述符;

    2 每次调用前,重新设置等待时间;

    3 准备好的描述符定义为: read/write 描述符时不会阻塞 (socket 断开将可读 )

    解释:

    1 fd_set* 以指针形式传入, select 将扫描所关心的描述符,改变其值后返回。用户判断此返回值得知哪些描述符可读 / 可写。这意味着:在 select 返回后,描述符集必须重新设置!

    2 Timeout 以指针传入,就是说系统不保证其值不会被更改!

  • 相关阅读:
    bzoj4804
    bzoj2962
    bzoj4827
    bzoj2553
    bzoj3611
    BZOJ 1636: [Usaco2007 Jan]Balanced Lineup
    BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
    BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers
    BZOJ 1631: [Usaco2007 Feb]Cow Party
    BZOJ 2582: [Usaco2012Jan]Bovine Alliance
  • 原文地址:https://www.cnblogs.com/zhenjing/p/2021770.html
Copyright © 2011-2022 走看看