home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / OS2LAN / CTSPIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  4.0 KB  |  158 lines

  1. /*
  2.  *    OS/2 Lan Manager using named pipes version of c-tree server
  3.  *
  4.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  5.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  6.  *    transfer of this program is strictly prohibited.
  7.  *
  8.  *      Copyright (c) 1987, 1988, 1989 FairCom Corporation
  9.  *    (Subject to limited distribution and
  10.  *     restricted disclosure only.)
  11.  *    *** ALL RIGHTS RESERVED ***
  12.  *
  13.  *    4006 West Broadway
  14.  *    Columbia, MO 65203
  15.  *
  16.  *
  17.  *    c-tree(R)    Version 4.3
  18.  *            Release C
  19.  *            February 7, 1989 17:30
  20.  *
  21.  */
  22.  
  23. #define INCL_DOS
  24. #define INCL_DOSERRORS
  25. #include <os2def.h>       /* Common definitions */
  26. #include <bsedos.h>       /* Base definitions */
  27. #include <bseerr.h>       /* Base error code definitions */
  28.  
  29. #include <net\netcons.h>
  30. #ifndef INCL_DOSNMPIPES   /* This define i set if MS SDK 1.06 include files */
  31. #include <net\nmpipe.h>
  32. #endif
  33.  
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <malloc.h>
  38.  
  39. #include "ctpipes.h"
  40.  
  41. /*
  42.  * Receive buffer for call DosTransactNmPipe 
  43.  * in and out buffer could not be the same ??????!!!!!!?????
  44.  */
  45.  
  46. unsigned pipe_errcode;
  47.  
  48. unsigned makepipe(unsigned *handle, char *pipename)
  49. {
  50.    pipe_errcode = DosMakeNmPipe(pipename, handle,
  51.                                 SRV_DOSOPENMODE, SRV_PIPOPENMODE,
  52.                                 PIPESIZE, PIPESIZE, PIPE_TIMEOUT);
  53.    return(pipe_errcode);
  54. }
  55.  
  56. unsigned sendlogonreply(unsigned handle)
  57. {
  58. long yes_i_am = PIPE_ANSW;
  59.  
  60.    writepipe(handle, (char far *)&yes_i_am, sizeof(long));
  61.  
  62.    return(pipe_errcode);
  63. }
  64.  
  65. unsigned readpipe(unsigned handle, char far *buffer)
  66. {
  67. USHORT bytes;
  68.  
  69.    /*
  70.     * we will now hang on ConnectNmPipe until something to do
  71.     */
  72.    /* here we should implemet set to non-blocking mode
  73.       to se if any request is made, else sleep.
  74.       We could also implement several handles for many instances of
  75.       pipes to be opened */
  76.    if (!(pipe_errcode = DosConnectNmPipe(handle)) ) {
  77.       pipe_errcode = DosRead((HFILE)handle, buffer, (unsigned)PIPESIZE, &bytes);
  78.    }
  79.  
  80.    return(pipe_errcode ? 0 : bytes);
  81. }
  82.  
  83.  
  84. unsigned writepipe(unsigned handle, char far *buffer, unsigned len)
  85. {
  86. USHORT bytes;
  87. char     dummy[4];
  88. unsigned short rbytes, avail, status;
  89.  
  90.    if (!(pipe_errcode = DosWrite((HFILE)handle, buffer, len, &bytes))) {
  91.       for (;;) {
  92.          rbytes = 0;
  93.          avail  = 0;
  94.          if ((pipe_errcode = DosPeekNmPipe(handle, dummy, 0, &rbytes,
  95.                                       &avail, &status))) {
  96.             break;
  97.          }
  98.  
  99.          if (status == NP_CLOSING)
  100.             break;
  101.  
  102.          DosSleep(10L);
  103.  
  104.       }    
  105.       pipe_errcode = DosDisConnectNmPipe(handle);
  106.    }
  107.  
  108.    return(pipe_errcode ? 0 : bytes);
  109. }
  110.  
  111. unsigned disconnect_pipe(unsigned handle)
  112. {
  113.    pipe_errcode = DosClose(handle);
  114.    return(pipe_errcode);
  115. }
  116.  
  117. /*
  118.  * This function is used to try to set Server application 
  119.  * to a higer priority level than the application(and other) 
  120.  * for faster performance.
  121.  * I have not succeded in doing this, becuase a background process
  122.  * always get less priority than the foreground procces.
  123.  * At time-critical level the server will not recive  request
  124.  * from the server.
  125.  * Temporarly we then use this fuction as a DUMMY.
  126.  */
  127. void set_exec_priority(int max_min)  /* 0 = min, 1 = max */
  128. {
  129. USHORT id;            /* process or thread identifier  */
  130. USHORT retval;
  131. static short first = 0;
  132. USHORT prio;
  133. static int pri_class;
  134. static int pri_level;
  135.  
  136. static SHORT  pr_max = 15, pr_min = -31, pr_class = 5;
  137.  
  138.    return;
  139.  
  140.    id = get_process_id();
  141.  
  142.    if (!first) {
  143.       retval = DosGetPrty(PRTYS_PROCESS, &prio, id);
  144.       pri_class = HIBYTE(prio);
  145.       pri_level = LOBYTE(prio);
  146.       first++;
  147.    }
  148.    if (max_min) {
  149.       retval = DosSetPrty(PRTYS_PROCESS, PRTYC_TIMECRITICAL, pr_max, id);
  150.    }
  151.    else
  152.       /* set back to normal */
  153.       retval = DosSetPrty(PRTYS_PROCESS, pri_class, pri_level, id);
  154.  
  155. }
  156.  
  157.  
  158.