hangup.c 958 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #ifdef PLAN9PORT
  11. #include <sys/socket.h>
  12. #endif
  13. #include <libc.h>
  14. #include <venti.h>
  15. #include "queue.h"
  16. void
  17. vthangup(VtConn *z)
  18. {
  19. qlock(&z->lk);
  20. z->state = VtStateClosed;
  21. #ifdef PLAN9PORT
  22. /* try to make the read in vtrecvproc fail */
  23. shutdown(SHUT_WR, z->infd);
  24. shutdown(SHUT_WR, z->outfd);
  25. #endif
  26. if(z->infd >= 0)
  27. close(z->infd);
  28. if(z->outfd >= 0 && z->outfd != z->infd)
  29. close(z->outfd);
  30. z->infd = -1;
  31. z->outfd = -1;
  32. if(z->writeq)
  33. _vtqhangup(z->writeq);
  34. if(z->readq)
  35. _vtqhangup(z->readq);
  36. qunlock(&z->lk);
  37. }