TEMP_FAILURE_RETRY宏的用法
#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;
}
最新文章
- [ASP.NET MVC 小牛之路]02 - C#知识点提要
- 基于NXBRE规则引擎实现的柔性折扣策略
- HTTP图解
- 真正意义上的spring环境中的单元测试方案spring-test与mokito完美结合
- android图片拖动缩放
- 论文笔记之:Asynchronous Methods for Deep Reinforcement Learning
- NServiceBus-日志
- oc-13-多文件
- HMM模型实例 mahout官网上的案例
- CSharp tar类型文件压缩与解压
- 数据结构之后缀数组suffix array
- c++11多线程简介
- 从 MVC 到前后端分离
- 六星经典CSAPP笔记(2)信息的操作和表示
- 337A
- Date日期类型的绑定
- WEB 前端开发插件整理
- Python函数系列之eval()
- myBatis学习之路1-基本功能实现
- JavaScript倒计时实现
热门文章
- JSON数据转对象遍历
- Microsoft.CppCommon.targets(138,5): error MSB3073
- protobuf怎么处理java中的Object和Object[],protobuf的bytestring和object[]
- 6-SSRF漏洞
- centos安装k8s注意点
- 第二节 printf语句和C++中的判断结构
- git-bash打开自动执行某条命令的快捷方式创建
- Python中的startswith()函数用法
- WinForm分辨率适应-高DPI自动缩放
- 非常有用的python单行代码