package bytesrw

  1. Overview
  2. Docs

Module Bytesrw_unixSource

Blocking Unix file descriptor byte stream readers and writers.

bytes_reader_of_fd fd reads bytes from the blocking fd with Unix.read and provides them as slices of maximal length slice_length (defaults to Bytesrw.Bytes.Slice.unix_io_buffer_size). Bytesrw.Bytes.Slice.eod is returned when Unix.read returns 0.

pos defaults to the fd position as determined by Unix.lseek. Reads are retried on Unix.error.EINTR but both this function and the resulting reader may raise Unix.Unix_error.

Note. The reader performs no ressource management. It is the client's duty to close the fd. It can be used on sockets.

bytes_writer_of_fd fd writes bytes to the blocking fd using Unix.single_write. The hinted slice_length defaults to Bytesrw.Bytes.Slice.unix_io_buffer_size. Writing Bytesrw.Bytes.Slice.eod only terminates the writer, it makes no effect on fd, it only terminates the writer.

pos defaults to the fd position as determined by Unix.lseek. Writes are retried on Unix.error.EINTR but both this function and the resulting writer may raise Unix.Unix_error.

Note. The writer performs no ressource management. It is the client's duty to close the fd. It can be used on sockets but bytes_writer_of_socket_fd may be a better fit.

Sourceval bytes_writer_of_socket_fd : ?pos:Bytesrw.Bytes.Stream.pos -> ?slice_length:Bytesrw.Bytes.Slice.length -> Unix.file_descr -> Bytesrw.Bytes.Writer.t

bytes_writer_of_socket_fd is like bytes_writer_of_fd except that when Bytesrw.Bytes.Slice.eod is written it calls Unix.shutdown with Unix.shutdown_command.SHUTDOWN_SEND and pos defaults to 0.