lib/libc/sys-minix/shutdown.c

http://www.minix3.org/ · C · 79 lines · 63 code · 13 blank · 3 comment · 24 complexity · 850dba0e441cfab86da1d07276daf5b3 MD5 · raw file

  1. #include <sys/cdefs.h>
  2. #include "namespace.h"
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <sys/ioctl.h>
  6. #include <sys/socket.h>
  7. #include <sys/un.h>
  8. #include <net/gen/in.h>
  9. #include <net/gen/tcp.h>
  10. #include <net/gen/tcp_io.h>
  11. #ifdef __weak_alias
  12. __weak_alias(shutdown, _shutdown)
  13. #endif
  14. #define DEBUG 0
  15. static int _tcp_shutdown(int sock, int how);
  16. static int _uds_shutdown(int sock, int how);
  17. int shutdown(int sock, int how)
  18. {
  19. int r;
  20. struct sockaddr_un uds_addr;
  21. nwio_tcpconf_t tcpconf;
  22. r= ioctl(sock, NWIOGTCPCONF, &tcpconf);
  23. if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
  24. {
  25. if (r == -1)
  26. {
  27. /* Bad file descriptor */
  28. return -1;
  29. }
  30. return _tcp_shutdown(sock, how);
  31. }
  32. r= ioctl(sock, NWIOGUDSADDR, &uds_addr);
  33. if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
  34. {
  35. if (r == -1)
  36. {
  37. /* Bad file descriptor */
  38. return -1;
  39. }
  40. return _uds_shutdown(sock, how);
  41. }
  42. #if DEBUG
  43. fprintf(stderr, "shutdown: not implemented for fd %d\n", sock);
  44. #endif
  45. errno= ENOSYS;
  46. return -1;
  47. }
  48. static int _tcp_shutdown(int sock, int how)
  49. {
  50. int r;
  51. if (how == SHUT_WR || how == SHUT_RDWR)
  52. {
  53. r= ioctl(sock, NWIOTCPSHUTDOWN, NULL);
  54. if (r == -1)
  55. return -1;
  56. if (how == SHUT_WR)
  57. return 0;
  58. }
  59. /* We can't shutdown the read side of the socket. */
  60. errno= ENOSYS;
  61. return -1;
  62. }
  63. static int _uds_shutdown(int sock, int how)
  64. {
  65. return ioctl(sock, NWIOSUDSSHUT, &how);
  66. }