cja@castle.ed.ac.uk (C Adie) (11/27/89)
Has anyone had problems using DosReadQueue in NO WAIT mode? I find that
when a message gets written to a queue, the semaphore which the queue owner
passes to DosReadQueue gets cleared OK, but none of the other parameters to
DosReadQueue get updated - eg the length, element address, priority etc.
If you use WAIT mode, it all works fine.
Am I being stupid, or is there really a problem here? All the examples of
using queues I've been able to find use WAIT mode.
Clearly, the workaround would be to create a thread to do a synchronous
DosReadQueue - maybe this is what the asynchronous DosReadQueue does? In
which case, perhaps creating your own thread would be more efficient - you
could keep it around to do the next DosReadQueue, avoiding the overhead of
continual thread creation/deletion.
I enclose below a couple of test programs which demonstrate the problem.
Chris Adie
----cut here-------------------------------------------------------------
#define INCL_BASE
#include <os2.h>
#include <dos.h>
typedef struct _QUEUERESULT {
PID pidProcess;
USHORT usEventCode;
} QUEUERESULT;
main() {
SEL sel;
USHORT err;
HQUEUE hq;
HSEM hs;
QUEUERESULT qr;
USHORT len;
void far *el;
BYTE pri;
int wait;
if (err=DosAllocShrSeg(260,"\\sharemem\\test1",&sel)) {
printf("Error %d from DosAllocShrSeg\n",err);
exit(0);
}
FP_SEG(hs) = sel;
FP_OFF(hs) = 0;
*(PULONG)hs = 0L;
if (err=DosCreateQueue(&hq,0x0002,"\\queues\\test1")) {
printf("Error %d from DosCreateQueue\n",err);
exit(0);
}
qr.pidProcess = 0xFFFF;
qr.usEventCode = 0xFFFF;
pri = 0xFF;
el = 0xFFFFFFFF;
wait = DCWW_NOWAIT;
//wait = DCWW_WAIT;
if (err=DosReadQueue(hq,(PULONG)(&qr),&len,(PULONG)(&el),0,wait,&pri,hs)) {
if (err!=ERROR_QUE_EMPTY) {
printf("Error %d from DosReadQueue\n",err);
exit(0);
}
}
if (wait==DCWW_NOWAIT) if (err=DosSemWait(hs,-1L)) {
printf("Error %d from DosSemWait\n",err);
exit(0);
}
printf("Address %p\n",el);
printf("Length %d\n",len);
printf("Event type %d\n",qr.usEventCode);
printf("From process %d\n",qr.pidProcess);
printf("Priority %d\n",pri);
if (err=DosCloseQueue(hq)) {
printf("Error %d from DosCloseQueue\n",err);
exit(0);
}
}
----cut here-------------------------------------------------------------
#define INCL_BASE
#include <os2.h>
#include <dos.h>
main() {
SEL sel;
USHORT err;
HQUEUE hq;
HSEM hs;
USHORT len;
void far *el;
USHORT event;
BYTE pri;
PID owner;
if (err=DosGetShrSeg("\\sharemem\\test1",&sel)) {
printf("Error %d from DosGetShrSeg\n",err);
exit(0);
}
FP_SEG(el) = sel;
FP_OFF(el) = 4;
if (err=DosOpenQueue(&owner,&hq,"\\queues\\test1")) {
printf("Error %d from DosOpenQueue\n",err);
exit(0);
}
event = 123;
pri = 5;
printf("Address %p\n",el);
printf("Event type %d\n",event);
printf("Priority %d\n",pri);
if (err=DosWriteQueue(hq,event,256,el,pri)) {
printf("Error %d from DosWriteQueue\n",err);
exit(0);
}
if (err=DosCloseQueue(hq)) {
printf("Error %d from DosCloseQueue\n",err);
exit(0);
}
}
----cut here-------------------------------------------------------------
# If Codeview support is (is not) wanted, comment out the first (second) line below.
#CVIEW=/O
CVIEW=/Zi /Od
CMPLFLAGS=/AL /FPc /c $(CVIEW) /D OS2 /U MSDOS
#---------- Inference rules:
.c.obj:
cl $(CMPLFLAGS) $*.c
#---------- Targets:
test1.exe: test1.obj
link test1.obj /CO;
markexe windowcompat test1.exe
test2.exe: test2.obj
link test2.obj /CO;
markexe windowcompat test2.exe
#---------- Dependencies:
test1.obj: test1.c
test2.obj: test2.c