hangup.c 547 B

12345678910111213141516171819202122232425262728293031
  1. #include <u.h>
  2. #ifdef PLAN9PORT
  3. #include <sys/socket.h>
  4. #endif
  5. #include <libc.h>
  6. #include <venti.h>
  7. #include "queue.h"
  8. void
  9. vthangup(VtConn *z)
  10. {
  11. qlock(&z->lk);
  12. z->state = VtStateClosed;
  13. #ifdef PLAN9PORT
  14. /* try to make the read in vtrecvproc fail */
  15. shutdown(SHUT_WR, z->infd);
  16. shutdown(SHUT_WR, z->outfd);
  17. #endif
  18. if(z->infd >= 0)
  19. close(z->infd);
  20. if(z->outfd >= 0 && z->outfd != z->infd)
  21. close(z->outfd);
  22. z->infd = -1;
  23. z->outfd = -1;
  24. if(z->writeq)
  25. _vtqhangup(z->writeq);
  26. if(z->readq)
  27. _vtqhangup(z->readq);
  28. qunlock(&z->lk);
  29. }