minix网络功能概述(3)

( 原文:http://www.nyx.net/~ctwong/minix/MinixNetworking.html
  文章借助了google的翻译功能,所以有些地方不太通顺,凑合着看吧   by hugion, 2009.5.21 )

 

buf.c
 
We shall now discuss how inet allocates memory to store the data which is sent and received. This is handled in buf.c. bf_init() is called in inet.c when the

inet process starts running and runs the initialization procedures.  
我们现在讨论如何Inet分配内存来存储数据,发送和接收。这是在buf.c中处理. 当在Inet过程开始运行并运行初始化程序,调用inet.c中的bf_init()。

 

bf_init initializes the buffer used to store data. We shall only handle the case when storage is allocated without malloc - by using arrays (this is done by

not defining BUF_USEMALLOC) - and where each buffer stores 512 bytes of data (this is done by defining BUF512_NR).

bf_init初始化缓冲区用于存储数据。我们只应处理的情况下,存储分配没有内存分配-以使用数组(这样做是没有界定BUF_USEMALLOC ) -并在每个缓冲储存512字节的数据(这是通过确定BUF512_NR ) 。
 
The buffer structure is declared in
缓冲区结构中宣称
 
#define DECLARE_TYPE(Tag, Type, Size)              /
    typedef struct Tag                   /
    {                        /
        buf_t buf_header;               /
        char buf_data[Size];               /
    } Type
 
DECLARE_TYPE(buf512, buf512_t, 512);
 
buf_data is the array which stores the data. Buf512_t is the structure that holds buf_data.
buf_data是数组存储数据。 Buf512_t是结构,拥有buf_data 。
 
We shall now go over the buf_t structure. buf_t is defined in buf.h. Ignoring certain defines buf_t is defined as follows:
我们现在进入了buf_t结构。 buf_t是指在buf.h.无视某些定义buf_t的定义如下:
 
typedef struct buf
{
    int buf_linkC;
    buffree_t buf_free;
    size_t buf_size;
    char *buf_data_p;
} buf_t;
 
buf_linkC: holds the number of variables which points to this structure. If buf_linkC = 0 the buffer goes back to one of the free lists.
           拥有许多变量,其中指出这种结构。如果buf_linkC = 0的缓冲区可追溯到一个空闲列表。

buf_free: pointer to the function which is called to free the acc_t structures which holds the buffer.
          函数指针,用来释放acc_t

buf_size: amount (in byes) of data held in buf_data.
          缓存大小
 
buf_data_p: pointer to the buf_data array which holds the data.
            指向缓存的指针
 
We shall now go over the acc_t structure. acc_t is defined in buf.h. In general the specific implementations of the protocols (as in udp.c) access the buf_t structure indirectly throught the acc_t structure. Ignoring certain defines acc_t is defined as follows:

我们现在进入了acc_t结构。 acc_t是指在buf.h.一般来说,具体的实现协议(如在udp.c )访问buf_t结构间接认为acc_t结构。无视某些定义acc_t的定义如下:
 
typedef struct acc
{
    int acc_linkC;
    int acc_offset, acc_length;
    buf_t *acc_buffer;
    struct acc *acc_next, *acc_ext_link;
} acc_t;
 
acc_linkC: holds the number of variables which points to this structure. If acc_linkC = 0 the buffer goes back to one of the free lists.
           拥有许多变量,其中指出这种结构。如果acc_linkC = 0的缓冲区可追溯到一个空闲列表。

acc_offset: holds an offset in to the buffer data.
            缓存偏移
 
acc_length: length of buffer data which acc_t structure is storing.
            缓存大小
 
acc_buffer: points to buf_t structure which stores the data.
            缓存指针
 
acc_next: points to next acc_t structure in linked list. When the acc_t structure is not being used it points to the next free item in a linked list. When its not free, the linked list is used in the following way for example: one acc_t structure points to the ip header, acc_next points to the udp header., the

acc_next of that acc_t structure points to the data, etc. In the case the acc_t structure is not free, the different buffers which belong to the different acc_t structures in the linked list are considered to store the same chunk of data. Therefore if the size of the array pointed to by buf_data_p is not large

enough to hold the chunk of data desired, new acc_t structures (with their own buf_data_p arrays) are used until there are enough buf_data_p buffers to hold all of data. The acc_t structures are linked together by the acc_next pointer.
          指向acc_t结构链表的下一个元素。当acc_t结构并没有用,它指向下一个空闲的链表元素。当它不是空闲的,在链表中使用下列方式:例如: 1 acc_t结构指向IP头,

acc_next点的UDP连接头 ,该acc_t结构的acc_next指向数据等。如果acc_t不是空闲的,不同的缓冲器属于不同acc_t结构的链表,被视为相同的块存储的数据。因此,如果大小的

阵列所指向buf_data_p是不够大举行大块数据理想,新acc_t结构(用自己的buf_data_p阵列)的使用,直到有足够的缓冲举行buf_data_p的所有数据。该acc_t结构是被acc_next

指针联系在一起的。
 
acc_ext_link: points to next acc_t structure in linked list. Its used by the implementation of a protocol.
             指向链表的下一个acc_t结构,是由协议本身实现的

 

One define which is used quite often is the following from buf.h
一个经常用到的在buf.h定义的宏
 
#define ptr2acc_data(/* acc_t * */ a) (bf_temporary_acc=(a), /
    (&bf_temporary_acc->acc_buffer->buf_data_p[bf_temporary_acc-> /
        acc_offset]))
 
ptr2acc_data returns a pointer to the buffer data which is stored in the buf_data array in the buf512_t structure. The returned buffer is used to read data which has been received or to send data which shall be sent.
ptr2acc_data返回一个指针缓冲区数据存储在buf_data阵列buf512_t结构。返回的缓冲区是用来读取数据,已收到或发送的数据,应送交。

 

We begin with bf_init(). bf_init() declares an array of buffer structures buf_t called buffers512. bf_init() next declares an array of acc_t structures called accessors.
我们首先bf_init() 。 bf_init()宣布了一系列缓冲结构buf_t所谓buffers512 。 bf_init 接着宣布了一系列acc_t结构称为访问者accessors。

 
acc_freelist points to the head of the free list of the acc_t structures which do not have a acc_buffer buf_t structure allocated to them. It is used by bf_dupacc to return a copy of the original acc_t structure. Since the acc_t structure stores a pointer to the buf_t structure, bf_dupacc merely sets the

pointer to the buf_t structure in the original buffer and no new buf_t structure need be allocated to it.

acc_freelist指向空闲的acc_t结构列表头,没有acc_buffer buf_t结构分配给它们。它是利用bf_dupacc返回一份原始acc_t结构的拷贝。因此acc_t结构存储了指向buf_t结构的指

针,bf_dupacc只是规定了指针buf_t结构在原来的缓冲区,并没有新的buf_t结构需要分配给它。
 
bf512_freelist points to the head of the free list of the acc_t structures which do have a acc_buffer buf_t structure allocated to them. It is used by bf_memreq.
bf512_freelist指向空闲的acc_t结构列表,确实有acc_buffer buf_t结构分配给它们。它被bf_memreq所使用。
 
bf_logon() defines the freereq array which is called when a freelist runs out of free acc_t structures.
bf_logon()定义freereq数组,当freelist用完空闲的acc_t结构被调用。

 
bf_bufsize(acc_ptr) returns the data size of the acc_t structure pointed to by acc_ptr. As mentioned before, the different buffers which belong to the different acc_t structures in the linked list linked together by the acc_next pointer are considered to store the same chunk of data. Accordingly in order to return the buffer size of acc_ptr it sums the buffer size (as determined by acc_length) of the linked list of acc_t structures where acc_ptr points to the head of list.
bf_bufsize ( acc_ptr )返回的数据大小acc_t结构所指向acc_ptr 。如前所述,不同的缓冲器属于不同acc_t结构链表联系在一起的acc_next指针被视为相同的块存储的数据。

因此,以恢复缓冲区大小的acc_ptr它总结缓冲区大小(所确定的acc_length )的链表结构的acc_t在acc_ptr指向列表头。

 
bf_memreq(size) returns a acc_t structure whose bf_bufsize is size. It calls freereq if there are not any free acc_t structures in the buf512_freelist free list.
bf_memreq (大小)返回一个acc_t结构,该结构中的bf_bufsize是size。如果没有任何空闲的acc_t结构,在buf512_freelist空闲列表中,它将调用freereq。
 
bf_afree(acc) frees a acc_t structure. If the buf_t structure acc_buffer is still being used by another acc_t structure, acc is put on the acc_freelist; else acc is put on the bf512_freelist.
bf_memreq (大小)返回一个acc_t结构的bf_bufsize是规模。它呼吁freereq如果没有任何自由acc_t结构buf512_freelist免费清单。

 

bf_dupacc(acc_ptr) returns a copy of the original acc_t structure pointed to by acc_ptr
bf_dupacc ( acc_ptr )返回一份拷贝acc_t结构所指向acc_ptr

bf_packIffLess(pack, min_len).
 
bf_pack(old_acc)
 
bf_cut(data, offset, length) returns a copy of the chunk of data starting with offset and ending at offset + length - 1.
 返回的副本:从数据块偏移开始,并offset + length - 1处结束。

 

bf_delhead (data, offset) returns a copy of the chunk of data starting with offset. It frees the original acc_t.
  返回的副本:从数据块偏移开始,并释放原acc_t.
 
bf_align(acc, size, alignment)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值