惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
A
About on SuperTechFans
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
B
Blog RSS Feed
G
Google Developers Blog
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)

博客园 - 悠然小调

nothing.... Ogre中在SceneNode节点旁显示二维字的代码 博文阅读密码验证 - 博客园 最简单的智能指针原理 模板的特化 计算基类虚表指针在派生类中的偏移量 写一个内存拷贝函数 [转]来自 COM 经验的八个教训 COM本质论学习笔记(一)IDL windows核心编程学习笔记(三)线程池(Thread Pooling) windows核心编程学习笔记(八)结构化异常处理(Structured Exception Handling) [转]亲密接触VC6.0编译器 windows核心编程学习笔记(七)DLL Injection and API Hooking windows核心编程学习笔记(五.续)堆 windows核心编程学习笔记(五)内存映射文件 windows核心编程学习笔记(四)windows内存结构/虚拟内存/线程的堆栈 windows核心编程学习笔记(二)Wait For Kernel Object(s) windows核心编程学习笔记(一)使用Critical Section [转]筛选法求素数
winsock中select的作用
悠然小调 · 2008-03-05 · via 博客园 - 悠然小调

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   
                  }   
          }   
  }