socket流程
(af_inet udp)
数据结构
struct socket;
struct sock;
socket创建
socket()
sys_socket() --> kernel, socket.c
sock_create()
pf->create() --> net_families,sock_register(),Create a packet,struct sock.
socket接收
应用层调用recvfrom()
sys_recvfrom()
sock_recvmsg()
__sock_recvmsg()
sock->ops->recvmsg() --> 在socket被创建时赋值inet_dgram_ops.
sock_common_recvmsg()
sk->sk_prot->recvmsg() --> sk_prot在sk_alloc()中被赋值为udp_prot.
udp_recvmsg()
skb_recv_datagram() --> 检查等待sk->sk_receive_queue中的数据
自下而上往sk_receive_queue中填充数据
...... 这里省略
udp_rcv()
__udp4_lib_rcv()
__udp4_lib_lookup() --> 查找到对应的sock
udp_queue_rcv_skb()
sock_queue_rcv_skb() --> jump to sock.c
skb_queue_tail() --> add to sk->sk_receive_queue
socket发送
sys_sendto()
sock_sendmsg()
__sock_sendmsg()
sock->ops->sendmsg()
inet_sendmsg()
sk->sk_prot->sendmsg()
udp_sendmsg()
ip_route_output_flow() --> 交给路由,之后省略
阅读(1973) | 评论(0) | 转发(4) |