XBinder  Version 2.6.x
Typedefs | Functions
TCP/IP or UDP socket utility functions

Typedefs

typedef unsigned long OSIPADDR
 The IP address represented as unsigned long value. More...
 

Functions

EXTERNRT int rtxSocketAccept (OSRTSOCKET socket, OSRTSOCKET *pNewSocket, OSIPADDR *destAddr, int *destPort)
 This function permits an incoming connection attempt on a socket. More...
 
EXTERNRT int rtxSocketAddrToStr (OSIPADDR ipAddr, char *pbuf, size_t bufsize)
 This function converts an IP address to its string representation. More...
 
EXTERNRT int rtxSocketBind (OSRTSOCKET socket, OSIPADDR addr, int port)
 This function associates a local address with a socket. More...
 
EXTERNRT int rtxSocketClose (OSRTSOCKET socket)
 This function closes an existing socket. More...
 
EXTERNRT int rtxSocketConnect (OSRTSOCKET socket, const char *host, int port)
 This function establishes a connection to a specified socket. More...
 
EXTERNRT int rtxSocketConnectTimed (OSRTSOCKET socket, const char *host, int port, int nsecs)
 This function establishes a connection to a specified socket. More...
 
EXTERNRT int rtxSocketCreate (OSRTSOCKET *psocket)
 This function creates a TCP socket. More...
 
EXTERNRT int rtxSocketGetHost (const char *host, struct in_addr *inaddr)
 This function resolves the given host name to an IP address. More...
 
EXTERNRT int rtxSocketsInit (OSVOIDARG)
 This function initiates use of sockets by an application. More...
 
EXTERNRT int rtxSocketListen (OSRTSOCKET socket, int maxConnection)
 This function places a socket a state where it is listening for an incoming connection. More...
 
EXTERNRT int rtxSocketParseURL (char *url, char **protocol, char **address, int *port)
 This function parses a simple URL of the form <protocol>://<address>:<port> into its individual components. More...
 
EXTERNRT int rtxSocketRecv (OSRTSOCKET socket, OSOCTET *pbuf, size_t bufsize)
 This function receives data from a connected socket. More...
 
EXTERNRT int rtxSocketRecvTimed (OSRTSOCKET socket, OSOCTET *pbuf, size_t bufsize, OSUINT32 secs)
 This function receives data from a connected socket on a timed basis. More...
 
EXTERNRT int rtxSocketSelect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 This function is used for synchronous monitoring of multiple sockets. More...
 
EXTERNRT int rtxSocketSend (OSRTSOCKET socket, const OSOCTET *pdata, size_t size)
 This function sends data on a connected socket. More...
 
EXTERNRT int rtxSocketSetBlocking (OSRTSOCKET socket, OSBOOL value)
 This function turns blocking mode for a socket on or off. More...
 
EXTERNRT int rtxSocketStrToAddr (const char *pIPAddrStr, OSIPADDR *pIPAddr)
 This function converts the string with IP address to a double word representation. More...
 

Detailed Description

Typedef Documentation

◆ OSIPADDR

typedef unsigned long OSIPADDR

The IP address represented as unsigned long value.

The most significant 8 bits in this unsigned long value represent the first number of the IP address. The least significant 8 bits represent the last number of the IP address.

Definition at line 80 of file rtxSocket.h.

Function Documentation

◆ rtxSocketAccept()

EXTERNRT int rtxSocketAccept ( OSRTSOCKET  socket,
OSRTSOCKET pNewSocket,
OSIPADDR destAddr,
int *  destPort 
)

This function permits an incoming connection attempt on a socket.

It extracts the first connection on the queue of pending connections on socket. It then creates a new socket and returns a handle to the new socket. The newly created socket is the socket that will handle the actual connection and has the same properties as original socket. See description of 'accept' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate function.
pNewSocketThe pointer to variable to receive the new socket handle.
destAddrOptional pointer to a buffer that receives the IP address of the connecting entity. It may be NULL.
destPortOptional pointer to a buffer that receives the port of the connecting entity. It may be NULL.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketAddrToStr()

EXTERNRT int rtxSocketAddrToStr ( OSIPADDR  ipAddr,
char *  pbuf,
size_t  bufsize 
)

This function converts an IP address to its string representation.

Parameters
ipAddrThe IP address to be converted.
pbufPointer to the buffer to receive a string with the IP address.
bufsizeSize of the buffer.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketBind()

EXTERNRT int rtxSocketBind ( OSRTSOCKET  socket,
OSIPADDR  addr,
int  port 
)

This function associates a local address with a socket.

It is used on an unconnected socket before subsequent calls to the rtxSocketConnect or rtxSocketListen functions. See description of 'bind' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate function.
addrThe local IP address to assign to the socket.
portThe local port number to assign to the socket.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketClose()

EXTERNRT int rtxSocketClose ( OSRTSOCKET  socket)

This function closes an existing socket.

Parameters
socketThe socket handle created by call to rtxSocketCreate or rtxSocketAccept function.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketConnect()

EXTERNRT int rtxSocketConnect ( OSRTSOCKET  socket,
const char *  host,
int  port 
)

This function establishes a connection to a specified 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. See description of 'connect' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate function.
hostThe null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255).
portThe destination port to connect.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketConnectTimed()

EXTERNRT int rtxSocketConnectTimed ( OSRTSOCKET  socket,
const char *  host,
int  port,
int  nsecs 
)

This function establishes a connection to a specified socket.

It is similar to the rtxSocketConnect function except that it will only wait the given number of seconds to establish a connection before giving up.

Parameters
socketThe socket handle created by call to rtxSocketCreate function.
hostThe null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255).
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.

◆ rtxSocketCreate()

EXTERNRT int rtxSocketCreate ( OSRTSOCKET psocket)

This function creates a TCP socket.

Parameters
psocketThe pointer to the socket handle variable to receive the handle of new socket.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketGetHost()

EXTERNRT int rtxSocketGetHost ( const char *  host,
struct in_addr *  inaddr 
)

This function resolves the given host name to an IP address.

The resulting address is stored in the given socket address structure.

Parameters
hostHost name to resolve
inaddrSocket address structure to receive resolved IP address
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketListen()

EXTERNRT int rtxSocketListen ( OSRTSOCKET  socket,
int  maxConnection 
)

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

To accept connections, a socket is first created with the rtxSocketCreate function and bound to a local address with the rtxSocketBind function, a maxConnection for incoming connections is specified with rtxSocketListen, and then the connections are accepted with the rtxSocketAccept function. See description of 'listen' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate function.
maxConnectionMaximum length of the queue of pending connections.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketParseURL()

EXTERNRT int rtxSocketParseURL ( char *  url,
char **  protocol,
char **  address,
int *  port 
)

This function parses a simple URL of the form <protocol>://<address>:<port> into its individual components.

It is assumed that the buffer the URL is provided in is modifiable. Null-terminators are inserted in the buffer to delimit the individual components. If the user needs to use the URL in unparsed form for any other purpose, they will need to make a copy of it before calling this function.

Parameters
urlURL to be parsed. Buffer will be altered.
protocolProtocol string parsed from the URL.
addressIP address or domain name parsed from URL.
portOptional port number. Zero if no port provided.
Returns
Zero if parse successful or negative error code.

◆ rtxSocketRecv()

EXTERNRT int rtxSocketRecv ( OSRTSOCKET  socket,
OSOCTET *  pbuf,
size_t  bufsize 
)

This function receives data from a connected socket.

It is used to read incoming data on sockets. The socket must be connected before calling this function. See description of 'recv' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate or rtxSocketAccept function.
pbufPointer to the buffer for the incoming data.
bufsizeLength of the buffer.
Returns
If no error occurs, returns the number of bytes received. Otherwise, the negative value is error code.

◆ rtxSocketRecvTimed()

EXTERNRT int rtxSocketRecvTimed ( OSRTSOCKET  socket,
OSOCTET *  pbuf,
size_t  bufsize,
OSUINT32  secs 
)

This function receives data from a connected socket on a timed basis.

It is used to read incoming data on sockets. The socket must be connected before calling this function. If no data is available within the given timeout period, an error is returned. See description of 'recv' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate or rtxSocketAccept function.
pbufPointer to the buffer for the incoming data.
bufsizeLength of the buffer. secs Amount of time to wait, in seconds, for data to be received.
Returns
If no error occurs, returns the number of bytes received. Otherwise, the negative value is error code.

◆ rtxSocketSelect()

EXTERNRT int rtxSocketSelect ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout 
)

This function is used for synchronous monitoring of multiple sockets.

For more information refer to documentation of the "select" system call.

Parameters
nfdsThe highest numbered descriptor to be monitored plus one.
readfdsThe descriptors listed in readfds will be watched for whether read would block on them.
writefdsThe descriptors listed in writefds will be watched for whether write would block on them.
exceptfdsThe descriptors listed in exceptfds will be watched for exceptions.
timeoutUpper bound on amout of time elapsed before select returns.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxSocketSend()

EXTERNRT int rtxSocketSend ( OSRTSOCKET  socket,
const OSOCTET *  pdata,
size_t  size 
)

This function sends data on a connected socket.

It is used to write outgoing data on a connected socket. See description of 'send' socket function for further details.

Parameters
socketThe socket handle created by call to rtxSocketCreate or rtxSocketAccept function.
pdataBuffer containing the data to be transmitted.
sizeLength of the data in pdata.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketSetBlocking()

EXTERNRT int rtxSocketSetBlocking ( OSRTSOCKET  socket,
OSBOOL  value 
)

This function turns blocking mode for a socket on or off.

Parameters
socketThe socket handle created by call to rtxSocketCreate or rtxSocketAccept function.
valueBoolean value. True = turn blocking mode on.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.

◆ rtxSocketsInit()

EXTERNRT int rtxSocketsInit ( OSVOIDARG  )

This function initiates use of sockets by an application.

This function must be called first before use sockets.

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

◆ rtxSocketStrToAddr()

EXTERNRT int rtxSocketStrToAddr ( const char *  pIPAddrStr,
OSIPADDR pIPAddr 
)

This function converts the string with IP address to a double word representation.

The converted address may be used with the rtxSocketBind function.

Parameters
pIPAddrStrThe null-terminated string with the IP address in the following format: "NNN.NNN.NNN.NNN", where NNN is a number in the range (0..255).
pIPAddrPointer to the converted IP address.
Returns
Completion status of operation: 0 (0) = success, negative return value is error.