#define TEMP_FAILURE_RETRY(expression) \  

  (__extension__\  

   ({ long int __result;\  

       do __result = (long int)(expression);\  

       while(__result == -1L&& errno == EINTR);\  

       __result;})\  

#endif  





The GNU library provides a convenient way to retry a call after a temporary failure, with the macro TEMP_FAILURE_RETRY: — Macro: TEMP_FAILURE_RETRY (expression)

This macro evaluates expression once, and examines its value as type long int. If the value equals -1, that indicates a failure and errno should be set to show what kind of failure. If it fails and reports error code EINTR, TEMP_FAILURE_RETRY evaluates it again, and over and over until the result is not a temporary failure. The value returned by TEMP_FAILURE_RETRY is whatever value expression produced. 





举个例子(etc.)TEMP_FAILURE_RETRY(::accept(sock, (struct sockaddr*)addr, &len)); 

它的功能: 不断地从套接口中接收客户端的地址直到成功为止返回客户端的可用套接口. 





顺便写一个利用epoll技术来接收数据的routine 

int accept(struct sockaddr_in *addr) 



socklen_t len = sizeof(struct sockaddr_in); 

bzero(addr, sizeof(struct sockaddr_in)); 

struct epoll_event ev; 

int rc = epoll_wait(kdpfd, &ev, 1, 2000);//这里kdpfd is the library function epoll_create( 

           int size)的reture value.Here is called by epoll_create(1).You can man it.

if(1 == rc && (ev.events & EPOLLIN)) 

   return TEMP_FAILURE_RETRY(::accept(sock, (struct sockaddr*)addr, &len)); 

return -1; 

}

最新文章

  1. [ASP.NET MVC 小牛之路]02 - C#知识点提要
  2. 基于NXBRE规则引擎实现的柔性折扣策略
  3. HTTP图解
  4. 真正意义上的spring环境中的单元测试方案spring-test与mokito完美结合
  5. android图片拖动缩放
  6. 论文笔记之:Asynchronous Methods for Deep Reinforcement Learning
  7. NServiceBus-日志
  8. oc-13-多文件
  9. HMM模型实例 mahout官网上的案例
  10. CSharp tar类型文件压缩与解压
  11. 数据结构之后缀数组suffix array
  12. c++11多线程简介
  13. 从 MVC 到前后端分离
  14. 六星经典CSAPP笔记(2)信息的操作和表示
  15. 337A
  16. Date日期类型的绑定
  17. WEB 前端开发插件整理
  18. Python函数系列之eval()
  19. myBatis学习之路1-基本功能实现
  20. JavaScript倒计时实现

热门文章

  1. JSON数据转对象遍历
  2. Microsoft.CppCommon.targets(138,5): error MSB3073
  3. protobuf怎么处理java中的Object和Object[],protobuf的bytestring和object[]
  4. 6-SSRF漏洞
  5. centos安装k8s注意点
  6. 第二节 printf语句和C++中的判断结构
  7. git-bash打开自动执行某条命令的快捷方式创建
  8. Python中的startswith()函数用法
  9. WinForm分辨率适应-高DPI自动缩放
  10. 非常有用的python单行代码