Pipe.hx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package eval.luv;
  2. enum abstract PipeMode(Int) {
  3. var READ = 0;
  4. var WRITE = 1;
  5. var READ_WRITE = 2;
  6. }
  7. enum ReceiveHandle {
  8. NONE;
  9. TCP(associate:(tcp:Tcp)->Result<Result.NoData>);
  10. PIPE(associate:(pipe:Pipe)->Result<Result.NoData>);
  11. }
  12. /**
  13. Pipes
  14. @see https://aantron.github.io/luv/luv/Luv/Pipe
  15. **/
  16. @:using(eval.luv.Handle)
  17. @:using(eval.luv.Stream)
  18. @:coreType abstract Pipe to Handle to Stream to Stream.TStream<Pipe> to Handle.SocketHandle {
  19. /**
  20. Allocates and initializes a pipe.
  21. The pipe is not yet connected to anything at this point.
  22. The handle should be cleaned up with `eval.luv.Handle.close` when no longer needed.
  23. **/
  24. static public function init(loop:Loop, forHandlePassing:Bool = false):Result<Pipe>;
  25. /**
  26. Assigns a pipe a name or an address.
  27. **/
  28. public function bind(nameOrAddress:NativeString):Result<Result.NoData>;
  29. /**
  30. Connects to the pipe at the given name or address.
  31. **/
  32. public function connect(target:NativeString, callback:(result:Result<Result.NoData>)->Void):Void;
  33. /**
  34. Retrieves the name or address assigned to the pipe.
  35. **/
  36. public function getSockName():Result<NativeString>;
  37. /**
  38. Retrieves the name or address of the pipe's peer.
  39. **/
  40. public function getPeerName():Result<NativeString>;
  41. /**
  42. Set the number of pending pipe instance handles when the pipe server is
  43. waiting for connections.
  44. **/
  45. public function pendingInstances(amount:Int):Void;
  46. /**
  47. Receives a file descriptor over the given pipe.
  48. File descriptors are sent using the `sendHandle` argument of `eval.luv.Stream.write2`.
  49. On the receiving end, call `eval.luv.Stream.readStart`. When that function
  50. calls its callback, there may be file descriptors in the pipe, in addition
  51. to the ordinary data provided to the callback.
  52. To check, call this function `eval.luv.Pipe.recieveHandle` in a loop until
  53. it returns `NONE`. Each time it returns `TCP(associate)` or `PIPE(associate)`,
  54. create an appropriate handle using either `eval.luv.TCP.init` or `eval.uv.Pipe.init`,
  55. and call `associate` to receive the file descriptor and associate it with handle.
  56. **/
  57. public function receiveHandle():ReceiveHandle;
  58. /**
  59. Sets pipe permissions.
  60. **/
  61. public function chmod(mode:PipeMode):Result<Result.NoData>;
  62. }