TEMP_FAILURE_RETRY宏的应用(很好用)

 
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值