📄 timersrv.c
字号:
/*
* TIMERSRV.C - Testserver for message queues.
*
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 17.3.1991
*/
static char *VERSION = "Version 1.0" ;
/*
*/
static char *progname ;
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#define INCL_DOS
#include <os2.h>
#include "queue.h"
#define MAXTIMERLEN 25
typedef struct {
int sg ;
char timer[MAXTIMERLEN] ;
DATETIME dt ;
} _START_TMR ;
_START_TMR *pstart_tmr, stim ;
typedef struct {
int sg ;
char timer[MAXTIMERLEN] ;
} _STOP_TMR ;
_STOP_TMR *pstop_tmr ;
//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], buf[8] ;
progname = argv[0] ;
if (( ret = DosCreateQueue(&hpushreq, QUE_LIFO, "\\queues\\timerpsh")) != 0 ||
(ret = DosCreateQueue(&hpopreq, QUE_FIFO, "\\queues\\timerpop")) != 0 )
{
fprintf(stderr, "%s: error creating queues...\Exiting...\n", progname ) ;
return( 1 ) ;
}
printf("Queues \\queues\\timerpsh ja \\queues\\timerpop created...\nProcess ready to receive messages...\n") ;
/* read elements from queue and process them until ... */
for (;;)
{
if (( ret = DosReadQueue(hpopreq, &qres, &cbElement, &pstop_tmr, 0, DCWW_WAIT,
&bElemprty, NULL)) != 0)
{
return( 1 ) ;
}
if ( qres.usEventCode == 1 )
return( 0 ) ; /* EXIT-command received */
ptmp = itoa(pstop_tmr->sg, buf, 10) ;
strcpy(queue_name, "\\queues\\tmr") ; /* tmr prefix - somebody might use PIDs
as a name base. We want to minimize
risk for a name clash */
strcat(queue_name, ptmp) ;
//DosFreeSeg(SELECTOROF(pstop_tmp)) ;
if ( qres.usEventCode == 2)
{
usElementCode = 0 ;
while (( ret = DosPeekQueue(hpushreq, &qres, &cbElement, &pstart_tmr, &usElementCode,
DCWW_NOWAIT, &bElemprty, NULL)) == 0)
{
if (pstop_tmr->sg == pstart_tmr->sg )
{
QueSend( queue_name, (char *)pstart_tmr, sizeof(stim), 0, NULL, progname) ;
// send_queue( queue_name, (char *)pstart_tmr, sizeof(stim), 0) ;
}
}
QueSend( queue_name, " ", 1, 3, NULL, progname) ;
// send_queue( queue_name, " ", 1, 3) ; /* End of DIRS */
DosFreeSeg(SELECTOROF(pstop_tmr)) ;
}
else
{
/* process message... */
usElementCode = 0 ;
do
{
if (( ret = DosPeekQueue(hpushreq, &qres, &cbElement, &pstart_tmr, &usElementCode,
DCWW_NOWAIT, &bElemprty, NULL)) != 0)
{
QueSend( queue_name, (char *)" ", 1, 3, NULL, progname) ;
// send_queue( queue_name, (char *) " ", 1, 3) ;
break ;
}
} while (pstop_tmr->sg != pstart_tmr->sg ||
strcmpi(pstop_tmr->timer, pstart_tmr->timer) != 0) ;
if (ret == 0)
{
if (( ret = DosReadQueue(hpushreq, &qres, &cbElement, &pstart_tmr, usElementCode, DCWW_WAIT,
&bElemprty, NULL)) != 0)
{
return( 1 ) ;
}
QueSend( queue_name, (char *) pstart_tmr, sizeof(stim), 0, NULL, progname) ;
// send_queue( queue_name, (char *) pstart_tmr, sizeof(stim), 0) ;
DosFreeSeg(SELECTOROF(pstart_tmr)) ;
printf("poptimer = %s\n", pstop_tmr->timer) ;
}
else
printf("poptimer = NULL\n") ;
DosFreeSeg(SELECTOROF(pstop_tmr));
} /* 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) ;
memcpy(ptr, message, (size_t) cbElement) ;
if (( ret = DosWriteQueue(hpopresp, usRequest, cbElement, ptr, 0)) != 0)
{
fprintf(stderr, "%s: error in DosWriteQueue...\nExiting...\n", progname) ;
return( 1 ) ;
}
DosCloseQueue(hpopresp) ;
return( 0 ) ;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -