DESCRIPTION
Interface module for OSE messaging and process monitoring from Erlang
For each mailbox created through open/1 a OSE phantom process with that name is started. Since phantom processes are used the memory footprint of each mailbox is quite small.
To receive messages you first have to subscribe to the specific message numbers that you are interested in with listen/2. The messages will be sent to the Erlang process that created the mailbox.
DATA TYPES
-
- attach_ref():
-
-
Reference from an attach request. This term will be included in the term returned when the attached mailbox disappears.
-
- hunt_ref():
-
-
Reference from a hunt request. This term will be included in a successful hunt response.
-
- mailbox():
-
-
Mailbox handle. Implemented as an erlang port.
-
- mailbox_id():
-
-
Mailbox ID, this is the same as the process id of an OSE process. An integer.
-
- message_number() = 0..4294967295:
-
-
OSE Signal number
-
EXPORTS
attach(Port, Pid) -> Ref
-
Types:
-
Port = mailbox()
Pid = mailbox_id()
Ref = attach_ref()
-
Port = mailbox()
-
Attach to an OSE process.
Will send {mailbox_down, Port, Ref, MboxId} to the calling process if the OSE process exits.
Returns a reference that can be used to cancel the attachment using detach/2.
raises: badarg | enomem
close(Port) -> ok
-
Types:
-
Port = mailbox()
-
Port = mailbox()
-
Close a mailbox
This kills the OSE phantom process associated with this mailbox.
Will also consume any {'EXIT',Port,_} message from the port that comes due to the port closing when the calling process traps exits.
raises: badarg
dehunt(Port, Ref) -> ok
-
Types:
-
Port = mailbox()
Ref = hunt_ref()
-
Port = mailbox()
-
Stop hunting for OSE process.
If a message for this hunt has been sent but not received by the calling process, it is removed from the message queue. Note that this only works if the same process that did the hunt does the dehunt.
raises: badarg
See also: hunt/2.
detach(Port, Ref) -> ok
-
Types:
-
Port = mailbox()
Ref = attach_ref()
-
Port = mailbox()
-
Remove attachment to an OSE process.
If a message for this monitor has been sent but not received by the calling process, it is removed from the message queue. Note that this only works of the same process that did the attach does the detach.
raises: badarg
See also: attach/2.
get_id(Port) -> Pid
-
Types:
-
Port = mailbox()
Pid = mailbox_id()
-
Port = mailbox()
-
Get the mailbox id for the given port.
The mailbox id is the same as the OSE process id of the OSE phantom process that this mailbox represents.
raises: badarg
get_name(Port, Pid) -> Name | undefined
-
Types:
-
Port = mailbox()
Pid = mailbox_id()
Name = binary()
-
Port = mailbox()
-
Get the mailbox name for the given mailbox id.
The mailbox name is the name of the OSE process with process id Pid.
This call will fail with badarg if the underlying system does not support getting the name from a process id.
raises: badarg
hunt(Port, HuntPath) -> Ref
-
Types:
-
Port = mailbox()
HuntPath = iodata()
Ref = hunt_ref()
-
Port = mailbox()
-
Hunt for OSE process by name.
Will send {mailbox_up, Port, Ref, MboxId} to the calling process when the OSE process becomes available.
Returns a reference term that can be used to cancel the hunt using dehunt/2.
raises: badarg
listen(Port, SigNos) -> ok
-
Types:
-
Port = mailbox()
SigNos = [message_number()]
-
Port = mailbox()
-
Start listening for specified OSE signal numbers.
The mailbox will send {message,Port,{FromMboxId,ToMboxId,MsgNo,MsgData}} to the process that created the mailbox when an OSE message with any of the specified SigNos arrives.
Repeated calls to listen will replace the current set of signal numbers to listen to. i.e
1>ose:listen(MsgB,[1234,12345]). ok 2> ose:listen(MsgB,[1234,123456]). ok.
The above will first listen for signals with numbers 1234 and 12345, and then replace that with only listening to 1234 and 123456.
With the current implementation it is not possible to listen to all signal numbers.
raises: badarg | enomem
open(Name) -> Port
-
Types:
-
Name = iodata()
Port = mailbox()
-
Name = iodata()
-
Create a mailbox with the given name and return a port that handles the mailbox.
An OSE phantom process with the given name will be created that will send any messages sent through this mailbox. Any messages sent to the new OSE process will automatically be converted to an Erlang message and sent to the Erlang process that calls this function. See listen/2 for details about the format of the message sent.
The caller gets linked to the created mailbox.
raises: badarg | system_limit
See also: listen/2.
send(Port, Pid, SigNo, SigData) -> ok
-
Types:
-
Port = mailbox()
Pid = mailbox_id()
SigNo = message_number()
SigData = iodata()
-
Port = mailbox()
-
Send an OSE message.
The message is sent from the OSE process' own ID that is: get_id(Port).
raises: badarg
See also: send/5.
send(Port, Pid, SenderPid, SigNo, SigData) -> ok
-
Types:
-
Port = mailbox()
Pid = mailbox_id()
SenderPid = mailbox_id()
SigNo = message_number()
SigData = iodata()
-
Port = mailbox()
-
Send an OSE message with different sender.
As send/4 but the sender will be SenderPid.
raises: badarg
See also: send/4.
AUTHORS
<>