Table of Contents

Name

linx_hunt() - Locate the LINX endpoint matching a name

linx_hunt_from() - Locate the LINX endpoint matching a name, but set another LINX endpoint to be the owner of the pending hunt. However, if the hunt is resolved, it is still the caller that receives the hunt response.

Synopsis

#include <linx_types.h>
#include <linx.h>

int linx_hunt(LINX *linx, const char *name, union LINX_SIGNAL **hunt_sig);

int linx_hunt_from(LINX *linx, const char *name, union LINX_SIGNAL **hunt_sig, LINX_SPID from);

Description

linx_hunt() and linx_hunt_from() are used to locate a LINX endpoint with a name, exactly matching the provided hunt name, optionally prepended by link names to reach remote endpoints. When the endpoint is found, the provided signal buffer hunt_sig is sent from the located LINX endpoint to the caller. Without the hunt_sig, a default signal buffer is sent. The call consumes the signal buffer, transferring the buffer ownership, and sets the hunt_sig pointer to LINX_NIL. The buffer is consumed also if an error occurs.

If two endpoints have the same name, it is not specified which one of those two that will be returned to the caller. When the signal buffer is received, the linx_sender(3) call should be used to get the binary identifier (spid) of the hunted for LINX endpoint. The returned identifier (spid) is local in the caller's node, also if it corresponds to a LINX endpoint on a remote system.

The hunt can be resolved in two different ways. If a LINX endpoint with a matching name exists when the call is made, linx_hunt() returns 0 and hunt_sig is immediately sent to the caller with the resolved LINX endpoint identifier (spid) as sender.
If a LINX endpoint with a matching name does not exist when the call is made, the linx_hunt() calls returns 0 and the hunt is put in a pending state. When a LINX endpoint that matches the name is made available, the hunt_sig is sent to the caller with the resolved LINX endpoint identifier (spid) as sender.

A pending hunt will be freed if the linx endpoint is closed, e.g. if the caller exits. In the case with linx_hunt_from(), the from parameter indicates a different owner of the pending hunt. If the from endpoint is closed while the hunt is pending, the hunt will be freed. Note that from does NOT receive the hunt signal buffer, if a match of name is found.

name is a null-terminated string that shall exactly match a LINX endpoint's name. If the endpoint is located on a remote node, the name of a link to that node (or names in a sequence of links) shall be included as the leading part of the name according to the following syntax:
"[<link_1>/][<link_2>/]...[<link_N>/]name"
Example: "linkToA/linkToB/name" where a path of two links are passed to reach the LINX endpoint.

linx is the handle to the LINX endpoint, that will receive the hunt signal buffer.

hunt_sig is the signal buffer which will be sent to the caller as attach signal, with the located LINX endpoint as sender. If hunt_sig is LINX_NIL, a default signal buffer will be created with signal number LINX_OS_HUNT_SIG.

from specifies a different owner of a possible pending hunt. If the endpoint, with id from, is closed, the pending hunt will be removed.

If linx is not a valid LINX endpoint, i.e. created with linx_open(3) then abort(3) is called.

Return Value

Returns 0 if successful. -1 if an error occurred in which case errno is set.

Errors

EINVAL if name or, if applicable, from are invalid.

ENOMEM if there is not enough memory.

EBADF if the underlying linx structure contains a invalid socket descriptor.

EFAULT if name is an invalid user space address.

Bugs/Limitations

None.

Example

In this example client1 hunts for client2 and client3 */


Client 1:
#include <linx.h>
int
main (int argc, char *argv[]) 
{
  LINX *linx;
  LINX_SPID client2, client3;
  union LINX_SIGNAL *sig;
  /* Open a LINX endpoint with huntname "client1" */
  linx = linx_open("client1", NULL, 0);
  /* Hunt for client2 */
  linx_hunt(linx, "client2", NULL);
  /* Receive hunt signal */
  linx_receive(linx, &sig, LINX_OS_HUNT_SIG);
  /* Retrive client2's spid */
  client2 = linx_sender(linx, &sig);
  /* Free the hunt signal */
  linx_free_buf(linx, &sig);
   /* Hunt for client3 */    
  linx_hunt(linx, "client3", NULL);
  /* Receive hunt signal */
  linx_receive(linx, &sig, LINX_OS_HUNT_SIG);
  /* Retrive client3's spid */
  client3 = linx_sender(linx, &sig);
  /* Free the hunt signal */
  linx_free_buf(linx, &sig);
  /* Do work, e.g. exchanges signals with client2 or client3 ... */
  /* Close the LINX endpoint */
  linx_close(linx);
  return 0;
}
Client 2:
#include <linx.h>
int
main (int argc, char *argv[])
{
  LINX *linx;
  /* Open a LINX endpoint with huntname "client2" */
  linx = linx_open("client2", NULL, 0);
  /* Do work.... */
  /* When done close the LINX endpoint */
  linx_close(linx);
  /* "client2" can no longer be hunted on */
  return 0;
}
Client 3:
#include <linx.h>
int
main (int argc, char *argv[])
{
  LINX *linx;
  /* Open a LINX endpoint with huntname "client3" */
  linx = linx_open("client3", NULL, 0);
  /* Do work.... */
  /* When done close the LINX endpoint */
  linx_close(linx);
  /* "client3" can no longer be hunted on */
  return 0;
}

See Also

linx(7) , linx_attach(3) , linxcfg(1) , linxdisc(8)

Author

Enea LINX team

Copyright

Copyright (c) 2006-2007, Enea Software AB All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Enea Software AB nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Table of Contents