开发者

Linux Kernel - Socket file descriptor close location

Where in开发者_StackOverflow中文版 the linux kernel does the closing of a socket's file descriptor occur? I know for a file, the file's file descriptor is closed in fs/open.cs function sys_close(). However, for a socket file descriptor, is this the same location or somewhere else?

Also, do sockets utilize the file.c alloc_fd to allocate the file descriptor or do they utilize some other function?


Yes, sys_close() is the entry point for closing all file descriptors, including sockets.

sys_close() calls filp_close(), which calls fput() on the struct file object. When the last reference to the struct file has been put, fput() calls the file object's .release() method, which for sockets, is the sock_close() function in net/socket.c.

The socket code uses get_unused_fd() and put_unused_fd() to acquire and release file descriptors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜