Annotation of mstools/samples/rpc/dict/server.c, revision 1.1.1.1

1.1       root        1: /*************************************************************/
                      2: /**                                                         **/
                      3: /**                 Microsoft RPC Examples                  **/
                      4: /**                 Dictionary Application                  **/
                      5: /**             Copyright(c) Microsoft Corp. 1991           **/
                      6: /**                                                         **/
                      7: /*************************************************************/
                      8: 
                      9: /*
                     10:  *************************************************************************
                     11:  * Remote dictionary example: server side                                *
                     12:  *                                                                       *
                     13:  * Created:                                 Dov Harel   12/??/1990       *
                     14:  * Modified to use context_handle           Donna Liu    3/??/1991       *
                     15:  * Further modifications / documentation    Dov Harel    5/1/1991        *
                     16:  *                                                                       *
                     17:  * Description:                                                          *
                     18:  * This is the driver for the server side remote dictionary              *
                     19:  * (splay trees based) demo.  This is a standard server driver,          *
                     20:  * and it works as follows:                                              *
                     21:  *                                                                       *
                     22:  *  o Call RpcCreateServer to initialize all data structures             *
                     23:  *                                                                       *
                     24:  *  o Initialize an appropriate protocol stack                           *
                     25:  *                                                                       *
                     26:  *  o Call RpcAddAddress to start listening on a transport address       *
                     27:  *    (a named pipe in our case).                                        *
                     28:  *                                                                       *
                     29:  *  o Call RpcAddInterface to initialize interface specific structures   *
                     30:  *    (such as dispatch table, etc.)                                     *
                     31:  *                                                                       *
                     32:  *  o Optionally advertise by calling RpcExport (not in this version)    *
                     33:  *                                                                       *
                     34:  *  o Loop forever...                                                    *
                     35:  *                                                                       *
                     36:  *************************************************************************
                     37: */
                     38: 
                     39: #include <stdio.h>
                     40: #include <malloc.h>
                     41: #include <stdlib.h>
                     42: #include <string.h>
                     43: #include <ctype.h>
                     44: #include <windows.h>
                     45: 
                     46: #include <rpc.h>
                     47: #include "dict0.h"
                     48: #include "replay.h"
                     49: #include "util0.h"
                     50: 
                     51: // char *server = "\\pipe\\rpc\\replay";
                     52: void exit(int);
                     53: 
                     54: void Usage()
                     55: {
                     56:   printf("Usage : server -a<address>\n");
                     57:   exit(1);
                     58: }
                     59: 
                     60: void
                     61: main(int argc, char *argv[])
                     62: {
                     63:   int                   argscan;
                     64:   char *                InterfaceAddress = NULL;
                     65:   RPC_HANDLE            Server, Address, Interface;
                     66:   RPC_STATUS            status;
                     67: 
                     68: 
                     69:   for (argscan = 1; argscan < argc; argscan++)
                     70:     {
                     71:       if (argv[argscan][0] == '-')
                     72:         {
                     73:           switch (argv[argscan][1])
                     74:             {
                     75:               case 'a':
                     76:               case 'A':
                     77:                 InterfaceAddress = &(argv[argscan][2]);
                     78:                 break;
                     79:               default:
                     80:                 Usage();
                     81:             }
                     82:         }
                     83:       else
                     84:         Usage();
                     85:     }
                     86:   if (InterfaceAddress == NULL)
                     87: #ifndef OLDOS
                     88:       InterfaceAddress = "\\device\\namedpipe\\dict";
                     89: #else // OLDOS
                     90:       InterfaceAddress = "\\pipe\\dict";
                     91: #endif // OLDOS
                     92: 
                     93:   status = RpcCreateServer((RPC_EVENT_HANDLERS *) 0, &Server);
                     94:   printf ("server created\n");
                     95:   if (status)
                     96:     {
                     97:       printf("RpcCreateServer = %lu\n",status);
                     98:       exit(2);
                     99:     }
                    100: 
                    101:   /* Initialize required protocol stack fields */
                    102:   dict_ProtocolStack.StackType = RPC_STACK_TYPE_V1;
                    103:   dict_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE;
                    104:   dict_ProtocolStack.TransportInfo = InterfaceAddress;
                    105:   dict_ProtocolStack.TransportInfoLength = strlen(InterfaceAddress)+1;
                    106: 
                    107:   status = RpcAddAddress(
                    108:     Server,
                    109:     &dict_ProtocolStack,
                    110:     0, // Do not prevent deadlock...
                    111:     &Address,
                    112:     (void *)0, // Reserved for security information...
                    113:     RpcNormalResourceUsage,
                    114:     0L // No timeout...
                    115:     );
                    116: 
                    117:   printf ("server address added\n");
                    118: 
                    119:   if (status)
                    120:     {
                    121:       printf("RpcAddAddress = %lu\n",status);
                    122:       exit(2);
                    123:     }
                    124:   status = RpcAddInterface(
                    125:     Server,
                    126:     &dict_ProtocolStack,
                    127:     &Interface,
                    128:     (void *)0, // Reserved for security information...
                    129:     &dict_DispatchTable
                    130:     );
                    131: 
                    132:   printf ("server interface added\n");
                    133: 
                    134:   if (status)
                    135:     {
                    136:       printf("RpcAddInterface = %lu\n",status);
                    137:       exit(2);
                    138:     }
                    139: 
                    140: /*
                    141:   status = RpcExport(Server, 1, &dict_ProtocolStack);
                    142:   printf ("server exported\n");
                    143: 
                    144:  * The above is required for advertising that the server is serving
                    145:  * a particular interface (using a locator or alternatively a
                    146:  * directory service / name service).  Strictly equired for clients
                    147:  * using auto_handle.
                    148: 
                    149: */
                    150: 
                    151:   if (status)
                    152:     {
                    153:       printf("RpcExport = %lu\n",status);
                    154:       exit(2);
                    155:     }
                    156: 
                    157:   while (1)
                    158:     {
                    159: #ifndef OLDOS
                    160:         Sleep(5000L);
                    161: #else // OLDOS
                    162:         DosSleep(5000L);
                    163: #endif // OLDOS
                    164: 
                    165:     }
                    166: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.