GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> NMSG / dev > nmsg / sun-gcc


Interface   Data Structures   File List   Data Fields   Globals  

nmsgLib.h File Reference

Definitions for the network message routines. More...


Classes

struct  nmsgHead_s
 Network message header. More...
struct  nmsgBuff_s
 Prototype message buffer. More...
struct  nmsgStats_s
 Network statistics block. More...

Typedefs

typedef struct nmsgHead_s nmsgHead_t
 Network message header.
typedef struct nmsgBuff_s nmsgBuff_t
 Prototype message buffer.
typedef struct nmsgStats_s nmsgStats_t
 Network statistics block.
typedef int nmsgConnCB_t (void *hndl, void **uParm)
 Connect callback routine.
typedef int nmsgDiscCB_t (void *hndl, void **uParm)
 Disconnect callback routine.
typedef int nmsgRcveCB_t (void *hndl, void **uParm, nmsgBuff_t *msg, char **dataP)
 Receive message callback routine.

Enumerations

enum  { NMSG_MAGIC = 0x6e4d7347 }
 Magic word value definition. More...
enum  {
  NMSG_SUCCESS = 0,
  NMSG_NOMEMORY = 1,
  NMSG_UNKNHOST = 2,
  NMSG_NOSEMCRE = 3,
  NMSG_NOTASKCR = 4,
  NMSG_NOTCONN = 5,
  NMSG_INVSEMA = 6,
  NMSG_DISCONN = 7,
  NMSG_TIMEDOUT = 8,
  NMSG_INVFDESC = 9,
  NMSG_INVHNDL = 10,
  NMSG_OPNTPERM = 11,
  NMSG_FILENFND = 12,
  NMSG_IOERROR = 13,
  NMSG_NOACCESS = 14,
  NMSG_NOSCHDEV = 15,
  NMSG_NOTADIR = 16,
  NMSG_NOTAFILE = 17,
  NMSG_XSFILDVC = 18,
  NMSG_XSFILOPN = 19,
  NMSG_NAMELONG = 20,
  NMSG_RDONLYFS = 21,
  NMSG_NETUNRCH = 22,
  NMSG_NETRESET = 23,
  NMSG_CONNABRT = 24,
  NMSG_CONNRSET = 25,
  NMSG_NOBUFSPC = 26,
  NMSG_SOCKCONN = 27,
  NMSG_SNOTCONN = 28,
  NMSG_SHUTDOWN = 29,
  NMSG_CONNTMO = 30,
  NMSG_CONNREF = 31,
  NMSG_NETDOWN = 32,
  NMSG_TOODEEP = 33,
  NMSG_HSTUNRCH = 34,
  NMSG_HOSTDOWN = 35,
  NMSG_UNSUPPRO = 36,
  NMSG_UNSUPPRF = 37,
  NMSG_PROTOTYP = 38,
  NMSG_UNSUPADF = 39,
  NMSG_NOSTREAM = 40,
  NMSG_ADDRUSED = 41,
  NMSG_ADDRUNAV = 42,
  NMSG_ALREADY = 43,
  NMSG_BADFNMBR = 44,
  NMSG_INPROGRS = 45,
  NMSG_OPRNINTR = 46,
  NMSG_INVDARG = 47,
  NMSG_NOTASOCK = 48,
  NMSG_OPNTSUPP = 49,
  NMSG_BADADDRS = 50,
  NMSG_PROTOERR = 51,
  NMSG_TRYAGAIN = 52,
  NMSG_MSGLONG = 53,
  NMSG_BRKNPIPE = 54,
  NMSG_UNKNERR = 55
}
 Function return codes. More...

Functions

int nmsgCheck (void *hndl)
 Check a network connection handle.
int nmsgClose (void *hndl, int force)
 Terminate a message client or server.
int nmsgConnect (void **hndl, const char *node, int port)
 Connect to a message server.
int nmsgConnectAsy (void **hndl, const char *node, int port, int prio, nmsgConnCB_t connRtn, nmsgDiscCB_t discRtn, void *uParm)
 Connect asynchronously (robustly) to a message server.
const char * nmsgErrorMsg (int status)
 Obtain the text of an error message.
void nmsgErrorReport (int status, const char *func)
 Display an error message.
int nmsgListen (void **hndl, int port, int maxConn, int maxData, int prio, nmsgConnCB_t connRtn, nmsgDiscCB_t discRtn, nmsgRcveCB_t rcveRtn, void *uParm)
 Establish a message server.
int nmsgRemoteIP (void *hndl, int *ip)
 Get the IP address of the remote end.
int nmsgSend (void *hndl, nmsgBuff_t *msg)
 Send a message and return immediately.
int nmsgSendW (void *hndl, nmsgBuff_t *msg, nmsgBuff_t **replyP, nmsgBuff_t *reply, int maxData)
 Send a message and receive reply.
int nmsgStats (void *hndl, nmsgStats_t *stats)
 Get connection statistics.
int nmsgWait (void *hndl, nmsgBuff_t **replyP, nmsgBuff_t *reply, int maxData)
 Wait for a reply to a sent message.


Detailed Description

Definitions for the network message routines.

Author:
Owen H Saxton
Id
nmsgLib.h,v 1.11 2011/03/28 18:39:27 saxton Exp

Typedef Documentation

typedef int nmsgConnCB_t(void *hndl, void **uParm)

Connect callback routine.

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

Parameters:
hndl The handle for the network connection.
uParm The address of a per-connection copy of the user parameter supplied in the call to the listen or connection routine.
Return values:
0 Accept the connection.
-1 Reject the connection (for listen callback only).

typedef int nmsgDiscCB_t(void *hndl, void **uParm)

Disconnect callback routine.

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

Parameters:
hndl The handle for the network connection.
uParm The address of a per-connection copy of the user parameter supplied in the call to the listen or connection routine.
Returns:
The return value is ignored.

typedef int nmsgRcveCB_t(void *hndl, void **uParm, nmsgBuff_t *msg, char **dataP)

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.

Parameters:
hndl The handle for the network connection.
uParm The address of a per-connection copy of the user parameter supplied in the call to the listen routine.
msg The address of the received message.
dataP 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().
Returns:
The return value is ignored.


Enumeration Type Documentation

anonymous enum

Magic word value definition.

Enumerator:
NMSG_MAGIC  "nMsG"

anonymous enum

Function return codes.

Enumerator:
NMSG_SUCCESS  Success.
NMSG_NOMEMORY  Insufficient memory available.
NMSG_UNKNHOST  Unknown host name.
NMSG_NOSEMCRE  Cannot create semaphore.
NMSG_NOTASKCR  Cannot create task.
NMSG_NOTCONN  Not connected to server.
NMSG_INVSEMA  Invalid semaphore.
NMSG_DISCONN  Server connection was broken.
NMSG_TIMEDOUT  Timed out during connection.
NMSG_INVFDESC  Invalid file descriptor.
NMSG_INVHNDL  Invalid handle supplied.
NMSG_OPNTPERM  Operation not permitted.
NMSG_FILENFND  File not found.
NMSG_IOERROR  I/O error.
NMSG_NOACCESS  Access not permitted.
NMSG_NOSCHDEV  No such device.
NMSG_NOTADIR  Not a directory.
NMSG_NOTAFILE  Not a file.
NMSG_XSFILDVC  Too many files.
NMSG_XSFILOPN  Too many open files.
NMSG_NAMELONG  Name too long.
NMSG_RDONLYFS  Read-only file system.
NMSG_NETUNRCH  Network unreachable.
NMSG_NETRESET  Network has been reset.
NMSG_CONNABRT  Connection aborted.
NMSG_CONNRSET  Connection reset.
NMSG_NOBUFSPC  No buffer space available.
NMSG_SOCKCONN  Socket already connected.
NMSG_SNOTCONN  Socket not connected.
NMSG_SHUTDOWN  Socket shut down.
NMSG_CONNTMO  Connection timed out.
NMSG_CONNREF  Connection refused.
NMSG_NETDOWN  Network down.
NMSG_TOODEEP  Symbolic link level too deep.
NMSG_HSTUNRCH  Host unreachable.
NMSG_HOSTDOWN  Host down.
NMSG_UNSUPPRO  Unsupported protocol.
NMSG_UNSUPPRF  Unsupported protocol family.
NMSG_PROTOTYP  Wrong protocol type.
NMSG_UNSUPADF  Unsupported address family.
NMSG_NOSTREAM  No stream resources.
NMSG_ADDRUSED  Address in use.
NMSG_ADDRUNAV  Address unavailable.
NMSG_ALREADY  Operation already in progress.
NMSG_BADFNMBR  Invalid file number.
NMSG_INPROGRS  Operation in progress.
NMSG_OPRNINTR  Operation interrupted by signal.
NMSG_INVDARG  Invalid argument.
NMSG_NOTASOCK  Not a socket.
NMSG_OPNTSUPP  Operation not supported.
NMSG_BADADDRS  Invalid parameter address.
NMSG_PROTOERR  Protocol error.
NMSG_TRYAGAIN  Retry operation.
NMSG_MSGLONG  Message too long.
NMSG_BRKNPIPE  Broken pipe.
NMSG_UNKNERR  Unknown system error.


Function Documentation

int nmsgCheck ( void *  hndl  ) 

Check a network connection handle.

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

Parameters:
hndl The handle for the connection.
Return values:
1 The handle is valid.
0 The handle is invalid.

References NMSG_MAGIC.

int nmsgClose ( void *  hndl,
int  force 
)

Terminate a message client or server.

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

Parameters:
hndl The handle of the connection or server.
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.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.

References NMSG_INVHNDL, NMSG_MAGIC, and NMSG_SUCCESS.

int nmsgConnect ( void **  hndl,
const char *  node,
int  port 
)

Connect to a message server.

This routine establishes a network connection to a message server.

Parameters:
hndl The address of a pointer to receive the identifying handle for the network connection.
node The address of the name of the node containing the message server.
port The port number on which to establish the connection.
Return values:
NMSG_SUCCESS The connection was established successfully.
NMSG_NOMEMORY Insuffucuent memory available.
NMSG_UNKNHOST Host is unknown.
NMSG_NOSEMCRE Unable to create sync. semaphore (VxWorks)
NMSG_xxx Various connection errors.

References NMSG_MAGIC, NMSG_NOMEMORY, NMSG_NOSEMCRE, NMSG_SUCCESS, and NMSG_UNKNHOST.

int nmsgConnectAsy ( void **  hndl,
const char *  node,
int  port,
int  prio,
nmsgConnCB_t  connRtn,
nmsgDiscCB_t  discRtn,
void *  uParm 
)

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.

Parameters:
hndl The address of a pointer to receive the identifying handle for the network connection.
node The address of the name of the node containing the message server.
port The port number on which to establish the connection.
prio The priority of the connection task, where applicable. If 0, the default value (100) is used.
connRtn The address of a routine to be called when the connection has been made.
discRtn The address of a routine to be called when the connection is broken.
uParm A parameter to be passed to the connect and disconnect callback routines.
Return values:
NMSG_SUCCESS The connection was established successfully.
NMSG_NOMEMORY Insuffucuent memory available.
NMSG_UNKNHOST Host is unknown.
NMSG_NOSEMCRE Unable to create sync. semaphore (VxWorks)
NMSG_NOTASKCR Unable to spawn connection task.

References NMSG_MAGIC, NMSG_NOMEMORY, NMSG_NOSEMCRE, NMSG_SUCCESS, and NMSG_UNKNHOST.

const char* nmsgErrorMsg ( int  status  ) 

void nmsgErrorReport ( int  status,
const char *  func 
)

Display an error message.

This routine outputs to stderr the message corresponding to a given NMSG status code.

Parameters:
status The NMSG status code.
func The function name to be displayed at the start of the message.

References nmsgErrorMsg().

int nmsgListen ( void **  hndl,
int  port,
int  maxConn,
int  maxData,
int  prio,
nmsgConnCB_t  connRtn,
nmsgDiscCB_t  discRtn,
nmsgRcveCB_t  rcveRtn,
void *  uParm 
)

Establish a message server.

This routine establishes a network message server (listener).

Parameters:
hndl The address of a pointer to receive the identifying handle for the network listener.
port The port number on which to establish the server.
maxConn The maximum number of concurrent connections that the server will allow.
maxData The maximum number of data bytes that can be transferred in a single message.
prio The priority of the listener (server) and receiver tasks, where applicable. If 0, the default value (100) is used.
connRtn 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.
discRtn The address of a routine to be called when a connection is broken.
rcveRtn The address of a routine to be called whenever a message is received.
uParm A parameter to be passed to the connect, disconnect and receive callback routines.
Return values:
NMSG_SUCCESS The connection was established successfully.
NMSG_NOMEMORY Insuffucuent memory available.
NMSG_NOTASKCR Unable to spawn listener task.
NMSG_xxx Various system errors.

References NMSG_MAGIC, NMSG_NOMEMORY, and NMSG_SUCCESS.

int nmsgRemoteIP ( void *  hndl,
int *  ip 
)

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.

Parameters:
hndl The handle for the connection.
ip The addressof an integer to receive the IP address.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.

References NMSG_INVHNDL, NMSG_MAGIC, and NMSG_SUCCESS.

int nmsgSend ( void *  hndl,
nmsgBuff_t msg 
)

Send a message and return immediately.

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

Parameters:
hndl The handle for the connection.
msg The address of message to be sent. It must be formatted using the nmsgBuff_t structure type.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.
NMSG_NOTCONN Not connected to server.
NMSG_INVSEMA Invalid semaphore.
NMSG_DISCONN Server connection was broken.

References nmsgHead_s::func, nmsgBuff_s::head, nmsgHead_s::leng, nmsgHead_s::magic, NMSG_INVHNDL, NMSG_INVSEMA, NMSG_MAGIC, NMSG_NOTCONN, NMSG_SUCCESS, nmsgHead_s::parm, and nmsgHead_s::stat.

int nmsgSendW ( void *  hndl,
nmsgBuff_t msg,
nmsgBuff_t **  replyP,
nmsgBuff_t reply,
int  maxData 
)

Send a message and receive reply.

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

Parameters:
hndl The handle for the connection.
msg The address of message to be sent. It must be formatted using the nmsgBuff_t structure type.
replyP 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.
reply The address of an area to receive the reply to the message, or NULL if no area is to be used.
maxData The maximum number of data bytes that can be put into the supplied reply area.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.
NMSG_NOTCONN Not connected to server.
NMSG_INVSEMA Invalid semaphore.
NMSG_DISCONN Server connection was broken.

References nmsgHead_s::func, nmsgBuff_s::head, nmsgHead_s::leng, nmsgHead_s::magic, NMSG_DISCONN, NMSG_INVHNDL, NMSG_INVSEMA, NMSG_MAGIC, NMSG_NOTCONN, NMSG_SUCCESS, nmsgHead_s::parm, and nmsgHead_s::stat.

int nmsgStats ( void *  hndl,
nmsgStats_t stats 
)

Get connection statistics.

This routine returns a block of connection statistics containing the number of connects, disconnects, messages sent/received, bytes sent and bytes received.

Parameters:
hndl The handle for the connection.
stats The address of an area to receive the statistics block.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.

References nmsgStats_s::nByteR, nmsgStats_s::nByteS, nmsgStats_s::nConn, nmsgStats_s::nDisc, nmsgStats_s::nMsg, NMSG_INVHNDL, NMSG_MAGIC, and NMSG_SUCCESS.

int nmsgWait ( void *  hndl,
nmsgBuff_t **  replyP,
nmsgBuff_t reply,
int  maxData 
)

Wait for a reply to a sent message.

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

Parameters:
hndl The handle for the connection.
replyP 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.
reply The address of an area to receive the reply to the message, or NULL if no area is to be used.
maxData The maximum number of data bytes that can be put into the supplied reply area.
Return values:
NMSG_SUCCESS Success.
NMSG_INVHNDL Invalid network handle.
NMSG_NOTCONN Not connected to server.
NMSG_INVSEMA Invalid semaphore.
NMSG_DISCONN Server connection was broken.

References NMSG_DISCONN, NMSG_INVHNDL, NMSG_INVSEMA, NMSG_MAGIC, NMSG_NOTCONN, and NMSG_SUCCESS.


Generated on Mon Mar 28 11:43:08 2011 by  doxygen 1.5.8