Pipe.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "pal.h"
  2. #include "pal_debug.h"
  3. #include "api.h"
  4. int main (int argc, char ** argv, char ** envp)
  5. {
  6. char buffer1[20] = "Hello World 1", buffer2[20] = "Hello World 2";
  7. char buffer3[20], buffer4[20];
  8. int ret;
  9. PAL_HANDLE pipe1 = DkStreamOpen("pipe.srv:1", PAL_ACCESS_RDWR, 0, 0, 0);
  10. if (pipe1) {
  11. pal_printf("Pipe Creation 1 OK\n");
  12. // DEP 10/24/16: Try to read some attributes of the pipe
  13. PAL_STREAM_ATTR attr;
  14. if (!DkStreamAttributesQueryByHandle(pipe1, &attr)) {
  15. pal_printf("Failed to get any attributes from the pipesrv\n");
  16. return -1;
  17. } else
  18. pal_printf("Pipe Attribute Query 1 on pipesrv returned OK\n");
  19. // DEP: would be nice to sanity check the attributes.
  20. // Job for another day...
  21. PAL_HANDLE pipe2 = DkStreamOpen("pipe:1", PAL_ACCESS_RDWR, 0, 0, 0);
  22. if (pipe2) {
  23. // DEP 10/24/16: We should also be able to wait for a connection
  24. // on this handle
  25. //PAL_HANDLE pipe3 = DkObjectsWaitAny(1, &pipe1, 0);
  26. PAL_HANDLE pipe3 = DkStreamWaitForClient(pipe1);
  27. if (pipe3) {
  28. pal_printf("Pipe Connection 1 OK\n");
  29. ret = DkStreamWrite(pipe3, 0, 20, buffer1, NULL);
  30. if (ret > 0)
  31. pal_printf("Pipe Write 1 OK\n");
  32. ret = DkStreamRead(pipe2, 0, 20, buffer3, NULL, 0);
  33. if (ret > 0)
  34. pal_printf("Pipe Read 1: %s\n", buffer3);
  35. ret = DkStreamWrite(pipe2, 0, 20, buffer2, NULL);
  36. if (ret > 0)
  37. pal_printf("Pipe Write 2 OK\n");
  38. ret = DkStreamRead(pipe3, 0, 20, buffer4, NULL, 0);
  39. if (ret > 0)
  40. pal_printf("Pipe Read 2: %s\n", buffer4);
  41. }
  42. }
  43. }
  44. return 0;
  45. }