package async_unix

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

The Close module exists to collect close and its associated types, so they can be easily reused elsewhere, e.g., Unix_syscalls.

type socket_handling =
  1. | Shutdown_socket
  2. | Do_not_shutdown_socket
type file_descriptor_handling =
  1. | Close_file_descriptor of socket_handling
  2. | Do_not_close_file_descriptor
val close : ?file_descriptor_handling:file_descriptor_handling -> t -> unit Async_kernel.Deferred.t

close t prevents further use of t, and makes shutdown() and close() system calls on t's underlying file descriptor according to the file_descriptor_handling argument and whether or not t is a socket, i.e., kind t = Socket `Active:

        | file_descriptor_handling                     | shutdown() | close() |
        |----------------------------------------------+------------+---------|
        | Do_not_close_file_descriptor                 | no         | no      |
        | Close_file_descriptor Shutdown_socket        | if socket  | yes     |
        | Close_file_descriptor Do_not_shutdown_socket | no         | yes     |

The result of close becomes determined once the system calls complete. It is OK to call close multiple times on the same t; calls subsequent to the initial call will have no effect, but will return the same deferred as the original call.

val deregister : t -> unit Async_kernel.Deferred.t

deregister t causes Async to stop tracking this file descriptor, and prevents further use of t. The file descriptor remains open; it can be used by other libraries.

You should only call this function if you have a file descriptor created by Async and you need to move ownership of that file descriptor to another IO library which expects to be able to close the file descriptor itself. Otherwise, just use close.

This is like calling close with file_descriptor_handling set to Do_not_close_file_descriptor.

It is OK to call deregister multiple times on the same t, like close.

OCaml

Innovation. Community. Security.