• winsock中select的作用


    select函数用来填充一组可用的socket句柄,当满足如下条件时:
    1.可以读取的sockets。当这些socket被返回时,在这些socket上执行recv/accept等操作不会产生阻塞;
    2.可以写入的sockets。当这些socket被返回时,在这些socket上执行send等不会产生阻塞;
    3.返回有错误的sockets。

    同时和select配对使用的还有:
    FD_CLR(s, *set)
    Removes the descriptor s from set.
    FD_ISSET(s, *set)
    Nonzero if s is a member of the set. Otherwise, zero.
    FD_SET(s, *set)
    Adds descriptor s to set.
    FD_ZERO(*set)
    Initializes the set to the null set.

    示例代码:
      SOCKET     s;   
      fd_set     fdread;   
      
    int           ret;   
        
      
    //   Create   a   socket,   and   accept   a   connection   
        
      
    //   Manage   I/O   on   the   socket   
      while(TRUE)   
      {   
              
    //   Always   clear   the   read   set   before   calling     
              
    //   select()   
              FD_ZERO(&fdread);   
        
              
    //   Add   socket   s   to   the   read   set   
              FD_SET(s,   &fdread);   
        
              
    if   ((ret   =   select(0,   &fdread,   NULL,   NULL,   NULL))     
                      
    ==   SOCKET_ERROR)     
              {   
                      
    //   Error   condition   
              }   
        
              
    if   (ret   >   0)   
              {   
                      
    //   For   this   simple   case,   select()   should   return   
                      
    //   the   value   1.   An   application   dealing   with     
                      
    //   more   than   one   socket   could   get   a   value     
                      
    //   greater   than   1.   At   this   point,   your     
                      
    //   application   should   check   to   see   whether   the     
                      
    //   socket   is   part   of   a   set.   
        
                      
    if   (FD_ISSET(s,   &fdread))   
                      {   
                              
    //   A   read   event   has   occurred   on   socket   s   
                      }   
              }   
      }   
  • 相关阅读:
    C#中的多态
    反编译工具
    富文本粘贴图片
    [Silverlight入门系列]用TransformToVisual和Transform取得元素绝对位置(Location)
    Silverlight在IIS中的配置
    HubbleDotNet开源全文搜索数据库项目技术详解
    Thank you for choosing Telerik RadRichTextBox
    Asp.net读取AD域信息的方法<转>
    Sharepoint学习笔记—ECMAScript对象模型系列1、ECMAScript对象模型的引入
    SharePoint WebService
  • 原文地址:https://www.cnblogs.com/yoran/p/1091812.html
Copyright © 2020-2023  润新知