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

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 悠然小调

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