SERVER.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

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