[comp.protocols.tcp-ip] RPC server and fork

fischer@dssmv2.mpr.ca (Roger Fischer) (09/18/90)

A while ago there was a discussion about RPC servers forking a child task
to do the server function. I did not participate in that discussion.
When I run into the same problem a colleague showed me some of the
articles.

Here I would like to present a possible solution. Comments would be
greatly appreciated.

The problem I still have is how to return an error message when I
can't fork any more tasks or when the fork failed.


pmap_unset( PDIPROG, PDIVERS);
transport = svctcp_create( RPC_ANYSOCK, 0, 0);
svc_register( transport, PDIPROG, PDIVERS, pdirpprog_1, IPPROTO_TCP);
while (TRUE) {
  new_socket = accept( transport->xp_sock, &caller_adr, &addr_len);
  new_transport = svcfd_create( new_socket, 0, 0);
  new_transport->xp_raddr = caller_addr;
  new_transport->xp_addrlen = addr_len;
  if (no_more_forks)
    svcerr_systemerr( new_transport); /* maximum # of children exceeded */
  else {
    child_pid = fork();
    if (child_pid < 0)
      svcerr_systemerr( new_transport); /* fork failed */
    else if (child_pid > 0) {
      svc_destroy( transport);
      svc_run();
      /* should never get here */
      svc_destroy( new_transport);
    }
    else
      svc_destroy( new_transport);
  }
}
/* should never get here */
svc_destroy( transport);


Roger
----------------------------------------------------------------------------
Roger W. Fischer         fischer@mprgate.mpr.ca         fischer@mprgate.UUCP
..seismo!ubc-cs!mprgate!fischer     ...ihnp4!alberta!ubc-cs!mprgate!fischer