TEMP_FAILURE_RETRY宏的用法
来源:互联网 发布:用友nc系统java插件 编辑:程序博客网 时间:2024/06/14 11:11
#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;
}
(__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;
}
0 1
- TEMP_FAILURE_RETRY宏的用法
- TEMP_FAILURE_RETRY 宏
- TEMP_FAILURE_RETRY宏
- TEMP_FAILURE_RETRY宏的应用(很好用)
- TEMP_FAILURE_RETRY
- TEMP_FAILURE_RETRY,__extension,MSG_NOSIGNAL
- TEMP_FAILURE_RETRY,__extension,MSG_NOSIGNAL
- android-ndk-r10e开启C++11,编译TEMP_FAILURE_RETRY错误
- 宏的用法
- C宏的用法
- #define 宏的用法
- 宏 # ##符号 的用法
- 宏的用法
- 宏#line的用法
- offsetof宏的用法
- 宏的用法
- 宏的用法
- define宏的用法
- Android NDK Overview ---- Android 4.4
- Linux批量替换多文件中的字符串
- Oracle 分区技术
- context manager
- How to create a Oracle 11g RAC Database manually without DBCA ?
- TEMP_FAILURE_RETRY宏的用法
- Android NDK Development ---- Android 4.4
- MySQL日期时间函数大全
- php echo输出中文,读取MYSQL数据 echo 输出中文乱码
- UIScrollview
- ie6 iframe onload window.open
- Android监听WebView滑动到底部
- Redis以及Redis的php扩展安装无错版
- How to Build ffmpeg with NDK r9