Open System Services Programmer's Guide
Example 39 Launcher Program to Spawn Static Servers
/*slaunch1.c
* Simple OSS example using OSS sockets APIs for communication
* between requester and server.
*
* slaunch1 (static launcher 1) is an inetd-like program which
* starts an sserver (static server) process on each available cpu
* and then passes each incoming socket connection to a sserver process.
*
* slaunch1 and sserver write progress messages and error messages
* to stderr.
*/
#define _XOPEN_SOURCE_EXTENDED 1 /* needed for OSS sockets */
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <tdmext.h>
/* Guardian APIs */
#include <cextdecs.h(PROCESSHANDLE_GETMINE_, \
PROCESSHANDLE_DECOMPOSE_, \
PROCESSORSTATUS)>
short cpucount; /* cpucount - # cpu in system */
short cpuindex; /* cpuindex - current cpu for sserver */
short cpumask; /* cpumask - bit mask of available cpus */
short cpu, phandle[10]; /* our cpu and process handle */
int pairfd[2]; /* socketpair fd values */
int serverfd[16]; /* server fd indexed by cpu number */
int newpid, fd, listenfd; /* process id, file descriptor, listening fd */
int readycount, bytesread; /* ready fd count, recv byte count */
struct sockaddr_in addr; /* socket address (family,addr,port) */
struct timeval timeval; /* timeout structure for select() call */
fd_set fdset; /* set of fds for select() call */
struct msghdr fdmsghdr; /* msghdr for sendmsg() call */
struct iovec iov[1]; /* io vector for sendmsg() call */
struct { /* ancillary data for sendmsg() call */
struct cmsghdr fdcmsghdr;/* ancillary data header */
int fd; /* ancillary data (one fd) */
} fdadata;
#define IDLE_PERIOD 180 /* 180 second timeout value */
extern char *environ[];
static char *childargv[] = {"sserver", NULL};
struct inheritance inherit;
struct process_extension peparm = DEFAULT_PROCESS_EXTENSION;
struct process_extension_results perslt = DEFAULT_PROCESS_EXTENSION_RESULTS;
int main(int argc, char **argv)
{
/* get system cpu config */
cpumask = (short) PROCESSORSTATUS();
cpucount = (short) (PROCESSORSTATUS() >> 16);
cpuindex = -1;
Performance Considerations 143










