1、网络数据发送流程
用户数据被拷贝到内核态,然后经过协议栈处理后进入到了 RingBuffer 中,随后网卡驱动真正将数据发送了出去。当发送完成的时候,是通过硬中断来通知 CPU,然后清理 RingBuffer。
2、代码层面流程图
以上流程图转载于 Yi lan
3、数据发送详解
3.1、首先需要建立socket
3.2、开始发送数据send
//code path: net/socket.c
/*
* BSD sendmsg interface
*/
SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags)
{
int fput_needed, err;
struct msghdr msg_sys;
struct socket *sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (!sock)
goto out;
err = __sys_sendmsg(sock, msg, &msg_sys, flags, NULL);
--> int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
--> static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
struct msghdr *msg, size_t size);
--> static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,
struct msghdr *msg, size_t size);
--> sock->ops->sendmsg(iocb, sock, msg, size); //实际执行的是 inet_sendmsg
fput_light(sock->file, fput