home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Server Message Handler
- * Two Queue Approach
- * Unix/Xenix V Queue Implementation
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
- #include "ctmssg.h"
- #include <errno.h>
- #include <signal.h>
-
- LOCAL UCOUNT msgsiz;
- LOCAL LONG *ausrmid;
-
- extern COUNT uerr_cod;
- extern COUNT cts_mxusr;
- extern int errno;
-
- /* elapsed time before unread user queue declared inactive */
- #define INDEFINITE 5 /* seconds */
-
- /* LTYPE is defined in ctmsgg.h */
-
- TEXT *getmid(sizmsg,maxusr)
- UCOUNT sizmsg;
- COUNT maxusr;
- {
- TEXT *retval;
- int chfd;
-
- key_t ftok();
- TEXT *mballc();
-
- /* server ignores hangup */
- signal(SIGHUP,SIG_IGN);
-
- /* create SERVER3 to prove no other server is running */
- if ((chfd = open(SERVER3,O_RDWR | O_EXCL | O_CREAT,BCREATE)) < 0) {
- fprintf(stderr,"\nIs a c-tree Server already running?\n");
- fprintf(stderr,"\nIf a c-tree Server has terminated abnormally,");
- fprintf(stderr,"\nremove the file %s before starting the server.\n\n",
- SERVER3);
- exit(2);
- } else
- close(chfd);
-
- /* allocate an array for message ids: assumes long is OK */
- if ((ausrmid = (LONG *) mballc(maxusr + 1,sizeof(LONG))) == NULL) {
- uerr_cod = SSCB_ERR;
- return(NULL);
- }
-
- /* get message id for server */
- uerr_cod = 0;
-
- if ((srvkey = ftok(SERVER,'q')) == NOKEY) /* get "key" for input Q */
- uerr_cod = SSKY_ERR;
- else if ((srvid = msgget(srvkey,IPC_CREAT | 0666)) < 0) /* get msg id */
- uerr_cod = SSID_ERR;
- else if (msgctl(srvid,IPC_STAT,&qidbuf) < 0) /* get msg specs */
- uerr_cod = SMST_ERR;
- else {
- /* set message size specifications */
- msgsiz = sizmsg;
- qidbuf.msg_qbytes = sizmsg + LTYPE;
- if (msgctl(srvid,IPC_SET,&qidbuf) < 0)
- uerr_cod = SMQZ_ERR;
- }
- if (uerr_cod)
- return(NULL);
-
-
- /* get space for server message */
- if ((retval = mballc(1,sizmsg + LTYPE)) == NULL) {
- uerr_cod = SSPC_ERR;
- return(NULL);
- }
-
- if ((appkey = ftok(SERVER2,'q')) == NOKEY) /* get "key" for output Q */
- uerr_cod = ASKY_ERR;
- else if ((apxid = msgget(appkey,IPC_CREAT | 0666)) < 0) /* get msg id */
- uerr_cod = ASID_ERR;
- else if (msgctl(apxid,IPC_STAT,&qidbuf) < 0) /* get msg specs */
- uerr_cod = AMST_ERR;
- else {
- /* set message size specifications */
- qidbuf.msg_qbytes = cts_mxusr * (sizmsg + LTYPE); /* ???? */
- if (msgctl(apxid,IPC_SET,&qidbuf) < 0)
- uerr_cod = AMQZ_ERR;
- }
-
- return(retval + LTYPE);
- }
-
- LONG getumsg(pmsg,usrn,msgptr) /* assumes that mpntr member contains msg id */
- MESSAGE *pmsg;
- COUNT usrn;
- TEXT *msgptr;
- {
- /* save message id of application: assumes that a long is sufficient */
- if (usrn >= 0)
- ausrmid[usrn] = pmsg->mpntr;
-
- return(pmsg->mpntr);
- }
-
- COUNT dedusr(msgid)
- LONG msgid;
- {
- COUNT usrn;
-
- for (usrn = 0; usrn < cts_mxusr; usrn++)
- if (msgid == ausrmid[usrn]) {
- ausrmid[usrn] = 0;
- return(usrn);
- }
- return(-1);
- }
-
- COUNT ridmid()
- {
- /* remove check file */
- unlink(SERVER3);
-
- /* remove application message handling */
- if (msgctl(srvid,IPC_RMID,NULL) < 0)
- return(uerr_cod = SMRD_ERR);
- sleep(5);
- if (msgctl(apxid,IPC_RMID,NULL) < 0)
- return(uerr_cod = SMRD_ERR);
- return(NO_ERROR);
- }
-
- COUNT ctrqst(msgadr,pmsg)
- PFAST TEXT **msgadr;
- MESSAGE *pmsg;
- {
- /* read input message */
- if (msgrcv(srvid,*msgadr - LTYPE,msgsiz,0L,0) < 0)
- return(uerr_cod = SRQS_ERR);
-
- /* copy message header */
- cpybuf(pmsg,*msgadr,sizeof(MESSAGE));
-
- return(NO_ERROR);
- }
-
- COUNT ctrspn(msgadr,pmsg,sizmsg,usrn)
- PFAST TEXT *msgadr;
- MESSAGE *pmsg;
- UCOUNT sizmsg;
- COUNT usrn;
- {
- /* local copy of message id with correct type */
- long int locmid;
-
- if (usrn < 0) {
- usrn = - (usrn + 1);
- locmid = ausrmid[usrn];
- ausrmid[usrn] = 0;
- } else
- locmid = ausrmid[usrn];
-
- /* copy message header */
- cpybuf(msgadr,pmsg,sizeof(MESSAGE));
-
- /* send response */
- msgadr -= LTYPE;
- *((LONG *) msgadr) = locmid;
-
- if (msgsnd(apxid,msgadr,sizmsg,IPC_NOWAIT) < 0)
- if (errno != EAGAIN || msgsnd(apxid,msgadr,sizmsg,0) < 0)
- return(uerr_cod = SRSP_ERR);
-
- return(NO_ERROR);
-
- }
-
- COUNT norspn(usrn)
- COUNT usrn;
- {
- return(NO);
- }
-
- chkusrtim(usrtim,usrmap,usrtrn)
- LONG *usrtim;
- COUNT *usrmap;
- LONG *usrtrn;
- {
- /*
- * This function can interrogate the usrtim[] array to
- * determine if any active user slot is in fact dead.
- */
- return(NO_ERROR);
- }
-
- /* end of ctsmsg.c */
-
-