Linux Kernel tracking sys_listen function notes-general Linux technology-Linux programming and kernel information. The following is a detailed description. /*
* AUTHOR: anhk
* DATE: 2007-5-24
* KERNEL: 2.6.20
*
* This is the note for learning the network part. It is rough and some reference counting code is removed.
* Some lock code
* The sys_socketcall [net/socket. c] function is the interrupt entry function of the entire network.
*/
Asmlinkage long sys_socketcall (int call, unsigned long _ user * args );
{
Unsigned long a [6];
/* Obtain information from the user space. This function is SMP secure */
If (copy_from_user (a, args, nargs [call])
Return-EFAULT;
Switch (call ){
Case SYS_SOCKET:
Err = sys_socket (a [0], a [1], a [2]);
Break;
Case SYS_BIND:
Err = sys_bind (a [0], (struct sockaddr _ user *) a [1], a [2]);
Break;
Case SYS_CONNECT:
Err = sys_connect (a [0], (struct sockaddr _ user *) a [1], a [2]);
Break;
....
}
}
/*
* The following describes the sys_listen function.
*
* This function first calls the sockfd_lookup_light function,
* Obtain the struct file * file structure with the descriptor Based on the descriptor, and then obtain the struct socket * sock structure based on the file structure.
* Get fd and backlog from user space
* Call the sock-> ops-> listen () function, which is inet_listen [net/ipv4/af_inet.c] in tcp.
* For udp, sock-> ops-> listen = sock_no_listen is returned directly.
*/
Asmlinkage long sys_listen (int fd, int backlog)
{
Struct socket * sock;
Int err, fput_needed;
/*
* In the inet_listen function, first determine whether the sock status is SS_UNCONNECTED and whether the type is SOCK_STREAM. If not, exit directly.
* Then judge whether the sock-> sk is in the listened status. If yes, set the backlog directly and exit.
* Otherwise, call inet_csk_listen_start [net/ipv4/inet_connection_sock.c].
*/
Int inet_listen (struct socket * sock, int backlog)
{
Struct sock * sk = sock-> sk;
Unsigned char old_state;
Int err;
/* Really, if the socket is already in listen state
* We can only allow the backlog to be adjusted.
*/
If (old_state! = TCP_LISTEN ){
Err = inet_csk_listen_start (sk, backlog );
If (err)
Goto out;
}
Sk-> sk_max_ack_backlog = backlog;
Err = 0;
Out:
Release_sock (sk );
Return err;
}
/*
* Inet_csk_listen_start [net/ipv4/inet_connection_sock.c]
* This function first calls reqsk_queue_alloc [net/core/request_sock.c] To apply for a piece of memory and store the listener queue for accept;
* Set the listening status and put the struct sock * sk into tcp_hashinfo.ehash.
*/
/*
* Set the listening status and determine whether the port is not used
* Add it to tcp_hashinfo.ehash.
* Return 0;
*/
Sk-> sk_state = TCP_LISTEN;
If (! Sk-> sk_prot-> get_port (sk, inet-> num )){
Inet-> sport = htons (inet-> num );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.