dnxTcp.c File Reference

Implements the DNX TCP Transport Layer. More...

#include "dnxTcp.h"
#include "dnxTSPI.h"
#include "dnxTransport.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <pthread.h>
#include <limits.h>

Go to the source code of this file.

Data Structures

struct  iDnxTcpChannel_
 The implementation of the TCP low-level I/O transport. More...

Defines

#define HOST_NAME_MAX   256
#define DNX_TCP_LISTEN   5
 Number of listen buffers per TCP listen point.

Typedefs

typedef struct iDnxTcpChannel_ iDnxTcpChannel
 The implementation of the TCP low-level I/O transport.

Functions

static int dnxTcpOpen (iDnxChannel *icp, int mode)
 Open a TCP channel object.
static int dnxTcpClose (iDnxChannel *icp)
 Close a TCP channel object.
static int dnxTcpRead (iDnxChannel *icp, char *buf, int *size, int timeout, char *src)
 Read data from a TCP channel object.
static int dnxTcpWrite (iDnxChannel *icp, char *buf, int size, int timeout, char *dst)
 Write data to a TCP channel object.
static void dnxTcpDelete (iDnxChannel *icp)
 Delete a TCP channel object.
static int dnxTcpNew (char *url, iDnxChannel **icpp)
 Create a new TCP transport.
int dnxTcpInit (int(**ptxAlloc)(char *url, iDnxChannel **icpp))
 Initialize the TCP transport sub-system; return TCP channel contructor.
void dnxTcpDeInit (void)
 Clean up global resources allocated by the TCP channel sub-system.

Variables

static pthread_mutex_t tcpMutex


Detailed Description

Implements the DNX TCP Transport Layer.

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

Definition in file dnxTcp.c.


Define Documentation

#define DNX_TCP_LISTEN   5

Number of listen buffers per TCP listen point.

Definition at line 57 of file dnxTcp.c.

Referenced by dnxTcpOpen().

#define HOST_NAME_MAX   256

Definition at line 53 of file dnxTcp.c.

Referenced by dnxTcpNew(), and dnxUdpNew().


Typedef Documentation

The implementation of the TCP low-level I/O transport.


Function Documentation

static int dnxTcpClose ( iDnxChannel icp  )  [static]

Close a TCP channel object.

Parameters:
[in] icp - the TCP channel object to be closed.
Returns:
Always returns zero.

Definition at line 161 of file dnxTcp.c.

References DNX_OK, and iDnxTcpChannel_::socket.

Referenced by dnxTcpNew().

void dnxTcpDeInit ( void   ) 

Clean up global resources allocated by the TCP channel sub-system.

Definition at line 432 of file dnxTcp.c.

References DNX_PT_MUTEX_DESTROY, and tcpMutex.

static void dnxTcpDelete ( iDnxChannel icp  )  [static]

Delete a TCP channel object.

Parameters:
[in] icp - the TCP channel object to be deleted.

Definition at line 338 of file dnxTcp.c.

References iDnxTcpChannel_::host, iDnxTcpChannel_::socket, and xfree.

Referenced by dnxTcpNew().

int dnxTcpInit ( int(**)(char *url, iDnxChannel **icpp)  ptxAlloc  ) 

Initialize the TCP transport sub-system; return TCP channel contructor.

Parameters:
[out] ptxAlloc - the address of storage in which to return the address of the TCP channel object constructor (dnxTcpNew).
Returns:
Always returns zero.

Definition at line 419 of file dnxTcp.c.

References DNX_OK, DNX_PT_MUTEX_INIT, dnxTcpNew(), and tcpMutex.

static int dnxTcpNew ( char *  url,
iDnxChannel **  icpp 
) [static]

Create a new TCP transport.

Parameters:
[in] url - the URL containing the host name and port number.
[out] icpp - the address of storage for returning the new low- level TCP transport object (as a generic transport object).
Returns:
Zero on success, or a non-zero error value.

Definition at line 359 of file dnxTcp.c.

References DNX_ERR_BADURL, DNX_ERR_MEMORY, DNX_OK, dnxTcpClose(), dnxTcpDelete(), dnxTcpOpen(), dnxTcpRead(), dnxTcpWrite(), iDnxTcpChannel_::host, HOST_NAME_MAX, iDnxTcpChannel_::ichan, iDnxTcpChannel_::port, iDnxChannel_::txClose, iDnxChannel_::txDelete, iDnxChannel_::txOpen, iDnxChannel_::txRead, iDnxChannel_::txWrite, xfree, and xmalloc.

Referenced by dnxTcpInit().

static int dnxTcpOpen ( iDnxChannel icp,
int  mode 
) [static]

Open a TCP channel object.

Parameters:
[in] icp - the TCP channel object to be opened.
[in] mode - DNX_MODE_ACTIVE indicates the transport will be used in active mode (as a client); DNX_MODE_PASSIVE indicates the transport will be used in passive mode (as a server listen point).
Returns:
Zero on success, or a non-zero error value.

Definition at line 85 of file dnxTcp.c.

References DNX_ERR_ADDRESS, DNX_ERR_OPEN, DNX_MODE_ACTIVE, DNX_OK, DNX_PT_MUTEX_LOCK, DNX_PT_MUTEX_UNLOCK, DNX_TCP_LISTEN, dnxLog(), iDnxTcpChannel_::host, iDnxTcpChannel_::port, iDnxTcpChannel_::socket, and tcpMutex.

Referenced by dnxTcpNew().

static int dnxTcpRead ( iDnxChannel icp,
char *  buf,
int *  size,
int  timeout,
char *  src 
) [static]

Read data from a TCP channel object.

Parameters:
[in] icp - the TCP channel object from which to read data.
[out] buf - the address of storage into which data should be read.
[in,out] size - on entry, the maximum number of bytes that may be read into buf; on exit, returns the number of bytes stored in buf.
[in] timeout - the maximum number of seconds we're willing to wait for data to become available on icp without returning a timeout error.
[out] src - the address of storage for the sender's address if desired. This parameter is optional, and may be passed as NULL. If non-NULL, the buffer pointed to by src must be at least the size of a sockaddr_in structure.
Returns:
Zero on success, or a non-zero error value.

Definition at line 193 of file dnxTcp.c.

References DNX_ERR_RECEIVE, DNX_ERR_TIMEOUT, DNX_MAX_MSG, DNX_OK, dnxLog(), and iDnxTcpChannel_::socket.

Referenced by dnxTcpNew().

static int dnxTcpWrite ( iDnxChannel icp,
char *  buf,
int  size,
int  timeout,
char *  dst 
) [static]

Write data to a TCP channel object.

Parameters:
[in] icp - the TCP channel object on which to write data.
[in] buf - a pointer to the data to be written.
[in] size - the number of bytes to be written on icp.
[in] timeout - the maximum number of seconds to wait for the write operation to complete without returning a timeout error.
[in] dst - the address to which the data in buf should be sent using this channel. This parameter is ignored for virtual connection based channels. This parameter is optional and may be passed as NULL.
Returns:
Zero on success, or a non-zero error value.
Note:
If this is a stream oriented channel, or if NULL is passed for the dst parameter, the channel destination address is not used.

Definition at line 281 of file dnxTcp.c.

References DNX_ERR_SEND, DNX_ERR_TIMEOUT, DNX_OK, dnxLog(), and iDnxTcpChannel_::socket.

Referenced by dnxTcpNew().


Variable Documentation

pthread_mutex_t tcpMutex [static]

Todo:
Use GNU reentrant resolver interface on platforms where available.

Definition at line 70 of file dnxTcp.c.

Referenced by dnxTcpDeInit(), dnxTcpInit(), and dnxTcpOpen().


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