Classes | Macros | Typedefs | Enumerations | Functions
xssocket.h File Reference
#include "xsstring.h"
#include "xsbytearray.h"
#include "xsresultvalue.h"
#include "xstypedefs.h"
Include dependency graph for xssocket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  XsSocket
 A platform independent socket implementation. More...
 

Macros

#define XSSOCKET_INFINITE_TIMEOUT   -1
 
#define XSSOCKET_INITIALIZER   { NULL }
 

Typedefs

typedef int XSOCKET
 
typedef struct XsSocket XsSocket
 

Enumerations

enum  IpProtocol { IP_UDP, IP_TCP }
 the protocol on top of IP More...
 
enum  NetworkLayerProtocol { NLP_IPV4, NLP_IPV6, NLP_IPVX }
 The network layer protocol, or IP address family. More...
 
enum  XsSocketOption { XSO_ReuseAddress, XSO_ReusePort }
 

Functions

XSTYPES_DLL_API XsSocketXsSocket_accept (XsSocket *thisPtr, int mstimeout)
 Accept an incoming connection. More...
 
XSTYPES_DLL_API XsSocketXsSocket_allocate ()
 Dynamically allocate an XsSocket. More...
 
XSTYPES_DLL_API XsResultValue XsSocket_bind (XsSocket *thisPtr, const XsString *hostname, uint16_t port)
 Bind to the hostname and port combination. More...
 
XSTYPES_DLL_API int XsSocket_broadcast (XsSocket *thisPtr, const void *buffer, XsSize size, uint16_t port)
 Broadcast data over the socket to the port indicated by port. More...
 
XSTYPES_DLL_API XsResultValue XsSocket_close (XsSocket *thisPtr)
 
XSTYPES_DLL_API XsResultValue XsSocket_connect (XsSocket *thisPtr, const XsString *host, uint16_t port)
 Connect to hostame on port. More...
 
XSTYPES_DLL_API void XsSocket_create (XsSocket *thisPtr, enum NetworkLayerProtocol ip, enum IpProtocol protocol)
 Create socket thisPtr for IP version ip with protocol protocol. More...
 
XSTYPES_DLL_API void XsSocket_createFromFileDescriptor (XsSocket *thisPtr, int sockfd, XsDataFlags flags)
 
XSTYPES_DLL_API void XsSocket_destroy (XsSocket *thisPtr)
 Destroy the given socket. More...
 
XSTYPES_DLL_API int XsSocket_enableBroadcasts (XsSocket *thisPtr, int enable)
 
XSTYPES_DLL_API void XsSocket_flush (XsSocket *thisPtr)
 Flush the incoming data. More...
 
XSTYPES_DLL_API void XsSocket_free (XsSocket *thisPtr)
 Free a socket returned from XsSocket_accept() or XsSocket_allocate() More...
 
XSTYPES_DLL_API int XsSocket_getLastSystemError (const XsSocket *thisPtr)
 Return the system error code of the last socket operation. More...
 
XSTYPES_DLL_API void XsSocket_getRemoteAddress (const XsSocket *thisPtr, XsString *address)
 Get the numeric IP address of remote host of this socket. More...
 
XSTYPES_DLL_API int XsSocket_isUsable (const XsSocket *thisPtr)
 Return non-zero if the socket is usable for reading and writing data. More...
 
XSTYPES_DLL_API XsResultValue XsSocket_listen (XsSocket *thisPtr, int maxPending)
 Start listening for incoming connections on this socket. More...
 
XSTYPES_DLL_API XSOCKET XsSocket_nativeDescriptor (XsSocket const *thisPtr)
 Return the native file descriptor. More...
 
XSTYPES_DLL_API int XsSocket_read (XsSocket *thisPtr, void *dest, XsSize size, int timeout)
 Read size data into dest. More...
 
XSTYPES_DLL_API int XsSocket_read2ByteArray (XsSocket *thisPtr, XsByteArray *dest, int timeout)
 Read size data into dest. More...
 
XSTYPES_DLL_API int XsSocket_readFrom (XsSocket *thisPtr, void *dest, XsSize size, XsString *hostname, uint16_t *port, int timeout)
 Read size data into dest. More...
 
XSTYPES_DLL_API int XsSocket_readFrom2ByteArray (XsSocket *thisPtr, XsByteArray *dest, XsString *hostname, uint16_t *port, int timeout)
 Read size data into dest. More...
 
XSTYPES_DLL_API int XsSocket_select (XsSocket *thisPtr, int mstimeout, int *canRead, int *canWrite)
 
XSTYPES_DLL_API XsResultValue XsSocket_setSocketOption (XsSocket *thisPtr, enum XsSocketOption option, void *valuePtr, int valueSize)
 
XSTYPES_DLL_API int XsSocket_write (XsSocket *thisPtr, const void *buffer, XsSize size)
 Write data to the socket. More...
 
XSTYPES_DLL_API int XsSocket_writeTo (XsSocket *thisPtr, const void *buffer, XsSize size, const XsString *hostname, uint16_t port)
 Write data to the socket to the host indicated by hostname, port. More...
 

Macro Definition Documentation

◆ XSSOCKET_INFINITE_TIMEOUT

#define XSSOCKET_INFINITE_TIMEOUT   -1

Definition at line 115 of file xssocket.h.

◆ XSSOCKET_INITIALIZER

#define XSSOCKET_INITIALIZER   { NULL }

Definition at line 112 of file xssocket.h.

Typedef Documentation

◆ XSOCKET

typedef int XSOCKET

Definition at line 105 of file xssocket.h.

◆ XsSocket

typedef struct XsSocket XsSocket

Definition at line 75 of file xssocket.h.

Enumeration Type Documentation

◆ IpProtocol

enum IpProtocol

the protocol on top of IP

Enumerator
IP_UDP 

The UDP/IP protocol.

IP_TCP 

The TCP/IP protocol.

Definition at line 78 of file xssocket.h.

◆ NetworkLayerProtocol

The network layer protocol, or IP address family.

Enumerator
NLP_IPV4 

IPv4 address family.

NLP_IPV6 

IPv6 address family.

NLP_IPVX 

any IP address family

Definition at line 85 of file xssocket.h.

◆ XsSocketOption

Enumerator
XSO_ReuseAddress 

Allow bind to reuse a local port (using different local addresses)

XSO_ReusePort 

Allow bind to reuse the exact local address.

Definition at line 92 of file xssocket.h.

Function Documentation

◆ XsSocket_accept()

XSTYPES_DLL_API XsSocket* XsSocket_accept ( XsSocket thisPtr,
int  mstimeout 
)

Accept an incoming connection.

This function requires that XsSocket_listen() has already been called.

The returned pointer should be freed using XsSocket_freeAcceptedSocket().

\param[in] mstimeout the timeout in milliseconds

\returns a pointer to a newly created socket for the new connection. NULL on error.
\relates XsSocket

Definition at line 1084 of file xssocket.c.

◆ XsSocket_allocate()

XSTYPES_DLL_API XsSocket* XsSocket_allocate ( )

Dynamically allocate an XsSocket.

After calling this function, it is still required to call
XsSocket_create or the internal function XsSocket_createFromNativeSocket

Use XsSocket_free to safely free the returned XsSocket.

\returns a pointer to a newly allocated XsSocket, or NULL on error

Definition at line 1126 of file xssocket.c.

◆ XsSocket_bind()

XSTYPES_DLL_API XsResultValue XsSocket_bind ( XsSocket thisPtr,
const XsString hostname,
uint16_t  port 
)

Bind to the hostname and port combination.

\param[in] hostname the hostname to bind to, may be NULL, in which we will bind to any address
\param[in] port the port to bind to. Must be a value above 1023, unless we have elevated privileges

\return an XsResultValue indicating the result of the operation, possibly pointing towards a cause
\relates XsSocket

Definition at line 1220 of file xssocket.c.

◆ XsSocket_broadcast()

XSTYPES_DLL_API int XsSocket_broadcast ( XsSocket thisPtr,
const void *  data,
XsSize  size,
uint16_t  port 
)

Broadcast data over the socket to the port indicated by port.

\param[in] data the data to write
\param[in] size the size of the data
\param[in] port the port to send data to

\returns the number of bytes written, -1 on error, depending on whether the majority of sub broadcasts succeeded or failed.
\relates XsSocket

Definition at line 924 of file xssocket.c.

◆ XsSocket_close()

XSTYPES_DLL_API XsResultValue XsSocket_close ( XsSocket thisPtr)
related

◆ XsSocket_connect()

XSTYPES_DLL_API XsResultValue XsSocket_connect ( XsSocket thisPtr,
const XsString host,
uint16_t  port 
)

Connect to hostame on port.

\param[in] host the hostname to connect to
\param[in] port the port to connect to

\returns an XsResultValue indicating the result of the operation
\relates XsSocket

Definition at line 1296 of file xssocket.c.

◆ XsSocket_create()

XSTYPES_DLL_API void XsSocket_create ( XsSocket thisPtr,
enum NetworkLayerProtocol  ip,
enum IpProtocol  protocol 
)

Create socket thisPtr for IP version ip with protocol protocol.

\param[in] ip the IP version
\param[in] protocol the protocol. Currently supported are TCP and UDP
\relates XsSocket

Definition at line 350 of file xssocket.c.

◆ XsSocket_createFromFileDescriptor()

XSTYPES_DLL_API void XsSocket_createFromFileDescriptor ( XsSocket thisPtr,
int  sockfd,
XsDataFlags  flags 
)
related

◆ XsSocket_destroy()

XSTYPES_DLL_API void XsSocket_destroy ( XsSocket thisPtr)

Destroy the given socket.

After calling this function, the XsSocket will no longer be usable for socket communications.

It is safe to call this function twice on the same XsSocket.

If the socket was created from a file descriptor using
XsSocket_createFromFileDescriptor and had the XSDF_Managed flag set then
the underlying socket will be closed.

\relates XsSocket

Definition at line 457 of file xssocket.c.

◆ XsSocket_enableBroadcasts()

XSTYPES_DLL_API int XsSocket_enableBroadcasts ( XsSocket thisPtr,
int  enable 
)
related

◆ XsSocket_flush()

XSTYPES_DLL_API void XsSocket_flush ( XsSocket thisPtr)

Flush the incoming data.

Flush all data from the incoming buffer.

\relates XsSocket

Definition at line 1063 of file xssocket.c.

◆ XsSocket_free()

XSTYPES_DLL_API void XsSocket_free ( XsSocket thisPtr)

Free a socket returned from XsSocket_accept() or XsSocket_allocate()

Use this function only on sockets returned from XsSocket_accept().

This function calls XsSocket_destroy() before freeing the memory.

\see XsSocket_destroy
\relates XsSocket

Definition at line 1140 of file xssocket.c.

◆ XsSocket_getLastSystemError()

XSTYPES_DLL_API int XsSocket_getLastSystemError ( const XsSocket thisPtr)

Return the system error code of the last socket operation.

Returns
The error code

Definition at line 1324 of file xssocket.c.

◆ XsSocket_getRemoteAddress()

XSTYPES_DLL_API void XsSocket_getRemoteAddress ( const XsSocket thisPtr,
XsString address 
)

Get the numeric IP address of remote host of this socket.

Parameters
[in,out]addressXsString to return the remote host IP address in

Definition at line 1315 of file xssocket.c.

◆ XsSocket_isUsable()

XSTYPES_DLL_API int XsSocket_isUsable ( const XsSocket thisPtr)

Return non-zero if the socket is usable for reading and writing data.

\returns non-zero if the socket is usable for reading and writing data, zero otherwise
\relates XsSocket

Definition at line 1306 of file xssocket.c.

◆ XsSocket_listen()

XSTYPES_DLL_API XsResultValue XsSocket_listen ( XsSocket thisPtr,
int  maxPending 
)

Start listening for incoming connections on this socket.

\param[in] maxPending the maximum amount of pending connections

\return an XsResultValue indicating the result of the operation
\relates XsSocket

Definition at line 1259 of file xssocket.c.

◆ XsSocket_nativeDescriptor()

XSTYPES_DLL_API XSOCKET XsSocket_nativeDescriptor ( XsSocket const *  thisPtr)

Return the native file descriptor.

 The native socket descriptor returned from this function should only be
 passed to third party libraries. However, it is possible to select, read and
 write on it, if you know what you're doing. Do remember that this object
 still manages the lifetime of the file descriptor.

Definition at line 422 of file xssocket.c.

◆ XsSocket_read()

XSTYPES_DLL_API int XsSocket_read ( XsSocket thisPtr,
void *  dest,
XsSize  size,
int  timeout 
)

Read size data into dest.

\param[in,out] dest a pointer to a data buffer
\param[in] size the size of the buffer \a dest points to
\param[in] timeout the amount of time in milliseconds to wait for data

\returns the size of the data read from the socket, -1 on error.
\relates XsSocket

Definition at line 545 of file xssocket.c.

◆ XsSocket_read2ByteArray()

XSTYPES_DLL_API int XsSocket_read2ByteArray ( XsSocket thisPtr,
XsByteArray dest,
int  timeout 
)

Read size data into dest.

\param[in,out] dest a pointer to a data buffer XsByteArray, may be NULL, in which case only the size of the pending data is reported.
\param[in] timeout the amount of time in milliseconds to wait for data

\returns the size of the data read from the socket, -1 on error.
\relates XsSocket

Definition at line 609 of file xssocket.c.

◆ XsSocket_readFrom()

XSTYPES_DLL_API int XsSocket_readFrom ( XsSocket thisPtr,
void *  dest,
XsSize  size,
XsString hostname,
uint16_t *  port,
int  timeout 
)

Read size data into dest.

\param[in,out] dest a pointer to a data buffer, may be NULL, in which case only the size of the pending data is reported.
\param[in] size the size of the buffer \a dest points to
\param[in,out] hostname a pointer to a string that contains the hostname of the sender after returning from this function. May be NULL.
\param[in,out] port a pointer that will contain the port of the sender after returning from this function. May be NULL.
\param[in] timeout the amount of time in milliseconds to wait for data

\returns the size of the data read from the socket, -1 on error.
\relates XsSocket

Definition at line 574 of file xssocket.c.

◆ XsSocket_readFrom2ByteArray()

XSTYPES_DLL_API int XsSocket_readFrom2ByteArray ( XsSocket thisPtr,
XsByteArray dest,
XsString hostname,
uint16_t *  port,
int  timeout 
)

Read size data into dest.

\param[in,out] dest a pointer to a data buffer XsByteArray, may be NULL, in which case only the size of the pending data is reported.
\param[in,out] hostname a pointer to a string that contains the hostname of the sender after returning from this function. May be NULL.
\param[in,out] port a pointer that will contain the port of the sender after returning from this function. May be NULL.
\param[in] timeout the amount of time in milliseconds to wait for data

\returns the size of the data read from the socket, -1 on error.
\relates XsSocket

Definition at line 624 of file xssocket.c.

◆ XsSocket_select()

XSTYPES_DLL_API int XsSocket_select ( XsSocket thisPtr,
int  mstimeout,
int *  canRead,
int *  canWrite 
)
related

◆ XsSocket_setSocketOption()

XSTYPES_DLL_API XsResultValue XsSocket_setSocketOption ( XsSocket thisPtr,
enum XsSocketOption  option,
void *  valuePtr,
int  valueSize 
)
related

◆ XsSocket_write()

XSTYPES_DLL_API int XsSocket_write ( XsSocket thisPtr,
const void *  data,
XsSize  size 
)

Write data to the socket.

\param[in] data a pointer to the data to write
\param[in] size the size of the data to write

\returns the number of bytes written, -1 or 0 on error
\relates XsSocket

Definition at line 665 of file xssocket.c.

◆ XsSocket_writeTo()

XSTYPES_DLL_API int XsSocket_writeTo ( XsSocket thisPtr,
const void *  data,
XsSize  size,
const XsString hostname,
uint16_t  port 
)

Write data to the socket to the host indicated by hostname, port.

\param[in] data the data to write
\param[in] size the size of the data
\param[in] hostname the name of the host to send data to
\param[in] port the port to send data to

\returns the number of bytes written, -1 on error.
\relates XsSocket

Definition at line 861 of file xssocket.c.



xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:21