zoukankan      html  css  js  c++  java
  • 基于select的socket编程

    1.select函数

    The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrieve a specific error code.

    In summary, a socket will be identified in a particular set when select returns if:

    readfds:

    • If listen has been called and a connection is pending, accept will succeed.
    • Data is available for reading (includes OOB data if SO_OOBINLINE is enabled).
    • Connection has been closed/reset/terminated.

    writefds:

    • If processing a connect call (nonblocking), connection has succeeded.
    • Data can be sent.

    exceptfds:

    • If processing a connect call (nonblocking), connection attempt failed.
    • OOB data is available for reading (only if SO_OOBINLINE is disabled).
    int select(
      _In_    int                  nfds,
      _Inout_ fd_set               *readfds,//检测可读性的
      _Inout_ fd_set               *writefds,//检测可写性的
      _Inout_ fd_set               *exceptfds,//检测存在错误的
      _In_    const struct timeval *timeout   //select函数等待的最长时间,阻塞模式时设为0
    );
    typedef struct fd_set {
      u_int fd_count;  //集合中的数量
      SOCKET fd_array[FD_SETSIZE];
    } fd_set;




    ....................
  • 相关阅读:
    六、Redis主从复制 
    五、AOF持久化
    四、RDB持久化
    三、数据类型
    二、redis的配置文件介绍
    第八章、堆
    九、补充
    八、Filter
    七、监听器和国际化
    六、JDBC
  • 原文地址:https://www.cnblogs.com/freesec/p/6208425.html
Copyright © 2011-2022 走看看