queue.c

来自「使用于OS/2下的小工具的C源程序,使用于OS/2下的小工具的C源程序」· C语言 代码 · 共 75 行

C
75
字号
/*
* QUEUE.C - General message queue functions.
*
*
* PROGRAMMER:	    Martti Ylikoski
* CREATED:	    2.3.1992
*/
static char *VERSION = "Version  1.0" ;
/*
*/


#define INCL_DOSINFOSEG
#define INCL_DOS
#include <os2.h>
#include "queue.h"
#include <stdio.h>

int QueSend(char *queue_name, char *message, USHORT cbElement, USHORT usRequest,
    char *serverp, char *progname)
{
HQUEUE hpushreq ;
USHORT ret, qowner ;
SEL mesg, selRecipient ;
PCH ptr ;
int i ;

      i = 0 ;
      while (( ret = DosOpenQueue(&qowner, &hpushreq, queue_name)) != 0 && i < 2)
      {
         if (serverp == NULL)
         {
  	    fprintf(stderr, "%s: error opening queue %s...\nExiting...\n", progname, queue_name) ;
            return( 1 ) ;
         }
         
	 system(serverp) ;
	 DosSleep(2000L) ;
	 i ++ ;
      }

      if ( i >= 2)
      {
	 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) ;

//      strcpy(ptr, message) ;
      if (( ret = DosWriteQueue(hpushreq, usRequest
	, cbElement, ptr, 0)) != 0)
      {
	 fprintf(stderr, "%s: error in DosWriteQueue...\nExiting...\n", progname) ;
	 return( 1 ) ;
      }

      DosCloseQueue(hpushreq) ;

   return( 0 ) ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?