ASN1C C/C++ Common Runtime  ASN1C v7.6.x
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members

#include <OSRTSocket.h>

Public Member Functions

EXTRTMETHOD OSRTSocket ()
 
EXTRTMETHOD OSRTSocket (OSRTSOCKET socket, OSBOOL ownership=FALSE, int retryCount=1)
 
EXTRTMETHOD OSRTSocket (const OSRTSocket &socket)
 
EXTRTMETHOD ~OSRTSocket ()
 
EXTRTMETHOD OSRTSocketaccept (OSIPADDR *destIP=0, int *port=0)
 
EXTRTMETHOD int bind (OSIPADDR addr, int port)
 
EXTRTMETHOD int bindUrl (const char *url)
 
EXTRTMETHOD int bind (const char *pAddrStr, int port)
 
int bind (int port)
 
EXTRTMETHOD int blockingRead (OSOCTET *pbuf, size_t readBytes)
 
EXTRTMETHOD int close ()
 
EXTRTMETHOD int connect (const char *host, int port)
 
EXTRTMETHOD int connectTimed (const char *host, int port, int nsecs)
 
EXTRTMETHOD int connectUrl (const char *url)
 
OSBOOL getOwnership ()
 
OSRTSOCKET getSocket () const
 
int getStatus ()
 
EXTRTMETHOD int listen (int maxConnections)
 
EXTRTMETHOD int recv (OSOCTET *pbuf, size_t bufsize)
 
EXTRTMETHOD int send (const OSOCTET *pdata, size_t size)
 
void setOwnership (OSBOOL ownership)
 
void setRetryCount (int value)
 

Static Public Member Functions

static EXTRTMETHOD const char * addrToString (OSIPADDR ipAddr, char *pAddrStr, size_t bufsize)
 
static EXTRTMETHOD OSIPADDR stringToAddr (const char *pAddrStr)
 

Protected Member Functions

OSBOOL isInitialized ()
 

Protected Attributes

OSRTSOCKET mSocket
 
int mInitStatus
 
int mStatus
 
int mRetryCount
 
OSBOOL mOwner
 

Detailed Description

Wrapper class for TCP/IP or UDP sockets.

Constructor & Destructor Documentation

◆ OSRTSocket() [1/3]

EXTRTMETHOD OSRTSocket::OSRTSocket ( )

This is the default constructor. It initializes all internal members with default values and creates a new socket structure. Use getStatus() method to determine has error occurred during the initialization or not.

◆ OSRTSocket() [2/3]

EXTRTMETHOD OSRTSocket::OSRTSocket ( OSRTSOCKET  socket,
OSBOOL  ownership = FALSE,
int  retryCount = 1 
)

This constructor initializes an instance by using an existing socket.

Parameters
socketAn existing socket handle.
ownershipBoolean flag that specifies who is the owner of the socket. If it is TRUE then the socket will be destroyed in the destructor. Otherwise, the user is responsible to close and destroy the socket.
retryCountNumber of times to retry a socket connect operation.

◆ OSRTSocket() [3/3]

EXTRTMETHOD OSRTSocket::OSRTSocket ( const OSRTSocket socket)

The copy constructor. The copied instance will have the same socket handle as the original one, but will not be the owner of the handle.

◆ ~OSRTSocket()

EXTRTMETHOD OSRTSocket::~OSRTSocket ( )

The destructor. This closes socket if the instance is the owner of the socket.

Member Function Documentation

◆ accept()

EXTRTMETHOD OSRTSocket* OSRTSocket::accept ( OSIPADDR destIP = 0,
int *  port = 0 
)

This method permits an incoming connection attempt on a socket. It extracts the first connection on the queue of pending connections on the socket. It then creates a new socket and returns an instance of the new socket. The newly created socket will handle the actual connection and has the same properties as the original socket.

Parameters
destIPOptional pointer to a buffer that receives the IP address of the connecting entity. It may be NULL.
portOptional pointer to a buffer that receives the port of the connecting entity. It may be NULL.
Returns
An instance of the new socket class. NULL, if error occur. Use OSRTSocket::getStatus method to obtain error code.
See also
rtxSocketAccept

◆ addrToString()

static EXTRTMETHOD const char* OSRTSocket::addrToString ( OSIPADDR  ipAddr,
char *  pAddrStr,
size_t  bufsize 
)
static

This method converts an IP address to its string representation.

Parameters
ipAddrThe IP address to be converted.
pAddrStrPointer to the buffer to receive a string with the IP address.
bufsizeSize of the buffer.
Returns
Pointer to a string with IP-address. NULL, if error occur.

◆ bind() [1/3]

EXTRTMETHOD int OSRTSocket::bind ( OSIPADDR  addr,
int  port 
)

This method associates a local address with a socket. It is used on an unconnected socket before subsequent calls to the OSRTSocket::connect or OSRTSocket::listen methods.

Parameters
addrThe local IP address to assign to the socket.
portThe local port number to assign to the socket.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketBind

◆ bind() [2/3]

EXTRTMETHOD int OSRTSocket::bind ( const char *  pAddrStr,
int  port 
)

This method associates a local address with a socket. It is used on an unconnected socket before subsequent calls to the OSRTSocket::connect or OSRTSocket::listen methods.

Parameters
pAddrStrNull-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
portThe local port number to assign to the socket.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketBind

◆ bind() [3/3]

int OSRTSocket::bind ( int  port)
inline

This method associates only a local port with a socket. It is used on an unconnected socket before subsequent calls to the OSRTSocket::connect or OSRTSocket::listen methods.

Parameters
portThe local port number to assign to the socket.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketBind
bind ()

◆ bindUrl()

EXTRTMETHOD int OSRTSocket::bindUrl ( const char *  url)

This method associates a local address with a socket. It is used on an unconnected socket before subsequent calls to the OSRTSocket::connect or OSRTSocket::listen methods. This version of the method allows a URL to be used instead of address and port number.

Parameters
urlUniveral resource locator (URL) string.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketBind

◆ blockingRead()

EXTRTMETHOD int OSRTSocket::blockingRead ( OSOCTET *  pbuf,
size_t  readBytes 
)

This method receives data from the connected socket. In this case, the connection is blocked until either the requested number of bytes is received or the socket is closed or an error occurs.

Parameters
pbufPointer to the buffer for the incoming data.
readBytesNumber of bytes to receive.
Returns
If no error occurs, returns the number of bytes received. Otherwise, the negative value is error code.

◆ close()

EXTRTMETHOD int OSRTSocket::close ( )

This method closes this socket.

Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketClose

◆ connect()

EXTRTMETHOD int OSRTSocket::connect ( const char *  host,
int  port 
)

This method establishes a connection to this socket. It is used to create a connection to the specified destination. When the socket call completes successfully, the socket is ready to send and receive data.

Parameters
hostNull-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
portThe destination port to connect.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketConnect

◆ connectTimed()

EXTRTMETHOD int OSRTSocket::connectTimed ( const char *  host,
int  port,
int  nsecs 
)

This method establishes a connection to this socket. It is similar to the socketConnect method except that it will only wait the given number of seconds to establish a connection before giving up.

Parameters
hostNull-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
portThe destination port to connect.
nsecsNumber of seconds to wait before failing.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ connectUrl()

EXTRTMETHOD int OSRTSocket::connectUrl ( const char *  url)

This method establishes a connection to this socket. It is used to create a connection to the specified destination. In this version, destination is specified using a URL.

Parameters
urlUniveral resource locator (URL) string.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketConnect

◆ getOwnership()

OSBOOL OSRTSocket::getOwnership ( )
inline

Returns the ownership of underlying O/S socket.

Returns
TRUE, if the socket object has the ownership of underlying O/S socket.

◆ getSocket()

OSRTSOCKET OSRTSocket::getSocket ( ) const
inline

This method returns the handle of the socket.

Returns
The handle of the socket.

◆ getStatus()

int OSRTSocket::getStatus ( )
inline

Returns a completion status of last operation.

Returns
Completion status of last operation:
  • 0 = success,
  • negative return value is error.

◆ listen()

EXTRTMETHOD int OSRTSocket::listen ( int  maxConnections)

This method places a socket into a state where it is listening for an incoming connection.

Parameters
maxConnectionsMaximum length of the queue of pending connections.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketListen

◆ recv()

EXTRTMETHOD int OSRTSocket::recv ( OSOCTET *  pbuf,
size_t  bufsize 
)

This method receives data from a connected socket. It is used to read incoming data on sockets. The socket must be connected before calling this function.

Parameters
pbufPointer to the buffer for the incoming data.
bufsizeLength of the buffer.
Returns
If no error occurs, returns the number of bytes received. Negative error code if error occurred.
See also
rtxSocketRecv

◆ send()

EXTRTMETHOD int OSRTSocket::send ( const OSOCTET *  pdata,
size_t  size 
)

This method sends data on a connected socket. It is used to write outgoing data on a connected socket.

Parameters
pdataBuffer containing the data to be transmitted.
sizeLength of the data in pdata.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also
rtxSocketSend

◆ setOwnership()

void OSRTSocket::setOwnership ( OSBOOL  ownership)
inline

Transfers an ownership of the underlying O/S socket to or from the socket object. If the socket object has the ownership of the underlying O/S socket it will close the O/S socket when the socket object is being closed or destroyed.

Parameters
ownershipTRUE, if socket object should have ownership of the underlying O/S socket; FALSE, otherwise.

◆ setRetryCount()

void OSRTSocket::setRetryCount ( int  value)
inline

This method sets the socket connect retry count. The connect operation will be retried this many times if the operation fails. By default, the connect operation is not retried.

Parameters
valueRetry count.

◆ stringToAddr()

static EXTRTMETHOD OSIPADDR OSRTSocket::stringToAddr ( const char *  pAddrStr)
static

This method converts a string containing an Internet Protocol dotted address into a proper OSIPADDR address.

Parameters
pAddrStrNull-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
Returns
If no error occurs, returns OSIPADDR. OSIPADDR_INVALID, if error occurred.

The documentation for this class was generated from the following file: