concept driver in category erlang
appears as: drivers, driver

This is an excerpt from Manning's book Erlang and OTP in Action.
Figure 12.6. Reentrant linked-in driver code using only instance-specific data. Each instance of the driver has its own working memory and isn’t affected by the others.
![]()
You’ll typically allocate this memory in the initialization phase of the driver, but you may also allocate memory dynamically as needed. Erlang’s erl_driver API contains support functions such as driver_alloc() and driver_free() specially for managing memory in linked-in driver code.
Table 12.2. The available erl_driver callback functions. You implement only the ones that are needed for your driver and leave the rest as NULL.
Callback
Description
init Called at system start-up for statically linked drivers, and after loading for dynamically loaded drivers. start Called when open_port/2 is invoked. stop Called when the port is closed. output Called when output is available from some Erlang process to the port. Not used if the outputv callback is defined. ready_input Called when input is available from one of the driver’s handles. Used for asynchronous I/O. ready_output Called when output is possible to one of the driver’s handles. Used for asynchronous I/O. finish Called before the driver is unloaded. Only used for dynamically loaded drivers. control Like an ioctl for drivers. Called when port_control/3 is invoked from Erlang. timeout Called when one of the drivers’ timers triggers. outputv Called when someone writes to the port from Erlang. If this callback isn’t defined, the output callback is used instead to handle writes. ready_async Called after an asynchronous driver_async call has completed. flush Called when the port is about to be closed and data in the driver queue needs to be flushed before stop can be called. call Much like the control callback, but uses Erlang’s external term format for input and output. event Called when an event selected by driver_event() has occurred.