Module Uwt.Pipe

module Pipe: sig .. end

Pipe handles provide an abstraction over local domain sockets on Unix and named pipes on Windows.

type t 
include Uwt.Stream
include Uwt.Handle_ext
include Uwt.Handle_fileno
val to_stream : t -> Uwt.Stream.t
val init : ?ipc:bool -> unit -> t

The only thing that can go wrong, is memory allocation. In this case the ordinary exception Out_of_memory is thrown. The function is not called init_exn, because this exception can be thrown by nearly all functions.

ipc : is false by default
val openpipe : ?ipc:bool -> Unix.file_descr -> t uv_result

Be careful with open* functions. They exists, so you can re-use system dependent libraries. But if you pass a file descriptor to openpipe (or opentcp,...), that is not really a file descriptor of a pipe (or tcp socket,...) you can trigger assert failures inside libuv.

ipc : is false by default
val openpipe_exn : ?ipc:bool -> Unix.file_descr -> t
val bind : t -> path:string -> Int_result.unit

Bind the pipe to a file path (Unix) or a name (Windows).

val bind_exn : t -> path:string -> unit
val getsockname : t -> string uv_result

Get the name of the Unix domain socket or the named pipe.

val getsockname_exn : t -> string
val getpeername : t -> string uv_result

Get the name of the Unix domain socket or the named pipe to which the handle is connected.

val getpeername_exn : t -> string
val pending_instances : t -> int -> Int_result.unit

Set the number of pending pipe instance handles when the pipe server is waiting for connections.

Note: This setting applies to Windows only.

val pending_instances_exn : t -> int -> unit
val accept : t -> t uv_result

initializes a new client, accepts and returns it.

This call is used in conjunction with listen to accept incoming connections. Call this function after receiving a listen callback to accept the connection.

When the listen callback is called it is guaranteed that this function will complete successfully the first time. If you attempt to use it more than once, it may fail. It is suggested to only call this function once per listen callback call.

Don't use this function for pipes that have been initialized with ~ipc:true. It's not portable.

val accept_exn : t -> t
val accept_raw : server:t -> client:t -> Int_result.unit
val accept_raw_exn : server:t -> client:t -> unit
val pending_count : t -> Int_result.int
val pending_count_exn : t -> int

how many handles are waiting to be accepted with Uwt.Pipe.accept_ipc

type ipc_result = 
| Ipc_error of error (*

internal call to accept failed

*)
| Ipc_none (*

no pending handles

*)
| Ipc_tcp of Uwt.Tcp.t
| Ipc_udp of Uwt.Udp.t
| Ipc_pipe of t
val accept_ipc : t -> ipc_result

Used to receive handles over IPC pipes.

It call's Uwt.Pipe.pending_count, if it's > 0 then it initializes a handle of the appropriate type, accepts and returns it

val write2 : ?pos:int ->
?len:int -> buf:bytes -> send:Uwt.Tcp.t -> t -> unit Lwt.t

Extended write function for sending handles over a pipe. The pipe must be initialized with ~ipc:true.

Note: send_handle must be a TCP socket or pipe, which is a server or a connection (listening or connected state). Bound sockets or pipes will be assumed to be servers.

val write2_ba : ?pos:int -> ?len:int -> buf:buf -> send:Uwt.Tcp.t -> t -> unit Lwt.t
val write2_string : ?pos:int ->
?len:int -> buf:string -> send:Uwt.Tcp.t -> t -> unit Lwt.t
val write2_pipe : ?pos:int ->
?len:int -> buf:bytes -> send:t -> t -> unit Lwt.t

Similar to Uwt.Pipe.write2, but the send handle is a pipe. Note: This is not supported on Windows

val write2_pipe_ba : ?pos:int ->
?len:int -> buf:buf -> send:t -> t -> unit Lwt.t
val write2_pipe_string : ?pos:int ->
?len:int -> buf:string -> send:t -> t -> unit Lwt.t
val write2_udp : ?pos:int ->
?len:int -> buf:bytes -> send:Uwt.Udp.t -> t -> unit Lwt.t

Similar to Uwt.Pipe.write2, but the send handle is an udp socket. Note: This is not portable at all

val write2_udp_ba : ?pos:int -> ?len:int -> buf:buf -> send:Uwt.Udp.t -> t -> unit Lwt.t
val write2_udp_string : ?pos:int ->
?len:int -> buf:string -> send:Uwt.Udp.t -> t -> unit Lwt.t
val connect : t -> path:string -> unit Lwt.t

Connect to the Unix domain socket or the named pipe.

val with_pipe : ?ipc:bool -> (t -> 'a Lwt.t) -> 'a Lwt.t

with_pipe ?ipc f creates a new handle and passes the pipe to f. It is ensured that the pipe is closed when f t terminates (even if it fails).

You can also close the pipe manually inside f without further consequences.

val with_connect : path:string -> (t -> 'a Lwt.t) -> 'a Lwt.t
val with_open : ?ipc:bool -> Unix.file_descr -> (t -> 'a Lwt.t) -> 'a Lwt.t
type chmod = 
| Pipe_readable
| Pipe_writeable
| Pipe_readable_writeable
val chmod : t -> chmod -> Int_result.unit

Alters pipe permissions, allowing it to be accessed from processes run by different users. Makes the pipe writable or readable by all users. This function is blocking.

val chmod_exn : t -> chmod -> unit