Home

GEONius.com
2-Oct-2015
E-mail

nix_util - Network I/O Handler

This package has been superseded by the IOX I/O Event Dispatcher.

The functions in this file implement an X Toolkit-style I/O event dispatcher. Applications that make use of the NIX dispatcher are generally structured as follows:

    Perform any application-specific initialization activities.
    Register event callbacks with the NIX event dispatcher.
    do forever
        Wait for the next event.
        call the callback bound to the event.
    enddo

The event processing loop is encapsulated in a NIX function, NxMainLoop(). Other NIX functions are available to:

The NIX_UTIL functions are patterned after the following X Toolkit functions:

        NxAddInput ()		-	XtAppAddInput ()
        NxAddTimeOut ()		-	XtAppAddTimeOut ()
        NxAddWorkProc ()	-	XtAppAddWorkProc ()
        NxMainLoop ()		-	XtAppMainLoop ()
        NxRemoveInput ()	-	XtRemoveInput ()
        NxRemoveTimeOut ()	-	XtRemoveTimeOut ()
        NxRemoveWorkProc ()	-	XtRemoveWorkProc ()

I/O sources are registered with the NIX dispatcher by NxAddInput(), timeout timers by NxAddTimeOut(), and work procedures by NxAddWorkProc(). The dispatcher itself is contained in NxMainLoop(). Once called, NxMainLoop(), like XtAppMainLoop(), never returns; it loops forever, waiting for I/O and timer events and invoking the application-specified callback functions bound to the events.

The following program (working) shows a simple application of the NIX functions to reading standard input and echoing it to standard output:

    #include  <stdio.h>			-- Standard I/O definitions.
    #include  "nix_util.h"		-- Network I/O Handler definitions.

    static  int  ReadInput (...)	-- Standard input callback.
    {
        char  buffer[128] ;
        if (gets (buffer) == NULL)  exit (0) ;
        printf ("ReadInput: %s\n", buffer) ;
    }

    main (...)				-- Main routine.
    {
        NxAddInput (NULL, fileno (stdin), NxInputReadMask, ReadInput, NULL) ;
        NxMainLoop (NULL) ;
    }

The NIX main loop is implemented using a UNIX select(2) call and it supports read, write, and exceptional I/O events (much like the X Toolkit does). The NIX functions have been tested on UNIX and VMS machines and, if you get the header files straight, they should work under operating systems like VxWorks that support select(2).

Under VMS, you can use the select(2) implementation or, by calling NxMainLoopEF(), an event flag-based implementation a la DECWindows. The VMS UCX implementation of select(2) only supports socket I/O and not arbitrary device I/O as in UNIX; event flags provide this missing capability.


Public Procedures

NxAddInput() - registers an I/O source with the NIX dispatcher.
NxAddTimeOut() - registers a timeout callback with the NIX dispatcher.
NxAddWorkProc() - registers a background work procedure with the NIX dispatcher.
NxCreateContext() - creates an application context.
NxMainLoop() - monitors and responds to I/O events and timeouts.
NxMainLoopEF() - monitors and responds to I/O events and timeouts using event flags (VMS only).
NxRemoveInput() - removes the registration of an I/O source.
NxRemoveTimeOut() - removes the registration of a timeout callback.
NxRemoveWorkProc() - removes the registration of a work procedure.
NxSetDebug() - enables/disables debug output.

Source Files

nix_util.c
nix_util.h

(See libnet for the complete source, including support routines and build files.)


Alex Measday  /  E-mail