dnxTransport.c File Reference

Implements encapsulated communications transport functions. More...

#include "dnxTransport.h"
#include "dnxTSPI.h"
#include "dnxDebug.h"
#include "dnxError.h"
#include "dnxLogging.h"
#include "dnxProtocol.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <syslog.h>
#include <errno.h>
#include <assert.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "dnxTcp.h"
#include "dnxUdp.h"
#include "dnxMsgQ.h"

Go to the source code of this file.

Data Structures

struct  DnxChanMap_
 The channel map object structure. More...
struct  DnxTransport
 A low-level transport module. More...

Defines

#define elemcount(x)   (sizeof(x)/sizeof(*(x)))
#define DNX_MAX_CHAN_MAP   1000
 The maximum number of simultaneous open channels.

Typedefs

typedef struct DnxChanMap_ DnxChanMap
 The channel map object structure.

Functions

char * dnxNtop (const void *sastr, char *buf, size_t bufsz)
 Convert a sockaddr structure to a presentable string.
static int dnxChanMapUrlParse (DnxChanMap *chanMap, char *url)
 Set a channel map's transport object allocator in a based on URL scheme.
static int dnxChanMapFindSlot (DnxChanMap **chanMap)
 Locate a free channel map slot in the global channel map table.
static int dnxChanMapFindName (char *name, DnxChanMap **chanMap)
 Locate a channel map by name.
static int dnxChanMapAllocChannel (char *name, iDnxChannel **icpp)
 Allocate an unconnected channel.
int dnxChanMapAdd (char *name, char *url)
 Add a new channel to the global channel map.
void dnxChanMapDelete (char *name)
 Delete a channel map by name.
int dnxConnect (char *name, int mode, DnxChannel **channel)
 Connect a specified channel.
void dnxDisconnect (DnxChannel *channel)
 Disconnect and delete a specified channel.
int dnxGet (DnxChannel *channel, char *buf, int *size, int timeout, char *src)
 Read data from an open channel.
int dnxPut (DnxChannel *channel, char *buf, int size, int timeout, char *dst)
 Write data to an open channel.
void dnxGetStats (DnxChannel *channel, DnxTransStats *tsp)
 Retrieve stats from an open channel.
void dnxResetStats (DnxChannel *channel)
 Reset stats on an open channel.
int dnxChanMapInit (char *fileName)
 Initialize the channel map sub-system.
void dnxChanMapRelease (void)
 Clean up resources allocated by the channel map sub-system.

Variables

static DnxTransport gTMList []
static int dnxInit = 0
 The channel map initialization flag.
static pthread_mutex_t chanMutex
 The channel map mutex.
static DnxChanMap gChannelMap [DNX_MAX_CHAN_MAP]
 The global channel map.


Detailed Description

Implements encapsulated communications transport functions.

Author:
Robert W. Ingraham (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxTransport.c.


Define Documentation

#define DNX_MAX_CHAN_MAP   1000

The maximum number of simultaneous open channels.

Definition at line 51 of file dnxTransport.c.

Referenced by dnxChanMapFindName(), dnxChanMapFindSlot(), and dnxChanMapRelease().

#define elemcount (  )     (sizeof(x)/sizeof(*(x)))

Definition at line 48 of file dnxTransport.c.


Typedef Documentation

typedef struct DnxChanMap_ DnxChanMap

The channel map object structure.


Function Documentation

int dnxChanMapAdd ( char *  name,
char *  url 
)

Add a new channel to the global channel map.

Parameters:
[in] name - the name of the new channel to be added.
[in] url - the URL to associate with this new channel.
Returns:
Zero on success, or a non-zero error value.

Definition at line 251 of file dnxTransport.c.

References chanMutex, DNX_ERR_MEMORY, DNX_MAX_URL, DNX_OK, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxChanMapFindName(), dnxChanMapFindSlot(), dnxChanMapUrlParse(), DnxChanMap_::name, DnxChanMap_::url, xfree, and xstrdup.

Referenced by dnxCollectorCreate(), dnxDispatcherCreate(), dnxInitAgent(), initClientComm(), initWorkerComm(), and main().

static int dnxChanMapAllocChannel ( char *  name,
iDnxChannel **  icpp 
) [static]

Allocate an unconnected channel.

Parameters:
[in] name - the name of the channel to allocate.
[out] icpp - the address of storage for the returned object reference.
Returns:
Zero on success, or a non-zero error value.

Definition at line 223 of file dnxTransport.c.

References chanMutex, DNX_OK, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxChanMapFindName(), DnxChanMap_::txAlloc, and DnxChanMap_::url.

Referenced by dnxConnect().

void dnxChanMapDelete ( char *  name  ) 

static int dnxChanMapFindName ( char *  name,
DnxChanMap **  chanMap 
) [static]

Locate a channel map by name.

Parameters:
[in] name - the name of the channel map to locate and return.
[out] chanMap - the address of storage for returning the located channel map.
Returns:
Zero on success, or a non-zero error value.

Definition at line 197 of file dnxTransport.c.

References DNX_ERR_NOTFOUND, DNX_MAX_CHAN_MAP, and DNX_OK.

Referenced by dnxChanMapAdd(), dnxChanMapAllocChannel(), and dnxChanMapDelete().

static int dnxChanMapFindSlot ( DnxChanMap **  chanMap  )  [static]

Locate a free channel map slot in the global channel map table.

Parameters:
[out] chanMap - the address of storage in which to return the free channel map slot (address).
Returns:
Zero on success, or a non-zero error value.

Definition at line 172 of file dnxTransport.c.

References DNX_ERR_CAPACITY, DNX_MAX_CHAN_MAP, DNX_OK, and DnxChanMap_::name.

Referenced by dnxChanMapAdd().

int dnxChanMapInit ( char *  fileName  ) 

Initialize the channel map sub-system.

Parameters:
[in] fileName - a persistent storage file for the channel map. Not currently used.
Returns:
Zero on success, or a non-zero error value.

Todo:
Load global channel map from file, if specified.

Definition at line 457 of file dnxTransport.c.

References chanMutex, DNX_OK, DNX_PT_MUTEX_DESTROY, DNX_PT_MUTEX_INIT, dnxInit, elemcount, and DnxTransport::txExit.

Referenced by dnxServerInit(), initClientComm(), and main().

void dnxChanMapRelease ( void   ) 

Clean up resources allocated by the channel map sub-system.

Definition at line 490 of file dnxTransport.c.

References chanMutex, DNX_MAX_CHAN_MAP, DNX_PT_MUTEX_DESTROY, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, dnxInit, elemcount, DnxTransport::txExit, and xfree.

Referenced by dnxServerDeInit(), initClientComm(), main(), and releaseClientComm().

static int dnxChanMapUrlParse ( DnxChanMap chanMap,
char *  url 
) [static]

Set a channel map's transport object allocator in a based on URL scheme.

Parameters:
[in] chanMap - the channel map on which to set the allocator.
[in] url - the URL to be parsed.
Returns:
Zero on success, or a non-zero error value.

Definition at line 141 of file dnxTransport.c.

References DNX_ERR_BADURL, DNX_MAX_URL, DNX_OK, elemcount, DnxTransport::txAlloc, and DnxChanMap_::txAlloc.

Referenced by dnxChanMapAdd().

int dnxConnect ( char *  name,
int  mode,
DnxChannel **  channel 
)

Connect a specified channel.

The mode parameter specifies either active (DNX_MODE_ACTIVE) or passive (DNX_MODE_PASSIVE) for the connection mode. An active connection is basically a client connection, or a connection on which we send data to a server. A passive connection is a server connection, or a connection on which we listen for incoming messages.

Parameters:
[in] name - the name of the channel to open.
[in] mode - boolean; true (1) means this will be an active (client- side) connection to a server; false (0) means this will be a passive (server-side) listen point.
[out] channel - the address of storage for the returned connected channel.
Returns:
Zero on success, or a non-zero error value.

Definition at line 336 of file dnxTransport.c.

References DNX_OK, dnxChanMapAllocChannel(), iDnxChannel_::txDelete, and iDnxChannel_::txOpen.

Referenced by dnxCollectorCreate(), dnxDispatcherCreate(), dnxInitAgent(), initClientComm(), initWorkerComm(), and main().

void dnxDisconnect ( DnxChannel channel  ) 

Disconnect and delete a specified channel.

Parameters:
[in] channel - the channel to be disconnected (and deleted).

Definition at line 361 of file dnxTransport.c.

References DNX_OK, iDnxChannel_::txClose, and iDnxChannel_::txDelete.

Referenced by dnxCollectorCreate(), dnxCollectorDestroy(), dnxDispatcherCreate(), dnxDispatcherDestroy(), dnxInitAgent(), dnxReleaseAgent(), initWorkerComm(), main(), releaseClientComm(), and releaseWorkerComm().

int dnxGet ( DnxChannel channel,
char *  buf,
int *  size,
int  timeout,
char *  src 
)

Read data from an open channel.

Parameters:
[in] channel - the channel from which to read.
[out] buf - the address of storage for data read from channel.
[in,out] size - on entry, the maximum number of bytes that may be read into buf; on exit, returns the number of bytes actually read.
[in] timeout - the maximum number of seconds the caller is willing to wait for data on channel before returning a timeout error.
[out] src - the address of storage for the remote sender's address. This parameter is optional, and may be passed as NULL. The caller must ensure that the buffer pointed to is large enough to hold the returned address. Passing the address of a struct sockaddr_storage is more than adequate for any address type available.
Returns:
Zero on success, or a non-zero error value.

Definition at line 389 of file dnxTransport.c.

References iDnxChannel_::txRead.

Referenced by dnxWaitForJob(), dnxWaitForMgmtReply(), dnxWaitForMgmtRequest(), dnxWaitForNodeRequest(), and dnxWaitForResult().

void dnxGetStats ( DnxChannel channel,
DnxTransStats tsp 
)

Retrieve stats from an open channel.

Parameters:
[in] channel - the channel from which stats are to be retrieved.
[out] tsp - a buffer into which stats are to be copied.

Definition at line 426 of file dnxTransport.c.

References iDnxChannel_::txGetStats.

char* dnxNtop ( const void *  sastr,
char *  buf,
size_t  bufsz 
)

Convert a sockaddr structure to a presentable string.

Parameters:
[in] sastr - an optional sockaddr structure to be converted.
[out] buf - the destination buffer, which must be at least DNX_MAX_ADDRSTR bytes in length to hold the longest string.
[in] bufsz - the size in bytes of buf.
Returns:
a pointer to buf.

Definition at line 106 of file dnxTransport.c.

Referenced by dnxAgentServer(), dnxCreateNodeAt(), dnxSendMgmtReply(), dnxTimer(), dnxWaitForMgmtRequest(), dnxWaitForNodeRequest(), and processCommands().

int dnxPut ( DnxChannel channel,
char *  buf,
int  size,
int  timeout,
char *  dst 
)

Write data to an open channel.

Parameters:
[in] channel - the channel to which data should be written.
[in] buf - the data to be written to channel.
[in] size - the number of bytes in buf to be written.
[in] timeout - the maximum number of seconds the caller is willing to wait for the write operation to complete on channel before returning a timeout error.
[in] dst - the address to which data should be sent. This parameter is optional and may be passed as NULL. If NULL, the channel configured address will be used.
Returns:
Zero on success, or a non-zero error value.

Definition at line 412 of file dnxTransport.c.

References DNX_MAX_MSG, and iDnxChannel_::txWrite.

Referenced by dnxSendJob(), dnxSendMgmtReply(), dnxSendMgmtRequest(), dnxSendNodeRequest(), and dnxSendResult().

void dnxResetStats ( DnxChannel channel  ) 

Reset stats on an open channel.

Parameters:
[in] channel - the channel on which stats are to be reset.

Definition at line 440 of file dnxTransport.c.

References iDnxChannel_::txResetStats.


Variable Documentation

pthread_mutex_t chanMutex [static]

The channel map mutex.

Definition at line 90 of file dnxTransport.c.

Referenced by dnxChanMapAdd(), dnxChanMapAllocChannel(), dnxChanMapDelete(), dnxChanMapInit(), and dnxChanMapRelease().

int dnxInit = 0 [static]

The channel map initialization flag.

Definition at line 89 of file dnxTransport.c.

Referenced by dnxChanMapInit(), and dnxChanMapRelease().

DnxChanMap gChannelMap[DNX_MAX_CHAN_MAP] [static]

The global channel map.

Definition at line 91 of file dnxTransport.c.

DnxTransport gTMList[] [static]

Initial value:

{
   { "tcp",  0, 0, dnxTcpInit,  dnxTcpDeInit  },
   { "udp",  0, 0, dnxUdpInit,  dnxUdpDeInit  },
   { "msgq", 0, 0, dnxMsgQInit, dnxMsgQDeInit },
}

Definition at line 80 of file dnxTransport.c.


Generated on Tue Apr 13 15:48:08 2010 for DNX by  doxygen 1.5.6