ASN1C C/C++ Common Runtime
ASN1C v7.5.x
|
#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 OSRTSocket * | accept (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 |
Wrapper class for TCP/IP or UDP sockets.
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.
EXTRTMETHOD OSRTSocket::OSRTSocket | ( | OSRTSOCKET | socket, |
OSBOOL | ownership = FALSE , |
||
int | retryCount = 1 |
||
) |
This constructor initializes an instance by using an existing socket.
socket | An existing socket handle. |
ownership | Boolean 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. |
retryCount | Number of times to retry a socket connect operation. |
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.
EXTRTMETHOD OSRTSocket::~OSRTSocket | ( | ) |
The destructor. This closes socket if the instance is the owner of the socket.
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.
destIP | Optional pointer to a buffer that receives the IP address of the connecting entity. It may be NULL. |
port | Optional pointer to a buffer that receives the port of the connecting entity. It may be NULL. |
|
static |
This method converts an IP address to its string representation.
ipAddr | The IP address to be converted. |
pAddrStr | Pointer to the buffer to receive a string with the IP address. |
bufsize | Size of the buffer. |
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.
addr | The local IP address to assign to the socket. |
port | The local port number to assign to the socket. |
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.
pAddrStr | Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation. |
port | The local port number to assign to the socket. |
|
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.
port | The local port number to assign to the socket. |
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.
url | Univeral resource locator (URL) string. |
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.
pbuf | Pointer to the buffer for the incoming data. |
readBytes | Number of bytes to receive. |
EXTRTMETHOD int OSRTSocket::close | ( | ) |
This method closes this socket.
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.
host | Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation. |
port | The destination port to connect. |
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.
host | Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation. |
port | The destination port to connect. |
nsecs | Number of seconds to wait before failing. |
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.
url | Univeral resource locator (URL) string. |
|
inline |
Returns the ownership of underlying O/S socket.
|
inline |
This method returns the handle of the socket.
|
inline |
Returns a completion status of last operation.
EXTRTMETHOD int OSRTSocket::listen | ( | int | maxConnections | ) |
This method places a socket into a state where it is listening for an incoming connection.
maxConnections | Maximum length of the queue of pending connections. |
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.
pbuf | Pointer to the buffer for the incoming data. |
bufsize | Length of the buffer. |
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.
pdata | Buffer containing the data to be transmitted. |
size | Length of the data in pdata. |
|
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.
ownership | TRUE, if socket object should have ownership of the underlying O/S socket; FALSE, otherwise. |
|
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.
value | Retry count. |
|
static |
This method converts a string containing an Internet Protocol dotted address into a proper OSIPADDR address.
pAddrStr | Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation. |