\hypertarget{nmsgLib_8h}{
\section{nmsg\-Lib.h File Reference}
\label{nmsgLib_8h}\index{nmsgLib.h@{nmsgLib.h}}
}
Definitions for the network message routines. 



This graph shows which files directly or indirectly include this file:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=105pt]{nmsgLib_8h__dep__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{structnmsgHead__s}{nmsg\-Head\_\-s}
\begin{CompactList}\small\item\em Network message header. \item\end{CompactList}\item 
struct \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-s}
\begin{CompactList}\small\item\em Prototype message buffer. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{nmsgLib_8h_a0}{
typedef \hyperlink{structnmsgHead__s}{nmsg\-Head\_\-s} \hyperlink{nmsgLib_8h_a0}{nmsg\-Head\_\-t}}
\label{nmsgLib_8h_a0}

\begin{CompactList}\small\item\em Network message header. \item\end{CompactList}\item 
\hypertarget{nmsgLib_8h_a1}{
typedef \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-s} \hyperlink{nmsgLib_8h_a1}{nmsg\-Buff\_\-t}}
\label{nmsgLib_8h_a1}

\begin{CompactList}\small\item\em Prototype message buffer. \item\end{CompactList}\item 
typedef int \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t} (void $\ast$hndl, void $\ast$$\ast$u\-Parm)
\begin{CompactList}\small\item\em Connect callback routine. \item\end{CompactList}\item 
typedef int \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t} (void $\ast$hndl, void $\ast$$\ast$u\-Parm)
\begin{CompactList}\small\item\em Disconnect callback routine. \item\end{CompactList}\item 
typedef int \hyperlink{nmsgLib_8h_a4}{nmsg\-Rcve\-CB\_\-t} (void $\ast$hndl, void $\ast$$\ast$u\-Parm, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$msg, char $\ast$$\ast$data\-P)
\begin{CompactList}\small\item\em Receive message callback routine. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{nmsgLib_8h_a5}{nmsg\-Connect} (void $\ast$$\ast$hndl, char $\ast$node, int port)
\begin{CompactList}\small\item\em Connect to a message server. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a6}{nmsg\-Connect\-Asy} (void $\ast$$\ast$hndl, char $\ast$node, int port, \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t} conn\-Rtn, \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t} disc\-Rtn, void $\ast$u\-Parm)
\begin{CompactList}\small\item\em Connect asynchronously (robustly) to a message server. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a7}{nmsg\-Listen} (void $\ast$$\ast$hndl, int port, int max\-Conn, int max\-Data, \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t} conn\-Rtn, \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t} disc\-Rtn, \hyperlink{nmsgLib_8h_a4}{nmsg\-Rcve\-CB\_\-t} rcve\-Rtn, void $\ast$u\-Parm)
\begin{CompactList}\small\item\em Establish a message server. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a8}{nmsg\-Close} (void $\ast$hndl, int force)
\begin{CompactList}\small\item\em Terminate a message client or server. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a9}{nmsg\-Send\-W} (void $\ast$hndl, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$msg, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$$\ast$reply\-P, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$reply, int max\-Data)
\begin{CompactList}\small\item\em Send a message and receive reply. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a10}{nmsg\-Send} (void $\ast$hndl, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$msg)
\begin{CompactList}\small\item\em Send a message and return immediately. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a11}{nmsg\-Wait} (void $\ast$hndl, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$$\ast$reply\-P, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$reply, int max\-Data)
\begin{CompactList}\small\item\em Wait for a reply to a sent message. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a12}{nmsg\-Remote\-IP} (void $\ast$hndl)
\begin{CompactList}\small\item\em Get the IP address of the remote end. \item\end{CompactList}\item 
int \hyperlink{nmsgLib_8h_a13}{nmsg\-Check} (void $\ast$hndl)
\begin{CompactList}\small\item\em Check a network connection handle. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Definitions for the network message routines. 

\begin{Desc}
\item[Author:]Owen H Saxton\end{Desc}
\begin{Desc}
\item[Id]\hyperlink{nmsgLib_8h}{nmsg\-Lib.h},v 1.6 2007/02/26 17:34:20 saxton Exp \end{Desc}


\subsection{Typedef Documentation}
\hypertarget{nmsgLib_8h_a2}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgConnCB_t@{nmsgConnCB\_\-t}}
\index{nmsgConnCB_t@{nmsgConnCB\_\-t}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgConnCB\_\-t]{\setlength{\rightskip}{0pt plus 5cm}typedef int \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t}(void $\ast$hndl, void $\ast$$\ast$u\-Parm)}}
\label{nmsgLib_8h_a2}


Connect callback routine. 

This routine, if supplied to the listen or asynchronous connection routine, is called whenever a network connection is established.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the network connection.\item[{\em u\-Parm}]The user parameter supplied in the call to the listen or connection routine.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Accept the connection. \item[{\em -1}]Reject the connection (for listen callback only).\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a3}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgDiscCB_t@{nmsgDiscCB\_\-t}}
\index{nmsgDiscCB_t@{nmsgDiscCB\_\-t}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgDiscCB\_\-t]{\setlength{\rightskip}{0pt plus 5cm}typedef int \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t}(void $\ast$hndl, void $\ast$$\ast$u\-Parm)}}
\label{nmsgLib_8h_a3}


Disconnect callback routine. 

This routine, if supplied to the listen or asynchronous connection routine, is called whenever the network connection is broken.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the network connection.\item[{\em u\-Parm}]The user parameter supplied in the call to the listen or connection routine.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The return value is ignored.\end{Desc}
\hypertarget{nmsgLib_8h_a4}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgRcveCB_t@{nmsgRcveCB\_\-t}}
\index{nmsgRcveCB_t@{nmsgRcveCB\_\-t}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgRcveCB\_\-t]{\setlength{\rightskip}{0pt plus 5cm}typedef int \hyperlink{nmsgLib_8h_a4}{nmsg\-Rcve\-CB\_\-t}(void $\ast$hndl, void $\ast$$\ast$u\-Parm, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$msg, char $\ast$$\ast$data\-P)}}
\label{nmsgLib_8h_a4}


Receive message callback routine. 

This routine is called whenever a message is received on the server (listener) side of a network connection. It processes the message and generates a reply. Normally the whole reply is placed in the area occupied by the incoming message, and can contain data up to the maximum length established in the original listen call. However, the data portion of the reply may alternatively be supplied in a piece of allocated memory and has no restriction on its size in this case.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the network connection.\item[{\em u\-Parm}]The user parameter supplied in the call to the listen routine.\item[{\em msg}]The address of the received message.\item[{\em data\-P}]The address of a pointer to optionally receive the address of an alternate data area. This area must have been allocated via a call to malloc().\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The return value is ignored.\end{Desc}


\subsection{Function Documentation}
\hypertarget{nmsgLib_8h_a13}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgCheck@{nmsgCheck}}
\index{nmsgCheck@{nmsgCheck}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgCheck]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Check (void $\ast$ {\em hndl})}}
\label{nmsgLib_8h_a13}


Check a network connection handle. 

This routine checks whether a network handle is valid or not.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the connection.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 1}]The handle is valid. \item[{\em 0}]The handle is invalid.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a8}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgClose@{nmsgClose}}
\index{nmsgClose@{nmsgClose}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgClose]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Close (void $\ast$ {\em hndl}, int {\em force})}}
\label{nmsgLib_8h_a8}


Terminate a message client or server. 

This routine closes a network connection or stops a network server.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle of the connection or server.\item[{\em force}]For a client connection, if TRUE, the connection is closed even if another task is in the process of sending a message. If FALSE, the closing waits until any activity has ceased. Not used for a server.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a5}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgConnect@{nmsgConnect}}
\index{nmsgConnect@{nmsgConnect}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgConnect]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Connect (void $\ast$$\ast$ {\em hndl}, char $\ast$ {\em node}, int {\em port})}}
\label{nmsgLib_8h_a5}


Connect to a message server. 

This routine establishes a network connection to a message server.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The address of a pointer to receive the identifying handle for the network connection.\item[{\em node}]The address of the name of the node containing the message server.\item[{\em port}]The port number on which to establish the connection.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]The connection was established successfully. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a6}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgConnectAsy@{nmsgConnectAsy}}
\index{nmsgConnectAsy@{nmsgConnectAsy}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgConnectAsy]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Connect\-Asy (void $\ast$$\ast$ {\em hndl}, char $\ast$ {\em node}, int {\em port}, \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t} {\em conn\-Rtn}, \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t} {\em disc\-Rtn}, void $\ast$ {\em u\-Parm})}}
\label{nmsgLib_8h_a6}


Connect asynchronously (robustly) to a message server. 

This routine establishes a robust network connection to a message server. The connection is done asynchronously, and the attempt is retried periodically if the initial attempt fails, or if the connection is broken.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The address of a pointer to receive the identifying handle for the network connection.\item[{\em node}]The address of the name of the node containing the message server.\item[{\em port}]The port number on which to establish the connection.\item[{\em conn\-Rtn}]The address of a routine to be called when the connection has been made.\item[{\em disc\-Rtn}]The address of a routine to be called when the connection is broken.\item[{\em u\-Parm}]A parameter to be passed to the connect and disconnect callback routines.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]The connection process was started successfully. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a7}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgListen@{nmsgListen}}
\index{nmsgListen@{nmsgListen}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgListen]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Listen (void $\ast$$\ast$ {\em hndl}, int {\em port}, int {\em max\-Conn}, int {\em max\-Data}, \hyperlink{nmsgLib_8h_a2}{nmsg\-Conn\-CB\_\-t} {\em conn\-Rtn}, \hyperlink{nmsgLib_8h_a3}{nmsg\-Disc\-CB\_\-t} {\em disc\-Rtn}, \hyperlink{nmsgLib_8h_a4}{nmsg\-Rcve\-CB\_\-t} {\em rcve\-Rtn}, void $\ast$ {\em u\-Parm})}}
\label{nmsgLib_8h_a7}


Establish a message server. 

This routine establishes a network message server (listener).

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The address of a pointer to receive the identifying handle for the network listener.\item[{\em port}]The port number on which to establish the server.\item[{\em max\-Conn}]The maximum number of concurrent connections that the server will allow.\item[{\em max\-Data}]The maximum number of data bytes that can be transferred in a single message.\item[{\em conn\-Rtn}]The address of a routine to be called when a new connection has been made. The connection will be rejected if this routine returns ERROR status.\item[{\em disc\-Rtn}]The address of a routine to be called when a connection is broken.\item[{\em rcve\-Rtn}]The address of a routine to be called whenever a message is received.\item[{\em u\-Parm}]A parameter to be passed to the connect, disconnect and receive callback routines.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]The message server was started successfully. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a12}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgRemoteIP@{nmsgRemoteIP}}
\index{nmsgRemoteIP@{nmsgRemoteIP}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgRemoteIP]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Remote\-IP (void $\ast$ {\em hndl})}}
\label{nmsgLib_8h_a12}


Get the IP address of the remote end. 

This routine returns the IP address of the remote end of a connection. It can be used on either end of a connection.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the connection.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The IP address of the remote end of the connection.\end{Desc}
\hypertarget{nmsgLib_8h_a10}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgSend@{nmsgSend}}
\index{nmsgSend@{nmsgSend}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgSend]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Send (void $\ast$ {\em hndl}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$ {\em msg})}}
\label{nmsgLib_8h_a10}


Send a message and return immediately. 

This routine sends a message on a network connection and returns without waiting for a reply.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the connection.\item[{\em msg}]The address of message to be sent. It must be formatted using the nmsg\-Buff\_\-t structure type.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a9}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgSendW@{nmsgSendW}}
\index{nmsgSendW@{nmsgSendW}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgSendW]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Send\-W (void $\ast$ {\em hndl}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$ {\em msg}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$$\ast$ {\em reply\-P}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$ {\em reply}, int {\em max\-Data})}}
\label{nmsgLib_8h_a9}


Send a message and receive reply. 

This routine sends a message on a network connection and waits for a reply.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the connection.\item[{\em msg}]The address of message to be sent. It must be formatted using the nmsg\-Buff\_\-t structure type.\item[{\em reply\-P}]The address of a pointer to receive the address of the reply. If a reply area is supplied and it is big enough, this will be the address of this area. Otherwise a sufficiently large reply area is allocated and its address returned here. In this latter case, the memory must be relinquished using free() after it is no longer needed.\item[{\em reply}]The address of an area to receive the reply to the message, or NULL if no area is to be used.\item[{\em max\-Data}]The maximum number of data bytes that can be put into the supplied reply area.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
\hypertarget{nmsgLib_8h_a11}{
\index{nmsgLib.h@{nmsg\-Lib.h}!nmsgWait@{nmsgWait}}
\index{nmsgWait@{nmsgWait}!nmsgLib.h@{nmsg\-Lib.h}}
\subsubsection[nmsgWait]{\setlength{\rightskip}{0pt plus 5cm}int nmsg\-Wait (void $\ast$ {\em hndl}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$$\ast$ {\em reply\-P}, \hyperlink{structnmsgBuff__s}{nmsg\-Buff\_\-t} $\ast$ {\em reply}, int {\em max\-Data})}}
\label{nmsgLib_8h_a11}


Wait for a reply to a sent message. 

This routine waits for a reply to a previously sent message.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hndl}]The handle for the connection.\item[{\em reply\-P}]The address of a pointer to receive the address of the reply. If a reply area is supplied and it is big enough, this will be the address of this area. Otherwise a sufficiently large reply area is allocated and its address returned here. In this latter case, the memory must be relinquished using free() after it is no longer needed.\item[{\em reply}]The address of an area to receive the reply to the message, or NULL if no area is to be used.\item[{\em max\-Data}]The maximum number of data bytes that can be put into the supplied reply area.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Success. \item[{\em -1}]An error occurred.\end{description}
\end{Desc}
