<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cref SYSTEM "cref.dtd">

<cref>
  <header>
    <copyright>
      <year>1998</year><year>2020</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>ei_global</title>
    <prepared>Gordon Beaton</prepared>
    <responsible>Gordon Beaton</responsible>
    <docno></docno>
    <approved>Gordon Beaton</approved>
    <checked>Gordon Beaton</checked>
    <date>1998-07-03</date>
    <rev>A</rev>
    <file>ei_global.xml</file>
  </header>
  <lib>ei_global</lib>
  <libsummary>Access globally registered names.</libsummary>
  <description>
    <p>This module provides support for registering, looking
      up, and unregistering names in the <c>global</c> module.
      For more information, see
      <seeerl marker="kernel:global"><c>kernel:global</c></seeerl>.</p>

    <p>Notice that the functions below perform an RPC using an open file
      descriptor provided by the caller. This file descriptor must
      not be used for other traffic during the global operation, as the
      function can then receive unexpected data and fail.</p>
  </description>

  <funcs>
    <func>
      <name since=""><ret>char **</ret><nametext>ei_global_names(ec,fd,count)</nametext></name>
      <fsummary>Obtain list of global names.</fsummary>
      <type>
        <v><seecref marker="ei_connect#ei_cnode"><c>ei_cnode</c></seecref> *ec;</v>
        <v>int fd;</v>
        <v>int *count;</v>
      </type>
      <desc>
        <p>Retrieves a list of all known global names.</p>
        <list type="bulleted">
          <item><c>ec</c> is the <c>ei_cnode</c> representing the current cnode.</item>
          <item><c>fd</c> is an open descriptor to an Erlang
            connection.</item>
          <item><c>count</c> is the address of an integer, or
            <c>NULL</c>. If <c>count</c> is not <c>NULL</c>, it is
            set by the function to the number of names found.</item>
        </list>
        <p>On success, the function returns an array of strings, each
          containing a single registered name, and sets
          <c>count</c> to
          the number of names found. The array is terminated
          by a single <c>NULL</c> pointer. On failure, the function returns
          <c>NULL</c> and <c>count</c> is not modified.</p>
        <note>
          <p>It is the caller's responsibility to free the array
            afterwards. It has been allocated by the function with a
            single call to <c>malloc()</c>, so a single
            <c>free()</c> is all that is necessary.</p>
        </note>
      </desc>
    </func>

    <func>
      <name since=""><ret>int</ret><nametext>ei_global_register(fd,name,pid)</nametext></name>
      <fsummary>Register a name in global.</fsummary>
      <type>
        <v>int fd;</v>
        <v>const char *name;</v>
        <v><seecref marker="ei#erlang_pid"><c>erlang_pid</c></seecref> *pid;</v>
      </type>
      <desc>
        <p>Registers a name in <c>global</c>.</p>
        <list type="bulleted">
          <item><c>fd</c> is an open descriptor to an Erlang
            connection.</item>
          <item><c>name</c> is the name to register in
            <c>global</c>.</item>
          <item><c>pid</c> is the pid that is to be associated with
            <c>name</c>. This value is returned by <c>global</c>
            when processes request the location of <c>name</c>.
          </item>
        </list>
        <p>Returns <c>0</c> on success, otherwise <c>-1</c>.</p>
      </desc>
    </func>

    <func>
      <name since=""><ret>int</ret><nametext>ei_global_unregister(ec,fd,name)</nametext></name>
      <fsummary>Unregister a name from global.</fsummary>
      <type>
        <v><seecref marker="ei_connect#ei_cnode"><c>ei_cnode</c></seecref> *ec;</v>
        <v>int fd;</v>
        <v>const char *name;</v>
      </type>
      <desc>
        <p>Unregisters a name from <c>global</c>.</p>
        <list type="bulleted">
          <item><c>ec</c> is the <c>ei_cnode</c> representing the current cnode.</item>
          <item><c>fd</c> is an open descriptor to an Erlang
            connection.</item>
          <item><c>name</c> is the name to unregister from
            <c>global</c>.</item>
        </list>
        <p>Returns <c>0</c> on success, otherwise <c>-1</c>.</p>
      </desc>
    </func>

    <func>
      <name since=""><ret>int</ret><nametext>ei_global_whereis(ec,fd,name,pid,node)</nametext></name>
      <fsummary>Look up a name in global.</fsummary>
      <type>
        <v><seecref marker="ei_connect#ei_cnode"><c>ei_cnode</c></seecref> *ec;</v>
        <v>int fd;</v>
        <v>const char *name;</v>
        <v><seecref marker="ei#erlang_pid"><c>erlang_pid</c></seecref> *pid;</v>
        <v>char *node;</v>
      </type>
      <desc>
        <p>Looks up a name in <c>global</c>.</p>
        <list type="bulleted">
          <item><c>ec</c> is the <c>ei_cnode</c> representing the current cnode.</item>
          <item><c>fd</c> is an open descriptor to an Erlang
            connection.</item>
          <item><c>name</c> is the name that is to be looked up in
            <c>global</c>.</item>
        </list>
        <p>The <c>pid</c> parameter is a pointer to a
        <c>erlang_pid</c> that the function will update with the pid associated
           with the global name, if successful.</p>
        <p>If <c>node</c> is not <c>NULL</c>, it is a pointer to a
          buffer where the function can fill in the name of the node where
          <c>name</c> is found. <c>node</c> can be
          passed directly to <c>ei_connect()</c> if necessary.</p>
          <p>On success, the function returns 0, updates the <c>erlang_pid</c>
          pointed to by the pid parameter, and the <c>node</c> parameter is initialized to
          the node name where <c>name</c> is found. On failure,
          a negative number is returned.</p>
      </desc>
    </func>
  </funcs>
</cref>
