博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
socket文件
阅读量:4152 次
发布时间:2019-05-25

本文共 1927 字,大约阅读时间需要 6 分钟。

static const struct file_operations socket_file_ops = {	.owner =	THIS_MODULE,	.llseek =	no_llseek,	.read_iter =	sock_read_iter,	.write_iter =	sock_write_iter,	.poll =		sock_poll,	.unlocked_ioctl = sock_ioctl,#ifdef CONFIG_COMPAT	.compat_ioctl = compat_sock_ioctl,#endif	.mmap =		sock_mmap,	.release =	sock_close,	.fasync =	sock_fasync,	.sendpage =	sock_sendpage,	.splice_write = generic_splice_sendpage,	.splice_read =	sock_splice_read,};
 
/* *	Obtains the first available file descriptor and sets it up for use. * *	These functions create file structures and maps them to fd space *	of the current process. On success it returns file descriptor *	and file struct implicitly stored in sock->file. *	Note that another thread may close file descriptor before we return *	from this function. We use the fact that now we do not refer *	to socket after mapping. If one day we will need it, this *	function will increment ref. count on file by 1. * *	In any case returned fd MAY BE not valid! *	This race condition is unavoidable *	with shared fd spaces, we cannot solve it inside kernel, *	but we take care of internal coherence yet. */struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname){	struct qstr name = { .name = "" };	struct path path;	struct file *file;	if (dname) {		name.name = dname;		name.len = strlen(name.name);	} else if (sock->sk) {		name.name = sock->sk->sk_prot_creator->name;		name.len = strlen(name.name);	}	path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name);	if (unlikely(!path.dentry))		return ERR_PTR(-ENOMEM);	path.mnt = mntget(sock_mnt);	d_instantiate(path.dentry, SOCK_INODE(sock));	file = alloc_file(&path, FMODE_READ | FMODE_WRITE,		  &socket_file_ops);	if (IS_ERR(file)) {		/* drop dentry, keep inode */		ihold(d_inode(path.dentry));		path_put(&path);		return file;	}	sock->file = file;	file->f_flags = O_RDWR | (flags & O_NONBLOCK);	file->private_data = sock;	return file;}

转载地址:http://ewhti.baihongyu.com/

你可能感兴趣的文章
C++中异常的处理方法以及使用了哪些关键字
查看>>
内存分配的形式有哪些? C++
查看>>
什么是内存泄露,如何避免内存泄露 C++
查看>>
栈和堆的空间大小 C++
查看>>
什么是缓冲区溢出 C++
查看>>
sizeof C++
查看>>
使用指针有哪些好处? C++
查看>>
引用还是指针?
查看>>
checkio-non unique elements
查看>>
checkio-medium
查看>>
checkio-house password
查看>>
checkio-moore neighbourhood
查看>>
checkio-the most wanted letter
查看>>
Redis可视化工具
查看>>
大牛手把手带你!2021新一波程序员跳槽季,全套教学资料
查看>>
Guava Collections API学习之AbstractMapBasedMultimap
查看>>
jQuery1.9(动画效果)学习之——.queue()
查看>>
HTML5学习之——概念篇
查看>>
HTML5学习之——HTML 5 视频
查看>>
HTML5学习之——HTML 5 Video + DOM
查看>>