home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / fssht / shiprot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  6.6 KB  |  148 lines

  1. /*static char *SCCSID = "@(#)shiprot.c    13.2 92/05/01";*/
  2. /****************************************************************************/
  3. /*                                                                          */
  4. /*                    Copyright (c) IBM Corporation 1992                    */
  5. /*                           All Rights Reserved                            */
  6. /*                                                                          */
  7. /* SOURCE FILE NAME: SHIPROT.C                                              */
  8. /*                                                                          */
  9. /* DESCRIPTIVE NAME:  Stream Handler Install Protocol Routine               */
  10. /*                                                                          */
  11. /* NOTES: This is a DLL file. This function is mainly for tuning streams    */
  12. /*        performance by changing the buffer attributes.                    */
  13. /*                                                                          */
  14. /* ENTRY POINTS: ShcInstallProtocol                                         */
  15. /*                                                                          */
  16. /*************************** END OF SPECIFICATIONS **************************/
  17. #define  INCL_NOPMAPI                  /* no PM include files required */
  18. #define  INCL_DOSSEMAPHORES
  19. #define  INCL_DOSPROCESS
  20. #include <os2.h>
  21. #include <os2me.h>
  22. #include <hhpheap.h>
  23. #include <shi.h>
  24.  
  25. /************************** START OF SPECIFICATIONS *************************/
  26. /*                                                                          */
  27. /* SUBROUTINE NAME: ShcInstallProtocol                                      */
  28. /*                                                                          */
  29. /* DESCRIPTIVE NAME: Stream Handler Command Install Protocol                */
  30. /*                                                                          */
  31. /* FUNCTION: This updates the specified spcb with new values                */
  32. /*                                                                          */
  33. /* NOTES:                                                                   */
  34. /*                                                                          */
  35. /* ENTRY POINT: ShcInstallProtocol                                          */
  36. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  37. /*                                                                          */
  38. /* INPUT:                                                                   */
  39. /*                                                                          */
  40. /* EXIT-NORMAL:                                                             */
  41. /*                                                                          */
  42. /* EXIT-ERROR:                                                              */
  43. /*                                                                          */
  44. /* SIDE EFFECTS:                                                            */
  45. /*                                                                          */
  46. /* INTERNAL REFERENCES:                                                     */
  47. /*        ROUTINES:                                                         */
  48. /*                                                                          */
  49. /* EXTERNAL REFERENCES:                                                     */
  50. /*        ROUTINES:                                                         */
  51. /*        DATA STRUCTURES:                                                  */
  52. /*                                                                          */
  53. /*************************** END OF SPECIFICATIONS **************************/
  54.  
  55. RC ShcInstallProtocol(pipparm)
  56. PPARM_INSTPROT pipparm;
  57.  
  58. { /* Start of ShcInstallProtocol */
  59.  
  60. RC rc = NO_ERROR;                       // local return code
  61. int notfound = TRUE;
  62. PESPCB pTempEspcb;
  63. PESPCB pPrevEspcb;
  64.  
  65.   //
  66.   // the ESPCB list is under semphore control
  67.   //
  68.   if (!(rc = DosRequestMutexSem(hmtxGlobalData, SEM_INDEFINITE_WAIT)))
  69.     { /* obtained semaphore */
  70.       if (pipparm->ulFlags & SPI_DEINSTALL_PROTOCOL)
  71.         { /* DeInstall */
  72.           //
  73.           // To Deinstall, Find the spcb,
  74.           //               Take it off the espcb chain,
  75.           //               Free the espcb memory allocated
  76.           //
  77.           rc = ERROR_INVALID_SPCBKEY;
  78.           pPrevEspcb = NULL;
  79.           pTempEspcb = pESPCB_ListHead;
  80.           while (pTempEspcb && notfound)
  81.             { /* Loop thru espcbs */
  82.               if ((pipparm->spcbkey.ulDataType == pTempEspcb->spcb.spcbkey.ulDataType) &&
  83.                   (pipparm->spcbkey.ulDataSubType == pTempEspcb->spcb.spcbkey.ulDataSubType) &&
  84.                   (pipparm->spcbkey.ulIntKey == pTempEspcb->spcb.spcbkey.ulIntKey))
  85.                 { /* found match */
  86.                   notfound = FALSE;
  87.                   rc = NO_ERROR;
  88.                   //
  89.                   // Take the espcb off the chain
  90.                   //
  91.                   if (pPrevEspcb)
  92.                     {
  93.                       pPrevEspcb->pnxtESPCB = pTempEspcb->pnxtESPCB;
  94.                     }
  95.                   else
  96.                     {
  97.                       pESPCB_ListHead = pTempEspcb->pnxtESPCB;
  98.                     }
  99.  
  100.                   HhpFreeMem(hHeap, pTempEspcb);
  101.  
  102.                 } /* found match */
  103.               else
  104.                 { /* try the next espcb in the chain */
  105.  
  106.                   pPrevEspcb = pTempEspcb;
  107.                   pTempEspcb = pTempEspcb->pnxtESPCB;
  108.  
  109.                 } /* try the next espcb in the chain */
  110.             } /* Loop thru espcbs */
  111.         } /* DeInstall */
  112.       else
  113.         { /* Install */
  114.           //
  115.           // If the spcb already exists then error
  116.           //
  117.           if (ShFindEspcb(pipparm->spcbkey))
  118.             {
  119.               rc = ERROR_INVALID_SPCBKEY;
  120.             }
  121.           else
  122.             { /* Ok to add spcb */
  123.               //
  124.               // Allocate the espcb and put it on the front of the chain
  125.               //
  126.               pTempEspcb = (PESPCB)HhpAllocMem(hHeap, sizeof(ESPCB));
  127.               if (pTempEspcb)
  128.                 {
  129.                   pTempEspcb->spcb = *(pipparm->pspcb);
  130.                   pTempEspcb->pnxtESPCB = pESPCB_ListHead;
  131.                   pESPCB_ListHead = pTempEspcb;
  132.                 }
  133.               else
  134.                 {
  135.                   rc = ERROR_ALLOC_RESOURCES;
  136.                 }
  137.             } /* Ok to add spcb */
  138.  
  139.         } /* Install */
  140.  
  141.       DosReleaseMutexSem(hmtxGlobalData);
  142.  
  143.     } /* obtained semaphore */
  144.  
  145.   return(rc);
  146.  
  147. } /* End of ShcInstallProtocol */
  148.