GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> NMSG / V4-0-3 > nmsg / rhel4-32
#include <NMSG/nmsgLib.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
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. | |
| int nmsgCheck | ( | void * | hndl | ) |
Check a network connection handle.
This routine checks whether a network handle is valid or not.
| hndl | The handle for the connection. |
| 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.
| 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. |
| 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.
| 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. |
| 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.
| 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. |
| 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 | ) |
Obtain the text of an error message.
This routine returns a pointer to the message corresponding to a given NMSG status code.
| status | The NMSG status code. |
References NMSG_ADDRUNAV, NMSG_ADDRUSED, NMSG_ALREADY, NMSG_BADADDRS, NMSG_BADFNMBR, NMSG_BRKNPIPE, NMSG_CONNABRT, NMSG_CONNREF, NMSG_CONNRSET, NMSG_CONNTMO, NMSG_DISCONN, NMSG_FILENFND, NMSG_HOSTDOWN, NMSG_HSTUNRCH, NMSG_INPROGRS, NMSG_INVDARG, NMSG_INVHNDL, NMSG_INVSEMA, NMSG_IOERROR, NMSG_MSGLONG, NMSG_NAMELONG, NMSG_NETDOWN, NMSG_NETRESET, NMSG_NETUNRCH, NMSG_NOACCESS, NMSG_NOBUFSPC, NMSG_NOMEMORY, NMSG_NOSCHDEV, NMSG_NOSEMCRE, NMSG_NOSTREAM, NMSG_NOTADIR, NMSG_NOTAFILE, NMSG_NOTASKCR, NMSG_NOTASOCK, NMSG_NOTCONN, NMSG_OPNTPERM, NMSG_OPNTSUPP, NMSG_OPRNINTR, NMSG_PROTOERR, NMSG_PROTOTYP, NMSG_RDONLYFS, NMSG_SHUTDOWN, NMSG_SNOTCONN, NMSG_SOCKCONN, NMSG_SUCCESS, NMSG_TIMEDOUT, NMSG_TOODEEP, NMSG_TRYAGAIN, NMSG_UNKNERR, NMSG_UNKNHOST, NMSG_UNSUPADF, NMSG_UNSUPPRF, NMSG_UNSUPPRO, NMSG_XSFILDVC, and NMSG_XSFILOPN.
Referenced by nmsgErrorReport().
| 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.
| 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).
| 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. |
| 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.
| hndl | The handle for the connection. | |
| ip | The addressof an integer to receive the IP address. |
| 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.
| hndl | The handle for the connection. | |
| msg | The address of message to be sent. It must be formatted using the nmsgBuff_t structure type. |
| 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.
| 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. |
| 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.
| hndl | The handle for the connection. | |
| stats | The address of an area to receive the statistics block. |
| 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.
| 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. |
| 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.
1.5.8