“关闭”功能对 udp 套接字有什么影响?
int shutdown(int socket, int how);
Run Code Online (Sandbox Code Playgroud)
调用shutdown()UDP 套接字不会在线上执行任何操作,只会影响套接字对象的状态。
查看内核:
__sys_shutdown() 调用sock->ops->shutdown()套接字对象。ops是一个struct proto_ops。AF_INET),inet_stream_ops.shutdown设置为inet_shutdown。inet_shutdown是非常面向 TCP 的,有点棘手。但是,它会检查sk->sk_prot->shutdown并调用它是否为非 NULL。
sk_prot 指向一个struct proto:
struct proto tcp_prot 定义了一个.shutdown操作 ( tcp_shutdown)struct proto udp_prot 没有定义.shutdown