rpc_control Subroutine

Purpose

Changes or retrieves information of global remote procedure call (RPC) attributes for client and server applications.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
bool_t rpc_control(op, info);
int op;
void * info;

Description

The subroutine sets and retrieves values of global RPC attributes that apply to clients and servers. The op parameter indicates the operation type and the info parameter is a pointer to the operation-specific information. The data type specified by the info parameter changes according to the operation type. For example, you can set the op parameter with the following values:
RPC_SVC_MTMODE_SET
Sets the multithread mode.
RPC_SVC_MTMODE_GET
Get the multithread mode.

For the op parameter in this example, the value of the info parameter is of the int * type.

Values for the op Parameter Argument Type Function
RPC_SVC_MTMODE_SET int * Sets the multithread mode.
RPC_SVC_MTMODE_GET int * Gets the multithread mode.
RPC_SVC_THRMAX_SET int * Sets the maximum number of threads.
RPC_SVC_THRMAX_GET int * Gets the maximum number of threads.
RPC_SVC_THRTOTAL_GET int * Gets the number of active threads.
RPC_SVC_THRCREATES_GET int * Gets the number of threads created.
RPC_SVC_THRERRORS_GET int * Gets the number of threads that create errors.
RPC_SVC_USE_POLLFD int * Sets the number of file descriptors to unlimited.
Three multithread (MT) modes are listed in the following table.
Item Description
RPC_SVC_MT_NONE the single-threaded mode (default)
RPC_SVC_MT_AUTO the automatic MT mode
RPC_SVC_MT_USER the user MT mode
The default (single-threaded) mode stays unless the application sets the other two modes. When a mode is set, it cannot be changed. A server can create a maximum of 16 threads anytime. You can restrict the number of thread resources consumed by a server. If a server needs more than 16 threads, set the maximum number of threads to a desired number. Similarly, RPC servers are limited to a maximum of 1024 file descriptors or connections. Applications that use preferred interfaces of the svc_pollfd global variable and the svc_getreq_poll subroutines can use unlimited number of file descriptors. To achieve the goal, you can point the info parameter to nonzero and set the op parameter value to RPC_SVC_USE_POLLFD.

Parameters

Item Description
op Represents the operation type.
info Points to the information for the request type. The info parameter is expected to be a pointer to an appropriate structure. The nature of the structure depends on the operation type.

Return Values

Item Description
TRUE successful
FALSE unsuccessful

Examples

In the following example, the rpc_control subroutine is used to set server program in the automatic MT mode.

#include <stdlib.h>
#include <rpc/rpc.h>

int main()
{
  SVCXPRT *transpnum;
  rpcprog_t prognum = 0x3fffffffL;
  rpcvers_t progver = 0x1L;

  /* Register the service for prognum & progver on tcp transport */
  transpnum = svc_create(dispatch_AUTOMT, prognum, progver, "tcp");
  if (transpnum == 0)
  {
    fprintf(stderr, "Cannot create a service.\n");
    svc_unreg(prognum,progver);
    exit(1);
  }

  /* Configure the server in AUTO_MT mode */
  mode = RPC_SVC_MT_AUTO;
  if(rpc_control(RPC_SVC_MTMODE_SET,&mode) == FALSE)
  {
    fprintf(stderr,"\nError in rpc_control!\n");
    exit(1);
  }

  svc_run();

  return 0;
}