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;




    ....................
  • 相关阅读:
    mysql查询缓存
    Mysql 通过binlog日志恢复数据
    mysqlbinlog命令详解
    修改vsftpd默认端口21
    centos 卸载vsftpd方法
    linux挂载u盘和卸载
    Linux下搭建FTP服务器
    fastjson SerializerFeature详解
    Spring JPA使用CriteriaBuilder动态构造查询
    jdk之jps的用法
  • 原文地址:https://www.cnblogs.com/freesec/p/6208425.html
Copyright © 2011-2022 走看看