svc_getreq_common Subroutine

Purpose

Handles remote procedure call (RPC) service requests on a given file descriptor.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
void svc_getreq_common( fd )
int fd;

Description

The svc_getreq_common subroutine is used to handle the RPC service request on a specified file descriptor. You can use the subroutine after calling the poll or select subroutine. The svc_getreq_common subroutine is generally used when a server wants to handle RPC service requests asynchronously (the svc_run subroutine is not used).

Parameters

Item Description
fd Specifies a file descriptor on which the RPC service request arrives.

Examples

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

void my_svc_getreq_poll(struct pollfd * poll_fd, int retval)
{
    int  i;
    int   ds;

    for (i = fds = 0; fds < retval; i++) {
                
        /* for all file descriptors check if input is pending
        and handle the request on that file descriptor */

        svc_getreq_common(pll_fd[i]);
    } 
}
main()
{

    int no_of_fds;
    int i;
    struct pollfd pollfd_set[1024];

    /* Register RPC Service */
           
    /* serve client's requests asynchronously */
    while(1)
    {
        /* initialize the pollfd_set array and 
        get no of file descriptors in "no_of_fds"*/

        /* Keep polling on file descriptors */ 
        switch (i = poll(pollfd_set, no_of_fds, -1))
        {
             case -1:
             case  0:
             continue;
             default:   
             /* Handle RPC request on each file descriptor */
             my_svc_getreq_poll(pollfd_set, i);
        }
    }
}