The
This is a large reference document. For casual use of the
module, as well as for most real world applications, the
descriptions of the functions
The driver should be provided as a dynamically linked library
in a object code format specific for the platform in use,
i. e.
When describing a set of functions, (i.e. a module, a part of a module or an application) executing in a process and wanting to use a ddll-driver, we use the term user. There can be several users in one process (different modules needing the same driver) and several processes running the same code, making up several users of a driver. In the basic scenario, each user loads the driver before starting to use it and unloads the driver when done. The reference counting keeps track of processes as well as the number of loads by each process, so that the driver will only be unloaded when no one wants it (it has no user). The driver also keeps track of ports that are opened towards it, so that one can delay unloading until all ports are closed or kill all ports using the driver when it is unloaded.
The interface supports two basic scenarios of loading and unloading. Each scenario can also have the option of either killing ports when the driver is unloading, or waiting for the ports to close themselves. The scenarios are:
This (most common) scenario simply supports that each
Each
Two pairs of functions support this scenario:
When using the
If a process having the driver loaded dies, it will have the same effect as if unloading was done.
When loading, the function
These interfaces is intended to be used when it is considered an
error that ports are open towards a driver that no
The function names
This scenario occurs when the driver code might need
replacement during operation of the Erlang
emulator. Implementing driver code replacement is somewhat
more tedious than beam code replacement, as one driver
cannot be loaded as both "old" and "new" code. All
The actual unloading/loading is done as one atomic operation, blocking all processes in the system from using the driver concerned while in progress.
The preferred way to do driver code replacement is to let
one single process keep track of the driver. When
the process start, the driver is loaded. When replacement
is required, the driver is reloaded. Unload is probably never
done, or done when the process exits. If more than one
Demanding reload when a reload is already in progress is
always an error. Using the high level functions, it is also
an error to demand reloading when more than one
The two functions for reloading drivers should be used together with corresponding load functions, to support the two different behaviors concerning open ports:
This pair of functions is used when reloading should be done after the last open port towards the driver is closed.
As
This pair of functions are used when open ports towards
the driver should be killed with reason
If, however, another process has the driver loaded,
calling
Removes a driver monitor in much the same way as
The function throws a
Returns a list of tuples
Returns a list of tuples
The different tags that will appear in the list are:
For a detailed description of each value, please read the
description of
The function throws a
This function returns specific information about one aspect
of a driver. The
Return all processes containing
Return a list of the driver options provided when
loading, as well as any options set by the driver itself
during initialization. The currently only valid option
being
Return the number of ports (an
Return a
Return a
Return a list of all processes having monitors for
Return a list of all processes having monitors for
If the options
The function throws a
Loads and links the dynamic driver
The
If the driver has been previously unloaded, but is still
present due to open ports against it, a call to
If more than one process tries to load an already loaded
driver withe the same
It is not allowed to load
several drivers with the same name but with different
Note especially that the
On success, the function returns
For more control over the error handling, again use the
The function throws a
Works essentially as
The number of loads and unloads by different
This interface (or at least the name of the functions) is
kept for backward compatibility. Using
The function throws a
This function creates a driver monitor and works in many
ways as the function
As with process monitors, each driver monitor set will only
generate one single message. The monitor is
"destroyed" after the message is sent and there is then no
need to call
The
The function accepts the following parameters:
The monitor tag is always
The
Notify me when the driver is reloaded (or loaded if
loading is underway). It only makes sense to monitor
drivers that are in the process of being loaded or
reloaded. One cannot monitor a future-to-be driver
name for loading, that will only result in a
Setting a driver monitor for
This message is sent, either immediately if the driver is already loaded and no reloading is pending, or when reloading is executed if reloading is pending.
The
This message will be sent if reloading was expected, but the (old) driver made itself permanent prior to reloading. It will also be sent if the driver was permanent or statically linked in when trying to create the monitor.
This message will arrive if reloading was
underway, but the
This message will arrive if reloading was
underway but the loading for some reason
failed. The
Monitor when a driver gets unloaded. If one monitors a driver that is not present in the system, one will immediately get notified that the driver got unloaded. There is no guarantee that the driver was actually ever loaded.
A driver monitor for unload will eventually result in one of the following messages being sent:
The driver instance monitored is now
unloaded. As the unload might have been due to a
This message will be sent if unloading was
expected, but while the driver was waiting for
all ports to get closed, a new
This message appears when an
If one wants to really monitor when the
driver gets unloaded, this message will distort
the picture, no unloading was really done.
The
This message will be sent if unloading was expected, but the driver made itself permanent prior to unloading. It will also be sent if trying to monitor a permanent or statically linked in driver.
A monitor created as
The function throws a
Reloads the driver named
If there are other
Avoid mixing
several
If one wants to avoid hanging on open ports, one should use
the
The
Avoid mixing
several
On success, the function returns
For more control over the error handling, again use the
The function throws a
Works exactly as
As this interface implies that ports are being killed when the last user disappears, the function wont hang waiting for ports to get closed.
For further details, see the
The function throws a
This function provides more control than the
The driver was actually loaded and is immediately usable.
The driver was already loaded by another process
and/or is in use by a living port. The load by you is
registered and a corresponding
The load request is registered, but the loading is
delayed due to the fact that an earlier instance of the
driver is still waiting to get unloaded (there are open
ports using it). Still, unload is expected when you are
done with the driver. This return value will
mostly happen when the
The load request is registered, but the loading is
delayed due to the fact that an earlier instance of the
driver is still waiting to get unloaded by another
When the function returns
When monitoring is requested, and a corresponding
Note that in case of loading, monitoring can
not only get triggered by using the
The function accepts the following parameters:
The filesystem path to the directory where the driver
object file is situated. The filename of the object file
(minus extension) must correspond to the driver name
(used in the name parameter) and the driver must
identify itself with the very same name. The
The (possibly flattened)
The name parameter is the name of the driver to be used
in subsequent calls to
A number of options can be specified to control the loading operation. The options are given as a list of two-tuples, the tuples having the following values and meanings:
This option is to provide options that will change it's general behavior and will "stick" to the driver throughout it's lifespan.
The driver options for a given driver name need always to be consistent, even when the driver is reloaded, meaning that they are as much a part of the driver as the actual name.
Currently the only allowed driver option is
A
Only one
If reloading is not requested, it might still be
useful to specify the
This option is used when one wants to
reload a driver from disk, most often in a
code upgrade scenario. Having a
To reload a driver, the process needs to have previously
loaded the driver, i.e there has to be an active
The
The more useful option is
If the driver is unloaded (not present in the
system), the error code
The function might return numerous errors, of which some only can be returned given a certain combination of options.
A number of errors are opaque and can only be interpreted by
passing them to the
The driver with the specified name is an erlang statically linked in driver, which cannot be manipulated with this API.
The driver has already been loaded with either other
This can happen even if a
The driver has requested itself to be permanent, making it behave like an erlang linked in driver and it can no longer be manipulated with this API.
The driver is loaded by other
Driver reload is already requested by another
Appears when the
Appears when the
All other error codes are to be translated by the
If the arguments or options are malformed, the function will
throw a
This is the low level function to unload (or decrement
reference counts of) a driver. It can be used to force port
killing, in much the same way as the driver option
Unloading can be described as the process of telling the
emulator that this particular part of the code in this
particular process (i.e. this
To allow the
The possible monitor messages that can be expected are the
same as when using the
The function will return one of the following statuses upon success:
The driver was immediately unloaded, meaning that the driver name is now free to use by other drivers and, if the underlying OS permits it, the memory occupied by the driver object code is now reclaimed.
The driver can only be unloaded when there are no open
ports using it and there are no more
This return value indicates that this call removed the
last
This return value is valid even when the option
The unload request is registered, but there are still
other
This is a normal, healthy return value if the call was
just placed to inform the emulator that you have no
further use of the driver. It is actually the most
common return value in the most common
The function accepts the following parameters:
The name parameter is the name of the driver to be
unloaded. The name can be specified either as an
The
Force killing of all ports opened using this driver,
with the exit reason
If there are other
If one wants the consistent behavior of killing ports
when the last
This option creates a driver monitor if the condition
given in
Create a driver monitor if the return value is to
be
Create a monitor if the return value will be either
The
By using the monitor-triggers in the call to
The function may return several error conditions, of which all are well specified (no opaque values):
You were trying to unload an erlang statically linked in driver, which cannot be manipulated with this interface (and cannot be unloaded at all).
The driver
The driver
As a special case, drivers can be unloaded from
processes that has done no corresponding call to
The driver has made itself permanent, in which case it can no longer be manipulated by this interface (much like a statically linked in driver).
The function throws a
Unloads, or at least dereferences the driver named
If there are other
The
The function throws a
Unloads, or at least dereferences the driver named
If there are other
The
The function throws a
Returns a list of all the available drivers, both (statically) linked-in and dynamically loaded ones.
The driver names are returned as a list of strings rather than a list of atoms for historical reasons.
More information about drivers can be obtained using one of
the
Takes an
Due to peculiarities in the dynamic loading interfaces on different platform, the returned string is only guaranteed to describe the correct error if format_error/1 is called in the same instance of the erlang virtual machine as the error appeared in (meaning the same operating system process)!
erl_driver(4), driver_entry(4)