本文共 977 字,大约阅读时间需要 3 分钟。
1、获取该socket s本地的ip和port
#include<sys/socket.h>
int getsockname(int sockfd, struct sockaddr *localaddr, socklen_t *addrlen);
2、获取该socket s对端的ip和port
#include<sys/socket.h>
int getpeername(int sockfd, struct sockaddr *peeraddr, socklen_t *addrlen);
3、
if_nametoindex():指定网络接口名称字符串作为参数;若该接口存在,则返回相应的索引,否则返回0
if_indextoname():指定网络接口索引以及一块长度至少为IF_NAMESIZE(16)字节的内存区域作为参数;若索引对应的网络接口存在,则在内存区域中返回该接口的名称字符串,否则返回NULL,并将errno设置为相应的值
4、
线程可以安排它退出时需要调用的函数,这样的函数称为线程清理处理程序,线程可以建立多个清理处理程序。处理程序记录在栈中,也就是说它们的执行顺序与它们注册时的顺序相反。
pthread_cleanup_push来注册清理函数rtn,这个函数有一个参数arg。在以下三种情形之一发生时,注册的清理函数被执行:
1)调用pthread_exit。 2)作为对取消线程请求(pthread_cancel)的响应。 3)以非0参数调用pthread_cleanup_pop。 注意:1)如果线程只是由于简单的返回而终止的,则清除函数不会被调用。
2)如果pthread_cleanup_pop被传递0参数,则清除函数不会被调用,但是会清除处于栈顶的清理函数。
名称: | pthread_cleanup_push / pthread_cleanup_pop |
功能: | 线程清理处理程序 |
头文件: | #include <pthread.h> |
函数原形: | void pthread_cleanup_push(void (*rtn)(void *),void *arg); void pthread_cleanup_pop(int execute); |
参数: | rtn 处理程序入口地址 arg 传递给处理函数的参数 |
返回值: | 无 |
转载地址:http://wyfin.baihongyu.com/