minix网络功能概述(2)

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

 

sr.c continued
 
[Expand here]
 
sr_rec handles the different types of messages passed to inet. We shall go through each of the types of messages it handles.
sr_rec处理inet的不同消息类型,接下来,我们来看看没种消息类型
 
A)        mq_t *m;
          case DEV_OPEN:
        result= sr_open(&m->mq_mess);
        send_reply= 1;
        free_mess= 1;
        break;
 
 
sr_open is called when a message to open is received. m is a pointer to a message item. mq_mess is the message. main passes a pointer to the message to

sr_open returns an index to the first unused entry in the sr_fd_table array. The sr_fd_table array is an array of sr_fd structures. The file descriptor

returned to the user process corresponds to an entry in the sr_fd_table array. The entry in the sr_fd_table array is marked as used (by setting the flag

SFF_INUSE ).

当收到一个打开的消息, 将会调用sr_open. m是指向消息的指针. mq_mess是收到的消息.  main函数将消息指针传给sr_open, sr_open返回数组sr_fd_table第一个未使用的索引号

,sr_fd_table数组是sr_fd结构的数组。返回给用户的文件描述符就是sr_fd_table数组的入口. 在数组sr_fd_table的项,被表示为使用状态(通过设定标志SFF_INUSE).

 

typedef struct sr_fd
{
    int srf_flags;
    int srf_fd;
    int srf_port;
    sr_open_t srf_open;
    sr_close_t srf_close;
    sr_write_t srf_write;
    sr_read_t srf_read;
    sr_ioctl_t srf_ioctl;
    sr_cancel_t srf_cancel;
    mq_t *srf_ioctl_q, *srf_ioctl_q_tail;
    mq_t *srf_read_q, *srf_read_q_tail;
    mq_t *srf_write_q, *srf_write_q_tail;
} sr_fd_t;
 
srf_flags: flags which describe state of sr_fd.
           描述 sr_fd状态的标志
srf_fd: is an index to the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
        协议层的端口表索引
srf_port: is an index in to the corresponding fd table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          协议层的fd标索引
srf_open: is a pointer to the open function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          打开协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_close: is a pointer to the close function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          关闭协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_write: is a pointer to the write function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          写协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_read: is a pointer to the read function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          读协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_ioctl: is a pointer to the ioctl function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          io控制协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_cancel: is a pointer to the cancel function of the corresponding port table for the protocol or layer (eg tcp, udp, ip, psip, etc.)
          cancel协议层端口表(如tcp, udp, ip, psip等) 的函数指针
srf_ioctl_q: is a pointer to the head of the linked list of ioctl messages which are waiting to be completed (and hence the process is suspended)
             指向待完成的ioctl消息链表头的指针
srf_ioctl_q_tail: is a pointer to the end of the linked list of ioctl messages which are waiting to be completed (and hence the process is suspended)
                  指向待完成的ioctl消息链表尾的指针
srf_read_q: is a pointer to the head of the linked list of read messages which are waiting to be completed (and hence the process is suspended)
             指向待完成的read消息链表头的指针
srf_read_q_tail: is a pointer to the end of the linked list of read messages which are waiting to be completed (and hence the process is suspended)
             指向待完成的read消息链表尾的指针
srf_write_q: is a pointer to the head of the linked list of write messages which are waiting to be completed (and hence the process is suspended)
             指向待完成的write消息链表头的指针
srf_write_q_tail: is a pointer to the end of the linked list of write messages which are waiting to be completed (and hence the process is suspended)
             指向待完成的write消息链表尾的指针

 

 

The values of certain elements of the sr_fd_table array are set in the initialization rountines (eg tcp_init(), udp_init(), ip_init()) as described above in

How minor devices relate to sr.c. In particular the initialization rountines set the values of the elements whose index is equal to the minor device number

of a protocol/layer (eg ip, tcp, udp, ethernet, psip, etc.). The initialization is done by calling sr_add_minor.

sr_fd_table数组的值都是在初始化rountines (例如tcp_init ( ) , udp_init ( ) , ip_init ( ) )时候设定的,如上所述的值在sr.c中同次设备号相关联. 特别指出

的是初始化rountines设定的值,等于议定层(如ip,TCP , UDP,以太网, psip等)的次设备号 。调用sr_add_minor完成初始化 。
 
sr_add_minor sets the fields of the sr_fd structure to the protocol specific values except for srf_flags and srf_port. srf_flags is used to store the state

of the sr_fd structure. srf_port is not set till sr_open is called. 
sr_add_minor设定sr_fd结构属性值,除srf_flags和srf_port 。 srf_flags是用来储存的sr_fd结构状态。 srf_port当sr_open被调用时设定。

 

Before sr_open marks the element in the sr_fd_table array is marked as used, it copies the entry in the sr_fd_table array with the index equal to the

requested minor number to the unused element. The element with the index equal to the requested minor number should have been initialized by sr_add_minor

during the initialization rountine. After being marked as used, the element in the sr_fd_table array calls the srf_open function of the element in the

sr_fd_table array. The srf_open function tells the protocol/layer what functions to calls when it needs to get/put data from/to the user process. It also

tells the protocol/layer the index to the sr_fd_table array. It returns an index to the fd table for the protocol/layer. The sr_fd field of the element in

the sr_fd_table array is set to the index of the fd table for the protocol/layer. sr_open then returns the index of the element in the sr_fd_table array. 
在调用sr_open标识sr_fd_table数组元素的标志之前,它复制sr_fd_table数组入口索引值,该值等于所请求的未使用的元素的次设备索引号。在调用sr_add_minor在初始化该值

。在被标记为使用标志之后,执行函数指针srf_open功能。srf_open的功能是告诉议定层,它需要 放置/获取 数据 从/到 用户进程。它还告诉议定层,该sr_fd_table阵列索引值

。它返回一个索引fd表的索引值。sr_fd_table阵列的数组元素sr_fd 被设定议定层fd表索引值。 sr_open然后返回sr_fd_table阵列元素的索引值。

 

The index of the element in the sr_fd_table array is ultimately returned to the user process by the fs process as follows. When the user process does an open

system call to inet, fs calls net_open in fs/device.c. When the index of the element in the sr_fd_table array is returned to fs, fs (in the function

net_open) replaces the minor device number of the protocol/layer with the index of the element in the sr_fd_table array.

sr_fd_table阵列元素的索引值最终被返回到用户进程. 当用户进程通过系统调用打开inet的时候,fs调用 fs/device.c中的net_open. 当sr_fd_table数组的索引值被返回给fs的

时候,fs将使用该值来替换协议层的次设备号.

 

inet returns the minor device number to fs by calling sr_reply. More generally, all replies to fs are done by calling sr_reply.
inet 通过系统调用sr_reply返回次设备号. 更通俗的讲,所有的给fs的应答都是通过sr_reply.
 
sr_reply sends a reply to the user process which originally sent the message to inet. It attempts to revive the user process.
sr_reply发送一个应答给用户进程,他也会唤醒用户进程.
 
B)   mq_t *m;
    case DEV_CLOSE:
        sr_close(&m->mq_mess);
        result= OK;
        send_reply= 1;
        free_mess= 1;
        break;
 
sr_close closes a file descriptor. The user process passes the index of the element in the sr_fd_table array which it wants to release and mark as unused.
sr_close 关闭文件描述符. 用户进程传送sr_fd_table数组的索引号来释放并标识为未使用.

 

sr_close calls the protocol/layer specific close function when it calls
sr_close通过调用协议层的具体close函数来实现.
 
    (*sr_fd->srf_close)(sr_fd->srf_fd);
 
Then it marks the element in the sr_fd_table array as free.
接着标示 sr_fd_table数组中的元素为空闲的.

C)    mq_t *m;
    case DEV_READ:
    case DEV_WRITE:
    case DEV_IOCTL:
        result= sr_rwio(m);
        assert(result == OK || result == SUSPEND);
        send_reply= (result == SUSPEND);
        free_mess= 0;
        break;
 
Each element of the sr_fd_table is called a channel.
 
sr_rwio(m) is called for read, writes, and ioctls. sr_rwio calls sr_getchannel to retrieve the element in the sr_fd_table (ie channel) with the index passed

as a parameter to inet. The index is passed in the minor device field of the message to inet. sr_rwio puts the message at the respective read/write/ioctl

queue. Although inet requires a user process may only make one read/write/ioctl request at a time, inet allows more than one user process to make such a

request for any one channel. If such a request is made while inet is busy processing another request for the same channel, sr_rwio puts the message (which

performs the request) at the end of the queue and suspends the user process. If no other request is being processed, sr_rwio empties the queue and the

message is put in to the queue. Whether or not inet is busy processing another request for the same channel is determined by checking the SFF_READ_IP,

SFF_WRITE_IP, SFF_IOCTL_IP flags. If inet is not busy processing another request for the same channel, inet calls the protocol/layer specific functions ie

sr_rwio(m)被read, writes, and ioctls调用。 sr_rwio调用sr_getchannel检索元素的sr_fd_table (即通道)与索引值作为参数传递给inet。该索引值是通过次设备号传递给

inet。 sr_rwio使信息在各自的read/write/ioctl队列。虽然Inet需要用户进程只作一次read/write/ioctl请求, 但Inet也允许多个用户进程提出这一请求,在任何一个通道。如

果这样的要求的同时,Inet正在忙于处理另一个要求相同的通道,sr_rwio使信息(其中执行请求)在队列尾并挂起用户进程。如果没有其他的要求正在处理中, sr_rwio清空队列

和信息是建立在队列中。无论繁忙的Inet是否处理的另一个要求相同的通道,确定会检查SFF_READ_IP , SFF_WRITE_IP , SFF_IOCTL_IP标志。如果不是繁忙的Inet处理的另一项

要求在同一通道, Inet调用协议/层的具体职能函数
 
    r= (*sr_fd->srf_read)(sr_fd->srf_fd, m->mq_mess.COUNT);
or
    r= (*sr_fd->srf_write)(sr_fd->srf_fd, m->mq_mess.COUNT);
or
    r= (*sr_fd->srf_ioctl)(sr_fd->srf_fd, request);

 
If the request cannot be completed SUSPEND is returned and the srf_flag for the channel is marked as suspended by setting the suspend flag SFF_READ_SUSP,

SFF_WRITE_SUSP, or SFF_IOCTL_SUSP. sr_rwio then returns a code to sr_rec telling sr_rec whether or not to suspend the user process. If sr_rec is told to

suspend the user process, sr_rec calls sr_reply to inform fs to suspend the user process. If sr_rec is not told to suspend the user process, sr_rec does not

call sr_reply because the protocol/layer specific functions should have already replied to the user process calling sr_put_userdata.

如果要求不能完成挂起返回和srf_flag的渠道是标示为暂停设定暂停旗SFF_READ_SUSP , SFF_WRITE_SUSP ,或SFF_IOCTL_SUSP 。 sr_rwio然后返回一个代码sr_rec告诉sr_rec是

否暂停用户进程。如果说sr_rec是暂停用户的进程, sr_rec呼吁sr_reply通知,暂停财政司司长
用户进程。如果不告诉sr_rec暂停用户进程, sr_rec并不要求sr_reply因为协议/层具体职能应该已经回答了用户进程要求sr_put_userdata.the协议/层的具体职能
 
For an ioctl call, you can return an integer result to the user either by calling sr_put_userdata(x, y, 0, 1) or sr_get_userdata(x, y, 0, 1)
对于一个ioctl调用,要么是通过调用sr_put_userdata(x, y, 0, 1)或者调用sr_get_userdata(x, y, 0, 1)返回一个整型值给用户.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值