home *** CD-ROM | disk | FTP | other *** search
- /*
- * DIRSERV.C - Testserver for message queues.
- *
- *
- * PROGRAMMER: Martti Ylikoski
- * CREATED: 17.3.1991
- */
- static char *VERSION = "DIRSERV - Directory Stack Server. Copyright(c) Martti Ylikoski, 1990-1992. Version 1.0" ;
- /*
- */
-
- static char *progname ;
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define INCL_DOS
- #include <os2.h>
- //int send_queue(char *queue, char *message, USHORT cbElement, USHORT usRequest) ;
-
- int main(int argc, char *argv[])
- {
- HQUEUE hpushreq, hpopreq ; /* queuehandle */
- USHORT ret ;
- QUEUERESULT qres ;
- PVOID pmesg ;
- USHORT cbElement ;
- BYTE bElemprty ;
- ULONG tsem = 0L ;
- USHORT usElementCode ;
- int sg, sgpop ;
- char *ptmp, queue_name[80], dir[128] ;
-
- progname = argv[0] ;
-
- if (( ret = DosCreateQueue(&hpushreq, QUE_LIFO, "\\queues\\pushreq")) != 0 ||
- (ret = DosCreateQueue(&hpopreq, QUE_FIFO, "\\queues\\popreq")) != 0 )
- {
- fprintf(stderr, "%s: error creating queues...\Exiting...\n", progname ) ;
- return( 1 ) ;
- }
-
- printf("Queues \\queues\\pushreq ja \\queues\\popreq created...\nProcess ready to receive messages...\n") ;
-
- /* read elements from queue and process them until ... */
- for (;;)
- {
- if (( ret = DosReadQueue(hpopreq, &qres, &cbElement, &pmesg, 0, DCWW_WAIT,
- &bElemprty, NULL)) != 0)
- {
- return( 1 ) ;
- }
-
- if ( qres.usEventCode == 1 )
- return( 0 ) ; /* EXIT-command received */
-
- ptmp = strtok(pmesg, " ") ;
- sgpop = atoi(ptmp) ;
-
- strcpy(queue_name, "\\queues\\sg") ; /* sg prefix - somebody might use PIDs
- as a name base. We want to minimize
- risk for a name clash */
- strcat(queue_name, ptmp) ;
-
- DosFreeSeg(SELECTOROF(pmesg)) ;
-
- if ( qres.usEventCode == 2)
- {
- usElementCode = 0 ;
- while (( ret = DosPeekQueue(hpushreq, &qres, &cbElement, &pmesg, &usElementCode,
- DCWW_NOWAIT, &bElemprty, NULL)) == 0)
- {
- sscanf(pmesg, "%d %s", &sg, dir) ;
- if (sg == sgpop)
- {
- QueSend( queue_name, dir, cbElement, 0, NULL, progname) ;
- }
- }
- QueSend( queue_name, ".", 2, 3, NULL, progname) ; /* End of DIRS */
- }
- else
- {
- /* process message... */
- usElementCode = 0 ;
- do
- {
- if (( ret = DosPeekQueue(hpushreq, &qres, &cbElement, &pmesg, &usElementCode,
- DCWW_NOWAIT, &bElemprty, NULL)) != 0)
- {
- strcpy(dir, ". " ) ;
- break ;
- }
-
- sscanf(pmesg, "%d ", &sg) ;
- } while (sg != sgpop) ;
-
- if (ret == 0)
- {
- if (( ret = DosReadQueue(hpushreq, &qres, &cbElement, &pmesg, usElementCode, DCWW_WAIT,
- &bElemprty, NULL)) != 0)
- {
- return( 1 ) ;
- }
-
- ptmp = strtok(pmesg, " ") ;
- sg = atoi(ptmp) ;
- ptmp = strtok(NULL, " ") ;
- strcpy(dir, ptmp) ;
- DosFreeSeg(SELECTOROF(pmesg)) ;
- }
-
- printf("popdir = %s\n", dir) ;
- QueSend( queue_name, dir, cbElement, 0, NULL, progname) ;
- } /* else */
- } /* for(;;) */
-
- DosCloseQueue(hpushreq) ;
- DosCloseQueue(hpopreq) ;
-
- return( 0 ) ;
- }
- /*
- int send_queue(char *queue_name, char *message, USHORT cbElement, USHORT usRequest)
- {
- HQUEUE hpopresp ;
- USHORT ret, qowner ;
- SEL mesg, selRecipient ;
- PCH ptr ;
-
- if (( ret = DosOpenQueue(&qowner, &hpopresp, queue_name)) != 0)
- {
- fprintf(stderr, "%s: error opening queue %s...\nExiting...\n", progname, queue_name) ;
- return( 1 ) ;
- }
- if (( ret = DosAllocSeg(512, &mesg, SEG_GIVEABLE)) != 0)
- {
- fprintf(stderr, "%s: error in DosAllocSeg...\nExiting...\n", progname) ;
- return( 1 ) ;
- }
-
- if (( ret = DosGiveSeg(mesg, qowner, &selRecipient)) != 0)
- {
- fprintf(stderr, "%s: error in DosGiveSeg...\nExiting...\n", progname) ;
- return( 1 ) ;
- }
- ptr = MAKEP(mesg, 0) ;
- strcpy(ptr, message) ;
- if (( ret = DosWriteQueue(hpopresp, usRequest, cbElement, ptr, 0)) != 0)
- {
- fprintf(stderr, "%s: error in DosWriteQueue...\nExiting...\n", progname) ;
- return( 1 ) ;
- }
-
- DosCloseQueue(hpopresp) ;
- return( 0 ) ;
- }
- */
-