关于RPC 路由器的实现主要分布在smd_rpcrouterc、smd_rpcrouter_devicec、smd_rpcrouter_serversc、smd_rpcrouter_clientsc等文件中。RPC路由器起着RPC服务器查询、RPC服务器和RPC客户端的注册和销毁,以及底层通信的封装功能,类似于TCP协议。
在实际的实现中,RPC路由器和RPC服务器均是作为一个虚拟的字符型设备来存在的。
下面是RPC路由器的创建过程:
代码3-11 RPC 路由器的创建过程
int msm_rpcrouter_init_devices(void)
{
int rc;
int major;
msm_rpcrouter_class=class_create(THIS_MODULE,
"oncrpc"); //创建设备节点
if (IS_ERR(msm_rpcrouter_class)) {
rc=-ENOMEM;
printk(KERN_ERR
"rpcrouter: failed to create oncrpc class\n");
goto fail;
}
rc=alloc_chrdev_region(&msm_rpcrouter_devno,
0, //作为字符型设备分配资源
RPCROUTER_MAX_REMOTE_SERVERS + 1, "oncrpc");
if (rc<0) {
printk(KERN_ERR
"rpcrouter: Failed to alloc chardev region (%d)\n", rc);
goto fail_destroy_class;
}
major=MAJOR(msm_rpcrouter_devno);
rpcrouter_device=device_create(msm_
rpcrouter_class, NULL, //创建设备
msm_rpcrouter_devno, NULL, "%8x:%d",
0, 0);
if (IS_ERR(rpcrouter_device)) {
rc=-ENOMEM;
goto fail_unregister_cdev_region;
}
cdev_init(&rpcrouter_cdev, &rpcrouter_
router_fops); //字符型设备初始化
rpcrouter_cdevowner=THIS_MODULE;
rc=cdev_add(&rpcrouter_cdev, msm_rpcrouter_devno, 1);
if (rc<0)
goto fail_destroy_device;
return 0;
fail_destroy_device:
device_destroy(msm_rpcrouter_class,
msm_rpcrouter_devno);//销毁设备
fail_unregister_cdev_region:
unregister_chrdev_region(msm_rpcrouter_devno, //去注册
RPCROUTER_MAX_REMOTE_SERVERS + 1);
fail_destroy_class:
class_destroy(msm_rpcrouter_class);
fail:
return rc;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)