9
<holder>Ericsson AB, All Rights Reserved</holder>
7
<year>2001</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
26
24
<title>erl_driver</title>
807
793
<fsummary>Provide an event for having the emulator call the driver</fsummary>
809
795
<marker id="driver_select"></marker>
810
<p>The <c>driver_select</c> is used by the driver to
811
provide the emulator with an event to check for. This
812
enables the emulator to call the driver when something has
813
happened asynchronously.</p>
814
<p>The <c>event</c> parameter is used in the emulator cycle in
815
a <c>select</c> call. If the event is set then the driver is
816
called. The <c>mode</c> parameter can be either
817
<c>ON_READ</c> or <c>ON_WRITE</c>, and specifies whether
818
<seealso marker="driver_entry#ready_output">ready_output</seealso>
819
or <seealso marker="driver_entry#ready_input">ready_input</seealso>
820
will be called when the event is fired. Note that this is
821
just a convention, they don't have to read or write
823
<p>The <c>on</c> parameter should be <c>1</c> for adding the
824
event and <c>0</c> for removing it.</p>
825
<p>On Unix systems, the function <c>select</c> is used. The
826
<c>event</c> must be a socket or pipe (or other object that
827
<c>select</c> can use).</p>
828
<p>On windows, the Win32 API function
829
<c>WaitForMultipleObjects</c> is used. This places other
830
restriction on the <c>event</c>. Refer to the Win32 SDK
796
<p>This function is used by drivers to provide the emulator with
797
events to check for. This enables the emulator to call the driver
798
when something has happened asynchronously.</p>
799
<p>The <c>event</c> argument indentifies an OS-specific event object.
800
On Unix systems, the functions <c>select</c>/<c>poll</c> are used. The
801
event object must be a socket or pipe (or other object that
802
<c>select</c>/<c>poll</c> can use).
803
On windows, the Win32 API function <c>WaitForMultipleObjects</c>
804
is used. This places other restriction on the event object.
805
Refer to the Win32 SDK documentation.</p>
806
<p>The <c>on</c> parameter should be <c>1</c> for setting events
807
and <c>0</c> for clearing them.</p>
808
<p>The <c>mode</c> argument is bitwise-or combination of
809
<c>ERL_DRV_READ</c>, <c>ERL_DRV_WRITE</c> and <c>ERL_DRV_USE</c>.
810
The first two specifies whether to wait for read events and/or write
811
events. A fired read event will call
812
<seealso marker="driver_entry#ready_input">ready_input</seealso>
813
while a fired write event will call
814
<seealso marker="driver_entry#ready_output">ready_output</seealso>.
817
<p>Some OS (Windows) does not differ between read and write events.
818
The call-back for a fired event then only depends on the value of <c>mode</c>.</p>
820
<p><c>ERL_DRV_USE</c> specifies if we are using the event object or if we want to close it.
821
On an emulator with SMP support, it is not safe to clear all events
822
and then close the event object after <c>driver_select</c> has
823
returned. Another thread may still be using the event object
824
internally. To safely close an event object call
825
<c>driver_select</c> with <c>ERL_DRV_USE</c> and <c>on==0</c>. That
826
will clear all events and then call
827
<seealso marker="driver_entry#stop_select">stop_select</seealso>
828
when it is safe to close the event object.
829
<c>ERL_DRV_USE</c> should be set together with the first event
830
for an event object. It is harmless to set <c>ERL_DRV_USE</c>
831
even though it already has been done. Clearing all events but keeping
832
<c>ERL_DRV_USE</c> set will indicate that we are using the event
833
object and probably will set events for it again.</p>
835
<p>ERL_DRV_USE was added in OTP release R13. Old drivers will still work
836
as before. But it is recommended to update them to use <c>ERL_DRV_USE</c> and
837
<c>stop_select</c> to make sure that event objects are closed in a safe way.</p>
832
839
<p>The return value is 0 (Failure, -1, only if the
833
840
<c>ready_input</c>/<c>ready_output</c> is