Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a specification of the group leader protocol that handles IO?

Tags:

erlang

In Erlang, every process has a group leader, and when a process wants to print something (i.e. it calls the io library or does something similar), it will send a message to its group leader.

My question is, where can I find the specification of these messages? Or in general, the specification of what a group leader should do?

I managed to find out with some experimenting that sometimes the process sends an {io_request, Sender, GroupLeader, Request} term, and the answer is an {io_reply, GroupLeader, ok} term, but there may be other cases.

like image 445
hcs42 Avatar asked Nov 12 '08 08:11

hcs42


2 Answers

The Erlang Rationale (video) or (slides); is a good source of information, as is the source code for user.erl.

In short:

  {io_request, From, ReplyAs, Request}
  %From is the process to send the reply to, 
  %ReplyAs is any term the caller desires to 
  %match up the request and the response. (returned verbatim in the reply)
  {io_reply, ReplyAs, Reply}

Some requests in user.erl:

 {put_chars, IoList} % puts the iolist
 {put_chars, M,F,A} % puts the result of apply(M,F,A)
 {get_geometry, 'rows' | 'columns'} % returns the number of rows or columns of the console
 {get_line, Prompt} % calls io_lib:collect_line(Prompt)
 {get_chars, Prompt, Mod, Func, ExtraArgs} 
 {get_until, Prompt, Mod, Func, Args}
 {setopts, Options} % only option supported by user is 'binary' 
                    % (binary mode if present in Options, list mode otherwise)
like image 65
archaelus Avatar answered Oct 13 '22 18:10

archaelus


The Erlang I/O protocol is described in detail here:

http://www.erlang.org/doc/apps/stdlib/io_protocol.html

like image 22
luksan Avatar answered Oct 13 '22 18:10

luksan