【问题标题】:Is there a specification of the group leader protocol that handles IO?是否有处理 IO 的组长协议规范?
【发布时间】:2010-09-21 22:51:33
【问题描述】:

在 Erlang 中,每个进程都有一个组长,当一个进程想要打印一些东西时(即它调用 io 库或做类似的事情),它会向它的组长发送一条消息。

我的问题是,我在哪里可以找到这些消息的规范?或者一般来说,组长应该做什么的规范?

我通过一些实验设法发现,有时该进程会发送一个{io_request, Sender, GroupLeader, Request} 术语,而答案是一个{io_reply, GroupLeader, ok} 术语,但可能还有其他情况。

【问题讨论】:

    标签: erlang


    【解决方案1】:

    The Erlang Rationale (video) 或 (slides);是一个很好的信息来源,user.erl 的源代码也是如此。

    简而言之:

      {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}
    

    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)
    

    【讨论】:

      【解决方案2】:

      这里详细描述了 Erlang I/O 协议:

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

      【讨论】:

        猜你喜欢
        • 2017-05-01
        • 2018-11-13
        • 2015-12-21
        • 2019-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多