Пример #1
0
//---------------------------------------------------------------------------
//  FUNCTION: BOOL DoRnrServer(char * pszServerName, int  nServerType)
//
//  PURPOSE:  The driver for the server side code. It forms the global
//            class id "g_MyGuid" for this service class, installs this
//            service class, advertises the service name "pszServerName" with 
//            the associated bound SOCKADDR addresses and then loop through 
//            for data sent by client. This routine returns if user hits "Ctrl-C" 
//            or any error encountered.
//
//  RETURNS:
//    TRUE if user hits "Ctrl-C" to end the server program.
//    FALSE if there is any error encountered.
//
//---------------------------------------------------------------------------
BOOL DoRnrServer(char * pszServerName, int  nServerType)
{
    // I am using SVCID_NETWARE macro to form a common class id for the
    // client and server program such that the client program can also query 
    // some known SAP services on the network without running this program
    // as a server.
    // You can also generate your own class id by uuidgen.exe or guidgen.exe and
    // distribute the class id to client program.
    //
    // Please check svcguid.h for details about the macro.
    GUID guidNW = SVCID_NETWARE(nServerType); 

    memcpy(&g_MyGuid, &guidNW, sizeof(GUID));

    if (!SetConsoleCtrlHandler(CtrlHandler, TRUE))
    {
        printf ("SetConsoleCtrlHandler failed to install console handler: %d\n", 
                GetLastError());
        return FALSE;
    }
    // Install the server class
    if (!InstallClass(nServerType))
    {
        return FALSE;
    }
    // advertise the server instance
    if (!Advertise(pszServerName))
    {
        return FALSE;
    }

    // Make our bound sockets non-blocking such that
    // we can loop and test for data sent by client
    // without blocking.
    u_long arg = 1L;
    for (int i = 0; i < g_nNumOfUsedSocks; i++)
    {
        // make the socket as non-blocking socket
        if (ioctlsocket(g_aSock[i], FIONBIO, &arg) == SOCKET_ERROR)
        {
            printf("ioctlsocket[%d] error %d\n", i, WSAGetLastError());
            return FALSE;
        }
    }

    // receive data from client who find our address thru Winsock 2 RnR
    for (;;)
    {
        if (ServerRecv() == FALSE)
        {
            return FALSE;
        }
        if (fEndProgram)
            return TRUE;
        Sleep(100);
    }
}
Пример #2
0
/*****************************************************************************
  NAME         : AddClass
  DESCRIPTION  : Determines the precedence list of the new class.
                 If it is valid, the routine checks to see if the class
                 already exists.  If it does not, all the subclass
                 links are made from the class's direct superclasses,
                 and the class is inserted in the hash table.  If it
                 does, all sublclasses are deleted. An error will occur
                 if any instances of the class (direct or indirect) exist.
                 If all checks out, the old definition is replaced by the new.
  INPUTS       : The new class description
  RETURNS      : Nothing useful
  SIDE EFFECTS : The class is deleted if there is an error.
  NOTES        : No change in the class graph state will occur
                 if there were any errors.
                 Assumes class is not busy!!!
 *****************************************************************************/
static void AddClass(
  void *theEnv,
  DEFCLASS *cls)
  {
   DEFCLASS *ctmp;
#if DEBUGGING_FUNCTIONS
   int oldTraceInstances = FALSE,
       oldTraceSlots = FALSE;
#endif

   /* ===============================================
      If class does not already exist, insert and
      form progeny links with all direct superclasses
      =============================================== */
   cls->hashTableIndex = HashClass(GetDefclassNamePointer((void *) cls));
   ctmp = (DEFCLASS *) EnvFindDefclass(theEnv,EnvGetDefclassName(theEnv,(void *) cls));

   if (ctmp != NULL)
     {
#if DEBUGGING_FUNCTIONS
      oldTraceInstances = ctmp->traceInstances;
      oldTraceSlots = ctmp->traceSlots;
#endif
      DeleteClassUAG(theEnv,ctmp);
     }
   PutClassInTable(theEnv,cls);

   BuildSubclassLinks(theEnv,cls);
   InstallClass(theEnv,cls,TRUE);
   AddConstructToModule((struct constructHeader *) cls);

   FormInstanceTemplate(theEnv,cls);
   FormSlotNameMap(theEnv,cls);

   AssignClassID(theEnv,cls);

#if DEBUGGING_FUNCTIONS
   if (cls->abstract)
     {
      cls->traceInstances = FALSE;
      cls->traceSlots = FALSE;
     }
   else
     {
      if (oldTraceInstances)
        cls->traceInstances = TRUE;
      if (oldTraceSlots)
        cls->traceSlots = TRUE;
     }
#endif

#if DEBUGGING_FUNCTIONS
   if (EnvGetConserveMemory(theEnv) == FALSE)
     SetDefclassPPForm((void *) cls,CopyPPBuffer(theEnv));
#endif

#if DEFMODULE_CONSTRUCT

   /* =========================================
      Create a bitmap indicating whether this
      class is in scope or not for every module
      ========================================= */
   cls->scopeMap = (BITMAP_HN *) CreateClassScopeMap(theEnv,cls);

#endif

   /* ==============================================
      Define get- and put- handlers for public slots
      ============================================== */
   CreatePublicSlotMessageHandlers(theEnv,cls);
  }