POSIX-Data Structure
struct sigevent
The <signal.h> header shall define the sigeventstructure, which shall include at least the following members:
struct sigevent {
int sigev_notify; //Notification type.
int sigev_signo; //Signal number.
union sigval sigev_value; //Signal value.
void (*sigev_notify_function)(union sigval); //Notification function.
pthread_attr_t *sigev_notify_attributes; //Notification attributes.
};
sigev_notify
sigev_notify 的取值范围如下,只有3种情况(对应的宏在<signal.h>中定义)。
- SIGEV_NONE
- 事件发生时,什么也不做.
- SIGEV_SIGNAL
- 事件发生时,将sigev_signo 指定的信号(A queued signal)发送给指定的进程.
- SIGEV_THREAD
- 事件发生时,内核会(在此进程内)以sigev_notification_attributes为线程属性创建一个线程,并且让它执行sigev_notify_function,
- 传入sigev_value作为为一个参数.
sigev_signo
在sigev_notify = SIGEV_SIGNAL 时使用,指定信号的种别(number).
sigev_value
在sigev_notify = SIGEV_THREAD 时使用,作为sigev_notify_function 的参数.
union sigval
{
int sival_int;
void *sival_ptr;
};
(*sigev_notify_function)(union sigval)
函数指针(指向通知执行函数),在sigev_notify = SIGEV_THREAD 时使用, 其他情况下置为NULL.
sigev_notify_attributes
指向线程属性的指针,在sigev_notify = SIGEV_THREAD 时使用,指定创建线程的属性, 其他情况下置为NULL.
strcut timespec
The <time.h> header shall declare the timespecstructure, which shall include at least the following members:
struct timespec
{
time_t tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds(纳秒:十亿分之一秒) */
};
struct itimerspec
The <time.h> header shall also declare the itimerspecstructure, which shall include at least the following members:
struct itimerspec
{
struct timespec it_interval; /* Timer interval(timer循环时间间隔) */
struct timespec it_value; /* Initial expiration(timer初次到期时间间隔) */
};
clockid_t
clockid_tis used for clock ID type in the clock and timer functions, 取值范围如下(前4个是POSIX定义的,灰色部分为Linux的扩展),
/* Identifier for system-wide realtime clock, Setting this clock requires appropriate privileges */
#define CLOCK_REALTIME
/* Monotonic system-wide clock, Clock that cannot be set and represents monotonic time since some unspecified starting point */
#define CLOCK_MONOTONIC
/* High-resolution timer from the CPU. (since Linux 2.6.12) */
#define CLOCK_PROCESS_CPUTIME_ID 2
/* Thread-specific CPU-time clock. (since Linux 2.6.12) */
#define CLOCK_THREAD_CPUTIME_ID
/* Monotonic system-wide clock, not adjusted for frequency scaling. */
#define CLOCK_MONOTONIC_RAW 4
/* Identifier for system-wide realtime clock, updated only on ticks. */
#define CLOCK_REALTIME_COARSE 5
/* Monotonic system-wide clock, updated only on ticks. */
#define CLOCK_MONOTONIC_COARSE 6
CLOCK_REALTIME : 这种时钟表示的是绝对时间, 指的是从1970年1月1月0:00到目前经过多少秒, 相当于你的linux系统中显示的时间, 所以这个时间是可以更改的, 当系统的时钟源被改变,或者系统管理员重置了系统时间之后,这种类型的时钟可以得到相应的调整, 对设定为此类型的timer是有影响的.
CLOCK_MONOTONIC : 这种时钟表示的是相对时间, 其值对通过累积时钟节拍(嘀嗒)计算出来的, 不受时钟源等的影响, 从系统启动这一刻起开始计时, 如果你想计算出在一台计算机上不受重启的影响,两个事件发生的间隔时间的话,那么它将是最好的选择。
CLOCK_PROCESS_CPUTIME_ID : 测量调用进程(包括该进程内所有的线程)用户和系统消耗的总CPU时间.
CLOCK_THREAD_CPUTIME_ID : 测量调用线程消耗的CPU时间.
struct timeval
The <sys/time.h> header shall define the timevalstructure, which shall include at least the following members:
struct timeval
{
time_t tv_sec; // Seconds(秒).
suseconds_t tv_usec; // Microseconds(微秒:千分之一毫秒).
};
struct itimerval
The <sys/time.h> header shall define the itimerval structure, which shall include at least the following members:
struct itimerval
{
struct timeval it_interval; /* Timer interval(timer循环时间间隔) */
struct timeval it_value; /* Initial expiration(timer初次到期时间间隔) */
};
strcut tm
The <time.h> header shall declare the tm structure, which shall include at least the following members:
struct tm
{
int tm_sec //Seconds [0,60]. 60 is used for leap seconds.
int tm_min //Minutes [0,59].
int tm_hour //Hour [0,23].
int tm_mday //Day of month [1,31].
int tm_mon //Month of year [0,11].
int tm_year //Years since 1900.
int tm_wday //Day of week [0,6] (Sunday =0).
int tm_yday //Day of year [0,365]. The number of days since January 1
int tm_isdst //Daylight Savings flag(夏时令)
};
注意: 1)使用localtime等函数取得tm结构体,表示当前时间时, 年数要加1900,月数要加1;因为tm_year是1900的偏移量,tm_mon是从0开始计算的.
2)tm_isdst是夏时令的标志, 大于0表示时间使用了夏时令, 0表示未使用夏时令,小于0表示没有相关信息.
struct sockaddr
The <sys/socket.h> header shall define the sockaddr structure, which shall include at least the following members:
struct sockaddr
{
sa_family_t sa_family; //Address family.
char sa_data[]; // Socket address (variable-length data).
};
The sockaddr structure is used to define a socket address which is used in the bind(), connect(), getpeername(), getsockname(), recvfrom(), and sendto() functions.
struct sockaddr_in
The <netinet/in.h> header shall define the sockaddr_in structure, which shall include at least the following members:
typedef uint32_t in_addr_t; /* Internet address. */ struct in_addr
{
in_addr_t s_addr;
}; struct sockaddr_in
{
sa_family_t sin_family; //AF_INET.
in_port_t sin_port; //Port number(网络字节序).
struct in_addr sin_addr; //IP address(网络字节序).
};
The sockaddr_in structure is used to store addresses for the Internet address family. Pointers to this type shall be cast by applications to struct sockaddr * for use with socket functions.
struct hostent
The <netdb.h> header shall define the hostent structure, which shall include at least the following members:
struct hostent
{
char *h_name; //Official name of the host.
char **h_aliases; //主机的别名,可以有多个,最一个是空指针
int h_addrtype; //Address type.always AF_INET or AF_INET6 at present.
int h_length; //地址的长度(IPv4的长度为4字节).
char **h_addr_list; //IP地址,可以有多个,最后一个是空指针(网络字节序)
};
#define h_addr h_addr_list[0] /* for backward compatibility */ /* 注意事项
(1)h_aliases 和 h_addr_list 的用法见例子:http://www.cnblogs.com/LubinLew/p/Linux-gethostbyname.html
(2)h_addr_list中存储的IP地址格式为点分10进制,因为是网络字节序,不能用printf直接打印出来,需要使用inet_ntop函数来转换
*/
结构图示:
Ip Protocol
/* Standard well-defined IP protocols. */
enum {
IPPROTO_IP = , /* Dummy protocol for TCP. */
IPPROTO_ICMP = , /* Internet Control Message Protocol. */
IPPROTO_IGMP = , /* Internet Group Management Protocol. */
IPPROTO_IPIP = , /* IPIP tunnels (older KA9Q tunnels use 94). */
IPPROTO_TCP = , /* Transmission Control Protocol. */
IPPROTO_EGP = , /* Exterior Gateway Protocol. */
IPPROTO_PUP = , /* PUP protocol. */
IPPROTO_UDP = , /* User Datagram Protocol. */
IPPROTO_IDP = , /* XNS IDP protocol. */
IPPROTO_TP = , /* SO Transport Protocol Class 4. */
IPPROTO_DCCP = , /* Datagram Congestion Control Protocol. */
IPPROTO_IPV6 = , /* IPv6 header. */
IPPROTO_RSVP = , /* Reservation Protocol. */
IPPROTO_GRE = , /* General Routing Encapsulation. */
IPPROTO_ESP = , /* encapsulating security payload. */
IPPROTO_AH = , /* authentication header. */
IPPROTO_MTP = , /* Multicast Transport Protocol. */
IPPROTO_BEETPH = , /* IP option pseudo header for BEET. */
IPPROTO_ENCAP = , /* Encapsulation Header. */
IPPROTO_PIM = , /* Protocol Independent Multicast. */
IPPROTO_COMP = , /* Compression Header Protocol. */
IPPROTO_SCTP = , /* Stream Control Transmission Protocol. */
IPPROTO_UDPLITE = , /* UDP-Lite protocol. */
IPPROTO_RAW = , /* Raw IP packets. */
IPPROTO_MAX
};
struct addrinfo
The <netdb.h> header shall define the addrinfo structure, which shall include at least the following members:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h> /* ======================Types of sockets====================== */
enum __socket_type {
SOCK_STREAM = , /* Sequenced, reliable, connection-based byte streams. */
SOCK_DGRAM = , /* Connectionless, unreliable datagrams of fixed maximum length. */
SOCK_RAW = , /* Raw protocol interface. */
SOCK_RDM = , /* Reliably-delivered messages. */
SOCK_SEQPACKET = , /* Sequenced, reliable, connection-based,datagrams of fixed maximum length. */
SOCK_DCCP = , /* Datagram Congestion Control Protocol. */
SOCK_PACKET = , /* Linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level. */ /* Flags to be ORed into the type parameter of socket and socketpair and used for the flags parameter of paccept. */
SOCK_CLOEXEC = , /* Atomically set close-on-exec flag for the new descriptor(s). */
SOCK_NONBLOCK = /* Atomically mark descriptor(s) as non-blocking. */
}; /* ============Protocol families(只列出常用几个)================= */
#define PF_UNSPEC 0 /* Unspecified. */
#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */
#define PF_INET 2 /* IP protocol family. */
#define PF_IPX 4 /* Novell Internet Protocol. */
#define PF_APPLETALK 5 /* Appletalk DDP. */
#define PF_INET6 10 /* IP version 6. */
#define PF_TIPC 30 /* TIPC sockets. */
#define PF_BLUETOOTH 31 /* Bluetooth sockets. */ /* ==============Address families(只列出常用几个)================= */
#define AF_UNSPEC PF_UNSPEC
#define AF_LOCAL PF_LOCAL
#define AF_UNIX PF_UNIX
#define AF_FILE PF_FILE
#define AF_INET PF_INET
#define AF_IPX PF_IPX
#define AF_APPLETALK PF_APPLETALK
#define AF_INET6 PF_INET6
#define AF_ROSE PF_ROSE
#define AF_NETLINK PF_NETLINK
#define AF_TIPC PF_TIPC
#define AF_BLUETOOTH PF_BLUETOOTH /* ====Possible values for `ai_flags' field in `addrinfo' structure.===== */
#define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
#define AI_CANONNAME 0x0002 /* Request for canonical name. */
#define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
#define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
#define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
#define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose returned address type. */
#ifdef __USE_GNU
#define AI_IDN 0x0040 /* IDN encode input (assuming it is encoded
in the current locale's character set) before looking it up. */
#define AI_CANONIDN 0x0080 /* Translate canonical name from IDN format. */
#define AI_IDN_ALLOW_UNASSIGNED 0x0100 /* Don't reject unassigned Unicode code points. */
#define AI_IDN_USE_STD3_ASCII_RULES 0x0200 /* Validate strings according to STD3 rules. */
#endif
#define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ /* =======================struct addrinfo======================= */
struct addrinfo {
int ai_flags; /* 附加选项,多个选项可以使用或操作结合 */
int ai_family; /* 指定返回地址的协议簇,取值范围:AF_INET(IPv4)、AF_INET6(IPv6)、AF_UNSPEC(IPv4 and IPv6) */
int ai_socktype; /* enum __socket_type 类型,设置为0表示任意类型 */
int ai_protocol; /* 协议类型,设置为0表示任意类型,具体见上一节的 Ip Protocol */
socklen_t ai_addrlen; /* socket address 的长度 */
struct sockaddr *ai_addr; /* socket address 的地址 */
char *ai_canonname; /* Canonical name of service location. */
struct addrinfo *ai_next; /* 指向下一条信息,因为可能返回多个地址 */
};
POSIX-Data Structure的更多相关文章
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- Finger Trees: A Simple General-purpose Data Structure
http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...
- Mesh Data Structure in OpenCascade
Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...
- ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
- leetcode Add and Search Word - Data structure design
我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...
- Java for LeetCode 211 Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- LeetCode Two Sum III - Data structure design
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...
随机推荐
- Dijkstra【迪杰斯特拉算法】
有关最短路径的最后一个算法——Dijkstra 迪杰斯特拉算法是由荷兰计算机科学家迪杰斯特拉于1959 年提出的,因此又叫迪杰斯特拉算法.是从一个顶点到其余各顶点的最短路径算法,解决的是有权图中最短路 ...
- win10更改无线网卡的MAC地址
https://blog.csdn.net/qq_31778495/article/details/80932472 前段时间电脑蹭网被禁了MAC地址,故寻找修改MAC地址的方法. 本机配置: win ...
- Python的安装与小程序的编写
Python的安装 在此之前,我完全不了解Python,为了完成任务,在慌忙之中了解了一下Python,通过百度,一步步安装好Python 过程 1.从官网中找到下载菜单并下载最新版本 2.双击pyt ...
- 一文了解Python的线程
问题 什么是线程? 如何创建.执行线程? 如何使用线程池ThreadPoolExecutor? 如何避免资源竞争问题? 如何使用Python中线程模块threading提供的常用工具? 目录 1. 什 ...
- Python的优势及应用领域
Python的优势 Python是一门解释型语言,是比较容易入门. Python的程序代码更接近英语,更好好理解. Python的扩展库非常丰富. Python与C的粘合性非常好. Python的缺点 ...
- [C++] const与指针的关系
首先快速复习一些基础. 考虑下面的声明兼定义式: int p = 10; p的基础数据类型是int. 考虑下面的声明兼定义式: const int a = 10; a的基础数据类型是int,a是一个常 ...
- 【codeforces 983E】NN country
Description In the NN country, there are n cities, numbered from 1 to n, and n−1 roads, connecting t ...
- thinkphp5+vue+iview商城 公众号+小程序更新版本
thinkphp5+vue+iview商城加分销 源码下载地址:http://github.crmeb.net/u/crmeb 演示站后台:http://demo25.crmeb.net 账号:dem ...
- Python编程四大神兽:迭代器、生成器、闭包和装饰器
生成器 生成器是生成一个值的特殊函数,它具有这样一个特点:第一次执行该函数时,先从头按顺序执行,在碰到yield关键字时该函数会暂停执行该函数后续的代码,并且返回一个值:在下一次调用该函数执行时,程序 ...
- C语言通讯录系统——C语言单向链表实现
实现的通讯录功能有:查看通讯录.添加联系人.删除联系人.查询联系人.保存并退出. 通过txt文件保存和读取通讯录数据. #include <stdio.h> #include <st ...