|
|
Suppose a process is processing RPC requests while performing some other activity. If the other activity involves periodically updating a data structure, the process can set an alarm signal before calling svc_run.
If the other activity involves waiting on a file descriptor, however, the
svc_run
call will not work.
Given the file descriptors of the transport endpoints associated with
the programs being waited on,
a process can have its own
select
that waits on both the RPC file descriptors and its own file descriptors.
For example, consider the code below, which is for an earlier version of svc_run. Note that svc_fdset is a bit mask of all the file descriptors that RPC is using for services. The mask can change every time any RPC library routine is called, because descriptors are constantly being opened and closed:
void svc_run () { fd_set readfds; extern int errno;The current version of svc_run calls svc_getreq_poll. A process can bypass svc_run and call svc_getreqset (the dispatcher) or svc_getreq_poll directly. The svc_getreqset and svc_getreq_poll routines in turn call svc_getreq_common. These functions are described on the rpc_svc_reg(3rpc) manual page.for (;;) { readfds = svc_fdset; switch (select(_rpc_dtbsize(), &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0)) {
case -1: if (errno == EINTR) { continue; } /* * log an error: svc_run: select failed */ return; case 0: continue; default: svc_getreqset(&readfds); } } }