ose
Interface module for OSE messaging and process monitoring from Erlang.
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.
Functions
attach(Port, Pid) -> Ref
Port = mailbox()
Pid = mailbox_id()
Ref = attach_ref()
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
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
Port = mailbox()
Ref = hunt_ref()
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
Port = mailbox()
Ref = attach_ref()
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
Port = mailbox()
Pid = mailbox_id()
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
Port = mailbox()
Pid = mailbox_id()
Name = binary()
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
Port = mailbox()
HuntPath = iodata()
Ref = hunt_ref()
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
Port = mailbox()
SigNos = [message_number()]
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
Name = iodata()
Port = mailbox()
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
Port = mailbox()
Pid = mailbox_id()
SigNo = message_number()
SigData = iodata()
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.