nopsession.c 843 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <fcall.h>
  5. #include "../boot/boot.h"
  6. static Fcall hdr;
  7. static void
  8. rpc(int fd, int type)
  9. {
  10. int n, l;
  11. char buf[128], *p;
  12. hdr.type = type;
  13. hdr.tag = NOTAG;
  14. n = convS2M(&hdr, buf);
  15. if(write(fd, buf, n) != n)
  16. fatal("write rpc");
  17. print("...");
  18. p = buf;
  19. l = 0;
  20. while(l < 3) {
  21. n = read(fd, p, 3);
  22. if(n <= 0)
  23. fatal("read rpc");
  24. if(n == 2 && l == 0 && buf[0] == 'O' && buf[1] == 'K')
  25. continue;
  26. p += n;
  27. l += n;
  28. }
  29. if(convM2S(buf, &hdr, n) == 0){
  30. print("%ux %ux %ux\n", buf[0], buf[1], buf[2]);
  31. fatal("rpc format");
  32. }
  33. if(hdr.tag != NOTAG)
  34. fatal("rpc tag not NOTAG");
  35. if(hdr.type == Rerror){
  36. print("error %s;", hdr.ename);
  37. fatal("remote error");
  38. }
  39. if(hdr.type != type+1)
  40. fatal("not reply");
  41. }
  42. void
  43. nop(int fd)
  44. {
  45. print("nop");
  46. rpc(fd, Tnop);
  47. }