易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux内核数据结构

1.1.链表list_head
    include/linux/list.h
    很经典,链表在内核中很常用,例如管理进程,进程的各个状态队列都是使用这个双向链表实现的。内核中的链表定义成和数据无关的形式,而不是通常我们使用的链表格式,例如
typedef struct _list{
    Elemtype elem;
    struct _list *next;
}list;
内核中的链表定义为
struct list_head{
    struct list_head *next, *prev;
};
可见,这个链表节点中不包含任何数据,只有两个指针。当需要使用链表来组织数据结构时,这个结构中就包含一个list_head成员,例如
struct _list_struct{
    Elemtype elem;
    struct list_head list;
    ...
};
显而易见,链表实现成和数据分离的好处是,不用为每种数据都定义链表操作,可以使用统一的链表操作即可。但是问题是:只知道数据成员list的地址,怎样去访问自身以及其他成员呢?
#define list_entry(ptr,type,member)    \
    container_of(ptr,type,member)
而container_of(ptr,type,member)宏定义在include/list/kernel.h中
#define container_of(ptr,type,member)    ({
    const typeof( ((type *)0)->member) *__ptr=ptr;
    (type *)( (char *)__ptr - offsetof(type,member));})
    上面的宏有几点需要解释:
1)typeof(type) 宏
    typeof(type) 宏返回变量type的类型,例如:int a; typeof(a) b;等价于int b;
2)offsetof(type,member)宏
    它定义在include/linx/stddef.h中,如下:
#define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
这个宏返回member在type类型中的偏移量,type是一个结构,例如:
typeof(list_head,next);返回0,也就是返回相对于结构起始地址的偏移量。
3)为什么要使用typeof(((type *)0)->member)来定义指针 __ptr,而不是这样:
const typeof(member) *__ptr=ptr;?
    其实,这个很简单,因为member是结构的成员,只能通过结构来访问!
4)访问数据
    在文件include/linux/list.h中,有访问链表数据的代码
#define list_for_each_entry(pos, h


相关文档:

实战Linux Bluetooth编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

linux man的用法

man -k    [keyword ]    在whatis 数据库中查找关键字;
•man -f     [keyword ]    同上,但keyword 为一个整字(whole word)
•man -a    [keyword ]    通常man 会显示第一个找到的keyword的man page,但 ......

linux安装apache支持https(ssl)

软件环境
debian 5.0
Apache Httpd 2.0.63 (http://httpd.apache.org
)
OpenSSL 0.9.81 (http://www.openssl.org/source
)
SSL-Tools (http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
)
安装步骤(所有操作使用root用户进行):
1. OpenSSL
#tar zxvf openssl-0.9.81.tar.gz
#cd openssl-0.9.81
#./config
# ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号