home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / interop / server.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  4.7 KB  |  165 lines

  1. /*************************************************************/
  2. /**                                                         **/
  3. /**                 Microsoft RPC Examples                  **/
  4. /**                 OSF DCE Interop Application             **/
  5. /**           Copyright(c) Microsoft Corp. 1993-1996        **/
  6. /**                                                         **/
  7. /*************************************************************/
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <ctype.h>
  12.  
  13. #include "msg.h"    /* header file generated by M/IDL compiler */
  14.  
  15. #if defined(__RPC_WIN32__) || defined(__RPC_DOS__)
  16.  
  17. /*
  18.  On MS platforms we must include the dceport.h header file
  19.  which maps OSF DCE style APIs to MS style APIs.
  20.  
  21.  Currently, we must also define a common interface handle name.
  22. */
  23.  
  24. #include "dceport.h"
  25.  
  26. #else
  27. #include <pthread.h>
  28. #endif
  29.  
  30. #ifndef _CRTAPI1
  31. #define _CRTAPI1
  32. #endif
  33.  
  34. void Usage()
  35. {
  36.   printf("Usage : server -e <endpoint>   - optional endpoint\n");
  37.   printf("               -t <transport>  - optional, default ncacn_ip_tcp\n");
  38.   exit(1);
  39. }
  40.  
  41. int _CRTAPI1
  42. main(int argc, char *argv[])
  43. {
  44.     unsigned32 status;
  45.     unsigned char * pszProtocolSequence = (unsigned char *)"ncacn_ip_tcp";
  46.     unsigned char * pszEndpoint         = NULL;
  47.     unsigned int    cMaxCalls           = 20;
  48.     rpc_binding_vector_p_t pbvBindings  = NULL;
  49.     int i;
  50.  
  51.     printf ("Microsoft RPC Demo - OSF DCE Interop Message Server\n");
  52.  
  53.     for (i = 1; i < argc; i++) {
  54.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  55.             switch (tolower(*(argv[i]+1))) {
  56.             case 'e':
  57.                 pszEndpoint = (unsigned char *)argv[++i];
  58.                 break;
  59.             case 't':
  60.                 pszProtocolSequence = (unsigned char *)argv[++i];
  61.                 break;
  62.             case 'h':
  63.             case '?':
  64.             default:
  65.                 Usage();
  66.             }
  67.         }
  68.         else
  69.             Usage();
  70.     }
  71.  
  72.     if (pszEndpoint != NULL)
  73.         {
  74.         /*
  75.          Since we have an explict endpoint, use it and
  76.          wait for client requests.
  77.         */
  78.         rpc_server_use_protseq_ep(pszProtocolSequence,
  79.                                    cMaxCalls,
  80.                                    pszEndpoint,
  81.                                    &status);
  82.         if (status) {
  83.             printf("rpc_server_use_protseq_ep returned 0x%x\n", status);
  84.             return status;
  85.             }
  86.         }
  87.     else
  88.         {
  89.         /*
  90.          No explict endpoint, use the protocol sequence and register
  91.          the endpoint with the endpoint mapper.
  92.         */
  93.         rpc_server_use_protseq(pszProtocolSequence,
  94.                                cMaxCalls,
  95.                                &status);
  96.         if (status) {
  97.             printf("rpc_server_use_protseq returned 0x%x\n", status);
  98.             return status;
  99.             }
  100.  
  101.         rpc_server_inq_bindings(&pbvBindings, &status);
  102.         if (status) {
  103.             printf("rpc_server_inq_bindings returned 0x%x\n", status);
  104.             return status;
  105.             }
  106.  
  107.         rpc_ep_register(interop_v1_0_s_ifspec,
  108.                         pbvBindings,
  109.                         0,
  110.                         0,
  111.                         &status);
  112.         if (status) {
  113.             printf("rpc_ep_register returned 0x%x\n", status);
  114.             return status;
  115.             }
  116.         }
  117.  
  118.     rpc_server_register_if(interop_v1_0_s_ifspec,
  119.                            0,
  120.                            0,
  121.                            &status);
  122.     if (status) {
  123.         printf("rpc_server_register_if returned 0x%x\n", status);
  124.         return status;
  125.     }
  126.  
  127.     printf("RPC server ready\n");
  128.     rpc_server_listen(cMaxCalls,&status);
  129.  
  130.     if (status) {
  131.         printf("rpc_server_listen returned: 0x%x\n", status);
  132.         return status;
  133.     }
  134.  
  135.     rpc_server_unregister_if(interop_v1_0_s_ifspec,
  136.                              0,
  137.                              &status);
  138.     if (status) {
  139.         printf("rpc_server_unregister_if returned 0x%x\n", status);
  140.         return status;
  141.     }
  142.  
  143.     if (pszEndpoint == NULL)
  144.         {
  145.         /*
  146.          Unregister from endpoint mapper
  147.          */
  148.         rpc_ep_unregister(interop_v1_0_s_ifspec,
  149.                           pbvBindings,
  150.                           0,
  151.                           &status);
  152.         if (status) {
  153.             printf("rpc_ep_unregister returned 0x%x\n", status);
  154.             return status;
  155.             }
  156.  
  157.         rpc_binding_vector_free(&pbvBindings, &status);
  158.         if (status) {
  159.             printf("rpc_binding_vector_free returned 0x%x\n", status);
  160.             return status;
  161.             }
  162.         }
  163. }
  164.  
  165.