Apr 09

一个RPC程序所要做的工作就是: 读取请求, 处理请求, 返回响应. 以nfsd为例, 其实现代码如下所示. 处理请求和返回响应放在同一个函数svc_process()里.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* in fs/nfsd/nfssvc.c: nfsd() */
 
struct svc_rqst *rqstp = (struct svc_rqst *) vrqstp;
...
/*
 * The main request loop
 */
for (;;) {
	/*
	 * Find a socket with data available and call its
	 * recvfrom routine.
	 */
	while ((err = svc_recv(rqstp, 60*60*HZ)) == -EAGAIN)
		;
	if (err == -EINTR)
		break;
	else if (err < 0) {
		if (err != preverr) {
			printk(KERN_WARNING "%s: unexpected error "
				"from svc_recv (%d)\n", __func__, -err);
			preverr = err;
		}
		schedule_timeout_uninterruptible(HZ);
		continue;
	}
 
	update_thread_usage(atomic_read(&nfsd_busy));
	atomic_inc(&nfsd_busy);
 
	/* Lock the export hash tables for reading. */
	exp_readlock();
 
	svc_process(rqstp);
 
	/* Unlock export hash tables */
	exp_readunlock();
	update_thread_usage(atomic_read(&nfsd_busy));
	atomic_dec(&nfsd_busy);
}

svc_recv()接受结构体svc_rqst的指针作为参数, 如果正常返回, svc_rqst包含了RPC请求报文的字节数组. svc_rqst的内存是在svc_recv()进进行分配.

Related posts:

  1. svc_recv函数实现详解
  2. sunrpc 函数功能分析
  3. svc_process函数
  4. 如何为Linux生成和打上patch
  5. C语言网络程序惯用法-参数传递

Written by benegg at 2009-04-09 16:50:50 | Views: 7886 | tags: ,

One Response to “RPC程序的一般结构 – nfsd”

  1. 1. benegg blog - svc_recv函数实现详解 Says:

    [...] RPC程序的一般结构 – nfsd 讲到了 RPC [...]

Pages:

Leave a Reply

必须登录, 或者浏览器开启JavaScript支持才可以评论!