当前位置:网站首页>Listen in the network
Listen in the network
2022-07-01 13:28:00 【To maintain world peace_】
listen Main work
Request and initialize the receive queue , Full connection receive queue and half receive queue
int __sys_listen(int fd, int backlog)
{
struct socket *sock;
int err, fput_needed;
int somaxconn;
// according to fd lookup socket Kernel object
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (sock) {
// Get the kernel somaxconn Parameters ;net.core.somaxconn, And backlog Take the small one
somaxconn = sock_net(sock->sk)->core.sysctl_somaxconn;
if ((unsigned int)backlog > somaxconn)
backlog = somaxconn;
err = security_socket_listen(sock, backlog);
if (!err)// Call protocol stack initialization listen
err = sock->ops->listen(sock, backlog);
fput_light(sock->file, fput_needed);
}
return err;
}backlog And in the system net.core.somaxconn Select a small kernel parameter
sock->ops->listen function
int inet_listen(struct socket *sock, int backlog)
{
struct sock *sk = sock->sk;
unsigned char old_state;
int err, tcp_fastopen;
// If it is listening , allows backlog Parameter adjustment , Set the full connection queue length
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
// No listen state , Enter listening
if (old_state != TCP_LISTEN) {
tcp_fastopen = sock_net(sk)->ipv4.sysctl_tcp_fastopen;
if ((tcp_fastopen & TFO_SERVER_WO_SOCKOPT1) &&
(tcp_fastopen & TFO_SERVER_ENABLE) &&
!inet_csk(sk)->icsk_accept_queue.fastopenq.max_qlen) {
fastopen_queue_tune(sk, backlog);
tcp_fastopen_init_key_once(sock_net(sk));
}
// Start listening
err = inet_csk_listen_start(sk, backlog);
if (err)
goto out;
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);
}
err = 0;
out:
release_sock(sk);
return err;
}Full connection queue structure
struct inet_connection_sock {
/* inet_sock has to be the first member! */
struct inet_sock icsk_inet;
struct request_sock_queue icsk_accept_queue;
...
}
struct request_sock_queue {
spinlock_t rskq_lock;
u8 rskq_defer_accept;
u32 synflood_warned;
atomic_t qlen;
atomic_t young;
// Full connection queue
struct request_sock *rskq_accept_head;
struct request_sock *rskq_accept_tail;
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
* if TFO is enabled.
*/
};int inet_csk_listen_start(struct sock *sk, int backlog)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct inet_sock *inet = inet_sk(sk);
int err = -EADDRINUSE;
//icsk_accept_queue Receiving queue
// Receive queue kernel object initialization
reqsk_queue_alloc(&icsk->icsk_accept_queue);
sk->sk_ack_backlog = 0;
inet_csk_delack_init(sk);
inet_sk_state_store(sk, TCP_LISTEN);
if (!sk->sk_prot->get_port(sk, inet->inet_num)) {
inet->inet_sport = htons(inet->inet_num);
sk_dst_reset(sk);
err = sk->sk_prot->hash(sk);
if (likely(!err))
return 0;
}
inet_sk_set_state(sk, TCP_CLOSE);
return err;
}
static inline void fastopen_queue_tune(struct sock *sk, int backlog)
{
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
// Semi connected queue length
queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn);
}summary :listen It mainly applies for work and initializes the receiving queue , Full connection receive queue and half receive queue
Full connection receive queue length
backlog And net.core.somaxconn Smaller value between
边栏推荐
- 5G工业网关的科技治超应用 超限超重超速非现场联合执法
- 华为HMS Core携手超图为三维GIS注入新动能
- Redis explores cache consistency
- How much money do novices prepare to play futures? Is agricultural products OK?
- Research Report on China's software outsourcing industry investment strategy and the 14th five year plan Ⓡ 2022 ~ 2028
- 基于mysql乐观锁实现秒杀的示例代码
- Function test process in software testing
- 商汤科技崩盘 :IPO时已写好的剧本
- Sharing with the best paper winner of CV Summit: how is a good paper refined?
- 1. Sum of two numbers: given an integer array num and an integer target value, please find the two integers whose sum is the target value target in the array and return their array subscripts
猜你喜欢

Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音

逆向调试入门-PE结构-输入表输出表05/07

Qtdeisgner, pyuic detailed use tutorial interface and function logic separation (nanny teaching)

1553B环境搭建

La taille de la pile spécifiée est petite, spécifiée à la sortie 328k

华为HMS Core携手超图为三维GIS注入新动能

Content Audit Technology

VM virtual machine configuration dynamic IP and static IP access

8 popular recommended style layout

【机器学习】VAE变分自编码器学习笔记
随机推荐
商汤科技崩盘 :IPO时已写好的剧本
String input function
Professor Li Zexiang, Hong Kong University of science and technology: I'm wrong. Why is engineering consciousness more important than the best university?
【机器学习】VAE变分自编码器学习笔记
The 14th five year plan of China's environmental protection industry and the report on the long-term goals for 2035 Ⓖ 2022 ~ 2028
Introduction to reverse debugging PE structure input table output table 05/07
Analysis report on production and marketing demand and investment forecast of global and Chinese diamond powder industry Ⓤ 2022 ~ 2027
Terminal identification technology and management technology
codeforces -- 4B. Before an Exam
Will it affect the original MySQL database to read the data of a MySQL table in full by flick MySQL CDC
Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
La taille de la pile spécifiée est petite, spécifiée à la sortie 328k
VM virtual machine configuration dynamic IP and static IP access
MySQL六十六问,两万字+五十图详解!复习必备
ArrayList扩容机制以及线程安全性
Mysql间隙锁
启动solr报错The stack size specified is too small,Specify at least 328k
【大型电商项目开发】性能压测-压力测试基本概念&JMeter-38
Anti fraud, refusing to gamble, safe payment | there are many online investment scams, so it's impossible to make money like this
1553B environment construction