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;




    ....................
  • 相关阅读:
    软件工程概论-用户登录界面
    2016.11.25异常处理
    2016.11.18多态
    2016.11.11继承与接口
    11.6数组
    10.28字符串加密等
    python 读写文件
    python可变的类型、不可变的类型
    python 字典练习 记录学生是否交作业的小程序
    python字典
  • 原文地址:https://www.cnblogs.com/freesec/p/6208425.html
Copyright © 2011-2022 走看看