Exemplo n.º 1
0
int main(void)
{
    APIRET apiret;
    HQUEUE hq;
    PSZ pszQueueName = "\\queue\\os2linux\\test\\queue";
    PID pid;
    ULONG bytesread, priority = 0;
    REQUESTDATA request;
    PVOID msgtxt;
    CHAR fmtspec[80];

    printf(__FILE__ " main function invoked\n");
    printf("Test DosExecPgm and queues\n");

    /* create queue */
    apiret = DosOpenQueue(&pid, &hq, pszQueueName);
    printf("DosOpenQueue function returned %d\n", (int)apiret);
    if (apiret) {
        return 0;
    }

    apiret = DosReadQueue(hq, &request, &bytesread, &msgtxt, 0, TRUE,
                             (PBYTE)&priority, NULLHANDLE);
    printf("DosReadQueue function returned %d\n", (int)apiret);
    if (apiret) {
        return 0;
    }
    sprintf(fmtspec, "The message was \"%%0.%ds\"\n", (int)bytesread);
    printf(fmtspec, (PSZ)msgtxt);

    apiret = DosReadQueue(hq, &request, &bytesread, &msgtxt, 0, TRUE,
                             (PBYTE)&priority, NULLHANDLE);
    printf("DosReadQueue function returned %d\n", (int)apiret);
    if (apiret) {
        return 0;
    }
    sprintf(fmtspec, "The message was \"%%0.%ds\"\n", (int)bytesread);
    printf(fmtspec, (PSZ)msgtxt);

    apiret = DosReadQueue(hq, &request, &bytesread, &msgtxt, 0, TRUE,
                             (PBYTE)&priority, NULLHANDLE);
    printf("DosReadQueue function returned %d\n", (int)apiret);
    if (apiret) {
        return 0;
    }
    sprintf(fmtspec, "The message was \"%%0.%ds\"\n", (int)bytesread);
    printf(fmtspec, (PSZ)msgtxt);

    apiret = DosCloseQueue(hq);
    printf("DosCloseQueue function returned %d\n", (int)apiret);

    return 0;
}
Exemplo n.º 2
0
ULONG QueueOpen(
    PUCHAR name,
    ULONG argc,
    PRXSTRING args,
    PSZ queue,
    PRXSTRING result)
{
    PRXSTRING handleVar;
    PSZ qName;
    PRXSTRING serverVar;
    HEV sem;
    PQueue q;
    APIRET rc;
    ULONG cc;

    if (argc < 2 || argc > 4) return QUEUE_BADPARAM;

    if (!RxStringIsPresent(args + 0)) return QUEUE_BADPARAM;
    handleVar = args + 0;

    if (!RxStringIsPresent(args + 1)) return QUEUE_BADPARAM;
    qName = args[1].strptr;

    if (argc > 2 && RxStringIsPresent(args + 2)) serverVar = args + 2;
    else serverVar = NULL;

    if (argc > 3 && RxStringIsPresent(args + 3)) {
        if (!RxStringToUnsigned(args + 3, &sem)) return QUEUE_BADPARAM;
    }
    else sem = 0;

    q = malloc(sizeof(Queue));
    if (q == NULL) return QUEUE_NOMEM;

    rc = DosOpenQueue(&q->server, &q->handle, qName);

    if (rc == NO_ERROR) {
        q->client = Queue_GetPID();
        q->sem = sem;

        UnsignedToRxVariable((ULONG)q, handleVar);
        if (serverVar != NULL) UnsignedToRxVariable(q->server, serverVar);
    }
    else free(q);

    cc = UnsignedToRxResult(rc, result);
    return cc;
}
Exemplo n.º 3
0
static void server_maintenance(void *vpArg)
{
    int num_idle, num_needed;
    ULONG num_pending = 0;
    int threadnum;
    HQUEUE workq;
    ULONG rc;
    PID owner;

    rc = DosOpenQueue(&owner, &workq,
                      apr_psprintf(pchild, "/queues/httpd/work.%d", getpid()));

    if (rc) {
        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf,
                     "unable to open work queue in maintenance thread");
        return;
    }

    do {
        for (num_idle=0, threadnum=0; threadnum < HARD_THREAD_LIMIT; threadnum++) {
            num_idle += ap_scoreboard_image->servers[child_slot][threadnum].status == SERVER_READY;
        }

        DosQueryQueue(workq, &num_pending);
        num_needed = ap_min_spare_threads - num_idle + num_pending;

        if (num_needed > 0) {
            for (threadnum=0; threadnum < num_needed; threadnum++) {
                add_worker();
            }
        }

        if (num_idle - num_pending > ap_max_spare_threads) {
            DosWriteQueue(workq, WORKTYPE_EXIT, 0, NULL, 0);
        }
    } while (DosWaitEventSem(shutdown_event, 500) == ERROR_TIMEOUT);
}
Exemplo n.º 4
0
static int SendExtQMsg
(
   USHORT usEvent,
   PVOID pData,
   ULONG ulLen
)
{
   USHORT res;
   ULONG ulPID;
   HQUEUE hQueue;
   PVOID pItem;

   res=DosOpenQueue(&ulPID, &hQueue, szExtQueue);
   if (res)
   {
      printf("AM4PM not running\n");
      return 2;
   }

   if (pData != NULL)
   {
      DosAllocSharedMem(&pItem, NULL, ulLen, PAG_COMMIT | OBJ_GIVEABLE | PAG_READ | PAG_WRITE);
      memcpy(pItem, pData, ulLen);
      DosGiveSharedMem(pItem, ulPID, PAG_READ | PAG_WRITE);
      DosFreeMem(pItem);
   }
   else
      pItem=NULL;

   res=DosWriteQueue(hQueue, usEvent, ulLen, pItem, 0);

   DosCloseQueue(hQueue);
   if (res)
      return 2;
   return 0;
}
Exemplo n.º 5
0
static void worker_main(void *vpArg)
{
    long conn_id;
    conn_rec *current_conn;
    apr_pool_t *pconn;
    apr_allocator_t *allocator;
    apr_bucket_alloc_t *bucket_alloc;
    worker_args_t *worker_args;
    HQUEUE workq;
    PID owner;
    int rc;
    REQUESTDATA rd;
    ULONG len;
    BYTE priority;
    int thread_slot = (int)vpArg;
    EXCEPTIONREGISTRATIONRECORD reg_rec = { NULL, thread_exception_handler };
    ap_sb_handle_t *sbh;

    /* Trap exceptions in this thread so we don't take down the whole process */
    DosSetExceptionHandler( &reg_rec );

    rc = DosOpenQueue(&owner, &workq,
                      apr_psprintf(pchild, "/queues/httpd/work.%d", getpid()));

    if (rc) {
        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf,
                     "unable to open work queue, exiting");
        ap_scoreboard_image->servers[child_slot][thread_slot].tid = 0;
    }

    conn_id = ID_FROM_CHILD_THREAD(child_slot, thread_slot);
    ap_update_child_status_from_indexes(child_slot, thread_slot, SERVER_READY,
                                        NULL);

    apr_allocator_create(&allocator);
    apr_allocator_max_free_set(allocator, ap_max_mem_free);
    bucket_alloc = apr_bucket_alloc_create_ex(allocator);

    while (rc = DosReadQueue(workq, &rd, &len, (PPVOID)&worker_args, 0, DCWW_WAIT, &priority, NULLHANDLE),
           rc == 0 && rd.ulData != WORKTYPE_EXIT) {
        pconn = worker_args->pconn;
        ap_create_sb_handle(&sbh, pconn, child_slot, thread_slot);
        current_conn = ap_run_create_connection(pconn, ap_server_conf,
                                                worker_args->conn_sd, conn_id,
                                                sbh, bucket_alloc);

        if (current_conn) {
            ap_process_connection(current_conn, worker_args->conn_sd);
            ap_lingering_close(current_conn);
        }

        apr_pool_destroy(pconn);
        ap_update_child_status_from_indexes(child_slot, thread_slot,
                                            SERVER_READY, NULL);
    }

    ap_update_child_status_from_indexes(child_slot, thread_slot, SERVER_DEAD,
                                        NULL);

    apr_bucket_alloc_destroy(bucket_alloc);
    apr_allocator_destroy(allocator);
}
Exemplo n.º 6
0
int main(USHORT argc, PCHAR argv[]) {



   PSZ         szQueueName  = "\\QUEUES\\OF\\DATA\\WAITING\\FOR\\SERVICE";

   HQUEUE      hqSpecialQue = NULLHANDLE; /* Queue handle                   */

   REQUESTDATA Request      = {0};        /* Reques */

   PID         pidOwner     = 0;

   APIRET      rc           = NO_ERROR;   /* Return code                    */



   rc = DosCreateQueue(&hqSpecialQue,    /* Queue handle                    */

             QUE_FIFO |                  /* First-In First-Out order        */

             QUE_CONVERT_ADDRESS,        /* Convert 16-bit addresses to 32  */

             szQueueName);               /* Name of the queue to create     */



   if (rc!= NO_ERROR) {

      printf ("DosCreateQueue error: return code = %u\n", rc);

      return 1;       }



   rc = DosOpenQueue (&pidOwner,         /* PID of queue owner              */

                      &hqSpecialQue,     /* Handle for created queue        */

                      szQueueName);      /* Name of the queue to open       */



   if (rc!= NO_ERROR) {

      printf ("DosOpenQueue error: return code = %u\n", rc);

      return 1;       }



           /* Kill the queue owner (which is us) */



   rc = DosKillProcess(0, pidOwner);

   if (rc != NO_ERROR) {

      printf("DosKillProcess error: return code = %u\n", rc);

      return 1;

   }



   rc = DosSleep(45000L);    /* Dead code */



   return NO_ERROR;

}
Exemplo n.º 7
0
int main (int argc, char *argv[])
{
  HQUEUE hq_server, hq_client;
  ULONG rc, len;
  PID owner_pid;
  PVOID data;
  REQUESTDATA request;
  BYTE priority;
  char buffer[1024], name[512], *p;
  long client_pid;

  if (argc == 1)
    {
      if (spawnl (P_NOWAIT, argv[0], argv[0], "-r", NULL) < 0)
	  {
	  perror ("spawn");
	  return (1);
	  }
      for (;;)
	{
	  if (fgets (buffer, sizeof (buffer), stdin) == 0)
	    return (0);
	  p = buffer;
	  while (*p != 0 && !(*p >= '0' && *p <= '9'))
	    ++p;
	  client_pid = strtol (p, NULL, 10);
	  (void)sprintf (name, "/queues/emacs/clients/%ld", client_pid);
	  rc = DosOpenQueue (&owner_pid, &hq_client, name);
	  if (rc == 0)
	    {
	      len = strlen (buffer) + 1;
	      rc = DosAllocSharedMem (&data, 0, len,
				      PAG_COMMIT | OBJ_GIVEABLE | PAG_READ
				      | PAG_WRITE);
	      ERROR ("DosAllocSharedMem");
	      rc = DosGiveSharedMem (data, client_pid, PAG_READ);
	      ERROR ("DosGiveSharedMem");
	      (void)memcpy (data, buffer, len);
	      rc = DosWriteQueue (hq_client, 0, len, data, 0);
	      ERROR ("DosWriteQueue");
	      rc = DosFreeMem (data);
	      ERROR ("DosFreeMem");
	      rc = DosCloseQueue (hq_client);
	      ERROR ("DosCloseQueue");
	    }
	}
    }
  else if (argc == 2 && strcmp (argv[1], "-r") == 0)
    {
      rc = DosCreateQueue (&hq_server, QUE_FIFO | QUE_CONVERT_ADDRESS,
			   "/queues/emacs/server");
      ERROR ("DosCreateQueue");
      for (;;)
	{
	  rc = DosReadQueue (hq_server, &request, &len, &data, 0,
			     DCWW_WAIT, &priority, 0);
	  ERROR ("DosReadQueue");
	  (void)printf ("Client: %d ", (int)request.pid);
	  (void)fputs (data, stdout);
	  (void)fflush (stdout);
	  rc = DosFreeMem (data);
	  ERROR ("DosFreeMem");
	}
    }
  else
    {
      (void)fprintf (stderr, "Usage: %s\n", argv[0]);
      return (1);
    }
}
Exemplo n.º 8
0
 int EXPENTRY icqIPCSendCommand(ULONG uin, ICQQUEUEBLOCK *cmd)
 {
    /* Envia um comando */
    char                buffer[0x0100];
    int                 rc                      = 0;
    PID                 pid;
    HQUEUE              queue;
    ICQQUEUEBLOCK       *shr;
    int                 f;
    char                *src;
    char                *dst;
    USHORT              status;
    REQUESTDATA         req;
    int                 sz;

    if(cmd->szPrefix != sizeof(ICQQUEUEBLOCK) || cmd->sz < sizeof(ICQQUEUEBLOCK))
       return ERROR_INVALID_PARAMETER;

    if(!uin)
    {
       rc = icqIPCQueryInstance(&uin);
       if(rc)
          return rc;
    }

    sz = cmd->sz;

    /* Abre a fila */

    sprintf(buffer,"\\QUEUES\\PWICQ\\%lu",uin);
    rc = DosOpenQueue ( &pid,&queue, buffer);

    if(rc)
       return rc;

    rc = DosAllocSharedMem((PVOID) &shr, NULL, sz, PAG_COMMIT|OBJ_GETTABLE|PAG_READ|PAG_WRITE);

    if(!rc)
    {
       DBGTracex(shr);

       src = (char *) cmd;
       dst = (char *) shr;

       for(f=0;f<sz;f++)
          *(dst++) = *(src++);

       rc = DosWriteQueue(queue, 0, sizeof(ULONG), (PVOID) shr, 0);

       if(!rc)
       {
          DBGMessage("Mensagem escrita na fila");

          for(f=0;f<100 && shr->status == cmd->status;f++)
             DosSleep(10);

          DBGTrace(shr->status == cmd->status);

          src = (char *) shr;
          dst = (char *) cmd;

          for(f=0;f<sz;f++)
             *(dst++) = *(src++);
       }

       DosFreeMem(shr);
    }

    DosCloseQueue(queue);

    return rc;
 }