Novell Home

How to intercept EVENT LOGOUT CONNECTION (NetWare)

From Developer Community

This code demonstrates how to use RegisterForEvent() to install a handler for EVENT_LOGOUT_CONNECTION event

Sample Code

#include <nwadv.h>
#include <nwconn.h>
#include <nwerrno.h>
#include <nwthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

static int threadCount   = 0;
static int exitRequested = 0;
static int mainThreadID;
static int mainThreadGroupID;

static void sigHandler( int sig_no) {
#ifdef __MWERKS__
#pragma unused( sig_no)
#endif
   int saved_thread_group_ID = SetThreadGroupID( mainThreadGroupID);
   signal( SIGTERM, sigHandler);
   exitRequested = !0;
   ResumeThread( mainThreadID);
   while ( threadCount) delay( 100);
   SetThreadGroupID( saved_thread_group_ID);
}
static void eventProc( LONG param, LONG user_param) {
#ifdef __MWERKS__
#pragma unused( user_param)
#endif
   ++threadCount;
   printf( "logged out conn = %d\n", param);
   --threadCount;
}
int main() {
   LONG event_handle;
   ++threadCount;
   mainThreadID      = GetThreadID();
   mainThreadGroupID = GetThreadGroupID();
   signal( SIGTERM, sigHandler);
   event_handle = RegisterForEvent( EVENT_LOGOUT_CONNECTION, eventProc, NULL);
   if ( event_handle == EFAILURE) {
      puts( "RegisterForEvent failed");
      return EXIT_FAILURE;
   }
   puts( "Waiting...");
   SuspendThread( mainThreadID);
   UnregisterForEvent( event_handle);
   while ( threadCount > 1) delay( 100);
   --threadCount;
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.