.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Podwrapper::Man 1.20.0 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "libnbd-ocaml 3" .TH libnbd-ocaml 3 2024-05-31 libnbd-1.20.0 LIBNBD .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME libnbd\-ocaml \- how to use libnbd from OCaml .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 5 \& let nbd = NBD.create () in \& NBD.connect_uri nbd "nbd://localhost"; \& let size = NBD.get_size nbd in \& printf "%Ld\en" size; \& NBD.close () .Ve .PP Alternate syntax which ensures that close is called even if an exception is thrown: .PP .Vb 7 \& let size = \& NBD.with_handle ( \& fun nbd \-> \& NBD.connect_uri nbd "nbd://localhost"; \& NBD.get_size nbd \& ) in \& printf "%Ld\en" size .Ve .PP To compile: .PP .Vb 1 \& ocamlopt \-I +nbd mlnbd.cmxa prog.ml \-o prog .Ve .PP or using findlib: .PP .Vb 1 \& ocamlfind opt \-package nbd \-linkpkg prog.ml \-o prog .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This manual page documents how to use libnbd to access Network Block Device (NBD) servers from the OCaml programming language. .PP The OCaml bindings work very similarly to the C bindings so you should start by reading \fBlibnbd\fR\|(3). .PP For OCaml API documentation see \fBNBD\fR\|(3). .SH HANDLES .IX Header "HANDLES" Create a libnbd handle of type \f(CW\*(C`NBD.t\*(C'\fR by calling \f(CW\*(C`NBD.create\ ()\*(C'\fR. .PP You can either close the handle explicitly by calling \f(CW\*(C`NBD.close\*(C'\fR or it will be closed automatically when it is garbage collected. If you call any other method on a handle which you have explicitly closed then the API will throw an \f(CW\*(C`NBD.Closed\*(C'\fR exception. .PP \&\f(CW\*(C`NBD.with_handle\*(C'\fR can be used to make sure the handle is closed in a timely manner. See the example in the "SYNOPSIS" above. .SH ERRORS .IX Header "ERRORS" Libnbd errors are turned automatically into exceptions of type: .PP .Vb 1 \& NBD.Error (str, Unix.error option) .Ve .PP The first exception parameter is a string which is the printable error message. The second is the OCaml \f(CW\*(C`Unix.error\*(C'\fR code, if available (see \fBnbd_get_errno\fR\|(3)). .SS "Callbacks with ""int ref"" error parameter" .IX Subsection "Callbacks with ""int ref"" error parameter" Some callbacks take an error parameter of type \f(CW\*(C`int ref\*(C'\fR, corresponding to the \f(CW\*(C`int *error\*(C'\fR passed to those callbacks in C. See also: "Callbacks with "int *error" parameter" in \fBlibnbd\fR\|(3) .PP If an error occurs during the callback you can update the \f(CW\*(C`int\*(C'\fR in the reference, setting it to a \fIC\-compatible errno\fR. To convert an OCaml \f(CW\*(C`Unix.error\*(C'\fR into a C\-compatible errno call \&\f(CW\*(C`NBD.errno_of_unix_error\*(C'\fR. .SH EXAMPLES .IX Header "EXAMPLES" This directory contains examples written in OCaml: .PP https://gitlab.com/nbdkit/libnbd/tree/master/ocaml/examples .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBlibnbd\fR\|(3), \fBNBD\fR\|(3). .SH AUTHORS .IX Header "AUTHORS" Richard W.M. Jones .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright Red Hat .SH LICENSE .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110\-1301 USA