9 #include <sys/socket.h>
12 #include <net/gen/in.h>
13 #include <net/gen/tcp.h>
14 #include <net/gen/tcp_io.h>
18 static int _tcp_shutdown(int sock
, int how
);
19 static int _uds_shutdown(int sock
, int how
);
22 * Shut down socket send and receive operations.
25 __shutdown(int fd
, int how
)
29 memset(&m
, 0, sizeof(m
));
30 m
.m_lc_vfs_shutdown
.fd
= fd
;
31 m
.m_lc_vfs_shutdown
.how
= how
;
33 return _syscall(VFS_PROC_NR
, VFS_SHUTDOWN
, &m
);
36 int shutdown(int sock
, int how
)
39 struct sockaddr_un uds_addr
;
40 nwio_tcpconf_t tcpconf
;
42 r
= __shutdown(sock
, how
);
43 if (r
!= -1 || (errno
!= ENOTSOCK
&& errno
!= ENOSYS
))
46 r
= ioctl(sock
, NWIOGTCPCONF
, &tcpconf
);
47 if (r
!= -1 || errno
!= ENOTTY
)
51 /* Bad file descriptor */
54 return _tcp_shutdown(sock
, how
);
57 r
= ioctl(sock
, NWIOGUDSADDR
, &uds_addr
);
58 if (r
!= -1 || errno
!= ENOTTY
)
62 /* Bad file descriptor */
65 return _uds_shutdown(sock
, how
);
72 static int _tcp_shutdown(int sock
, int how
)
76 if (how
== SHUT_WR
|| how
== SHUT_RDWR
)
78 r
= ioctl(sock
, NWIOTCPSHUTDOWN
, NULL
);
85 /* We can't shutdown the read side of the socket. */
90 static int _uds_shutdown(int sock
, int how
)
92 return ioctl(sock
, NWIOSUDSSHUT
, &how
);