ADTF  v2.14.3
cDatagramSocket Class Reference

Datagram socket class. More...

Inheritance diagram for cDatagramSocket:

Public Member Functions

 cDatagramSocket ()
 Constructor.
 
virtual ~cDatagramSocket ()
 Destructor.
 
tResult Open (tInt nPort=0, tUInt32 dwMode=cSocket::OM_Block, tUInt32 ui32InterfaceAddress=0)
 Opens a listening socket. More...
 
tResult Write (const cString &strDest, tInt nPort, const tVoid *pData, tInt nDataLength, tInt *pnBytesWritten=NULL)
 Sends a datagram packet. More...
 
tResult Write (tUInt32 dwDest, tInt nPort, const tVoid *pData, tInt nDataLength, tInt *pnBytesWritten=NULL)
 Sends a datagram packet. More...
 
tResult Read (tVoid *pBuffer, tInt nBufferSize, tInt *pnBytesRead=NULL, tUInt32 *pSenderAddr=NULL, tUInt16 *pSenderPort=NULL)
 Read incoming data. More...
 
tResult EnableBroadcasts (tBool bEnable=tTrue)
 If enabled, the socket will receive packets sent to a broadcast address and will be able to send packets to a broadcast address. More...
 
tResult JoinMulticastGroup (tUInt32 nGroupAddr)
 Joins a specified multicast group. More...
 
tResult LeaveMulticastGroup (tUInt32 nGroupAddr)
 Leaves a specified multicast group. More...
 
- Public Member Functions inherited from cSocket
 cSocket ()
 Default constructor.
 
virtual ~cSocket ()
 Default destructor.
 
tVoid Close ()
 Closes the socket and frees all resources. More...
 
tVoid Close (tShutdownMode nHow)
 Closes the socket and frees all resources. More...
 
tUInt32 GetAddress () const
 Retrieves the IP address of the socket. More...
 
tInt GetPort () const
 Retrieves the port of the socket. More...
 
tSocketHandle GetHandle () const
 Get the internal socket handle. More...
 
tBool SetTimeout (tTimeStamp nReadTimeout=-1, tTimeStamp nWriteTimeout=-1)
 Sets timouts fo the read and write socket operations. More...
 
virtual tBool IsConnected (tTimeStamp nTimeout=0)
 Polls the socket for its connection state. More...
 
tBool DataAvailable ()
 Check if data is available for reading (a subsequent read succeed immediately). More...
 
tBool WaitForData (tTimeStamp nTimeout=-1)
 Blocks the current process until data is available for reading. More...
 
tInt SetOption (tInt nLevel, tInt nOptionId, const tVoid *pValue, tInt nValueLen)
 Sets a specific option for the socket. More...
 
tInt SetOption (cSocket::tOptionLevel eLevel, cSocket::tOptionId eId, const tVoid *pValue, tInt nValueLen)
 Equivalent to SetOption (tInt, tInt, const tVoid*, tInt) Instead of the system specific constants (e.g. More...
 
tResult GetOption (tInt nLevel, tInt nOptionId, tVoid *o_pValue, tInt *o_pValueLen)
 gets a specific option for the socket. More...
 
tResult GetOption (cSocket::tOptionLevel eLevel, cSocket::tOptionId eId, tVoid *o_pValue, tInt *o_pValueLen)
 Equivalent with GetOption(tInt, tInt, tVoid*, tInt*). More...
 

Additional Inherited Members

- Public Types inherited from cSocket
enum  tOpenMode { OM_Block = 0x0, OM_NonBlock = 0x01, OM_NoAddressReuse = 0x02 }
 The mode in which to run the sockets during and after a connection. More...
 
enum  tShutdownMode { SM_Read = 0, SM_Write = 1, SM_ReadWrite = 2 }
 The mode in which to switch the sockets to on shutdown. More...
 
enum  tOptionLevel { OL_SOCKET = 1, OL_IPPROTO_TCP = 2 }
 Abstraction of the system specific socket option levels (e.g. More...
 
enum  tOptionId {
  OI_DEBUG, OI_BROADCAST, OI_REUSEADDR, OI_KEEPALIVE,
  OI_LINGER, OI_SNDBUF, OI_RCVBUF, OI_DONTROUTE,
  OI_TCP_NODELAY
}
 Abstraction of the system specific socket options (e.g. More...
 
- Static Public Member Functions inherited from cSocket
static tVoid AddLibraryRef ()
 for the work with the static methods you have to use this function to load the nessessary libs, after work ReleaseLibraryRef has to be called.
 
static tVoid ReleaseLibraryRef ()
 to correctly unload the socket-libs you have to call this function
 
static cString GetHostName (tUInt32 dwHostAddress=0)
 Returns the hostname for a given address. More...
 
static tUInt32 GetHostAddress (const cString &strHostName="")
 Returns the address for a given hostname. More...
 
static tUInt32 AddressToUInt32 (const cString &strAddress)
 Converts a aaa.bbb.ccc.ddd formated address string to an integer. More...
 
static cString UInt32ToAddress (tUInt32 ui32Address)
 Converts an integer to an aaa.bbb.ccc.ddd formated address string. More...
 
static tInt GetLastErrorCode ()
 Gets the error code of the last failure. More...
 
static tResult GetLocalAddresses (std::set< tUInt32, std::less< tUInt32 >, std::allocator< tUInt32 > > &oAddresses)
 Returns a list of addresses from all local interfaces. More...
 
static tResult SocketError (tInt nSocketError)
 Maps a socket error to an A_UTILS error. More...
 
static tResult FindInterfaceForAddress (tUInt32 ui32FarAddress, tUInt32 &ui32LocalAddress)
 If more than one network interface is used in the host the FindInterfaceForAddress finds out the local address of the interface where the far address is reachable. More...
 
static tResult WaitForData (const std::list< cSocket * > &i_lstSockets, cSocket **o_ppSocket, tTimeStamp tmTimeOut=-1)
 Blocks the current thread until data are available for reading in at least one of i_lstSockets. More...
 
- Static Public Attributes inherited from cSocket
static const tUInt32 SOCKET_NO_ADDRESS
 Constance for check No Address.
 
- Protected Member Functions inherited from cSocket
tBool Initialize ()
 Sets the params for the socket with 0/NULL. More...
 
tInt ResolveOptionLevel (tOptionLevel level) const
 Resolve the option value of the socket. More...
 
tInt ResolveOptionId (tOptionId id) const
 Resolve the option id of the socket. More...
 
- Protected Attributes inherited from cSocket
tSocketHandle m_hSocket
 this is internal handle of the socket, only use it if you really need that!!
 
tUInt32 m_ui32Address
 Address of the socket (valid only if opened)
 
tInt m_nPort
 Port of the socket (valid only if opened)
 

Detailed Description

Datagram socket class.

Remarks
Multicast on WIN32 platforms:
If your host cannot read the multicast messages you sent the following reasons could be responsible:

Definition at line 36 of file datagramsocket.h.

Member Function Documentation

tResult EnableBroadcasts ( tBool  bEnable = tTrue)

If enabled, the socket will receive packets sent to a broadcast address and will be able to send packets to a broadcast address.

Parameters
[in]bEnableWhether to enable broadcasts or not.
Return values
ERR_INVALID_HANDLEThe descriptor is not valid (EBADF).
ERR_MEMORYThe option value is not in a valid part of the process address space (EFAULT).
ERR_INVALID_FLAGSThe option length is invalid (EINVAL).
ERR_UNKNOWNThe option is unknown at the indicated level (ENOPROTOOPT).
Thedescriptor does not refer to a socket (ENOTSOCK).
tResult JoinMulticastGroup ( tUInt32  nGroupAddr)

Joins a specified multicast group.

IP of a MulticastGroup is between 224.0.0.1 and 239.255.255.255 .

Remarks
  • If JoinMulticastGroup fails on address 224.0.0.1 with the
  • error ERR_UNEXPECTED on Windows Vista or Windows 7 try disabling all wireless
  • adapters in the System (Bluetooth & WLAN). This seems to be a
  • known Problem in Windows.
Parameters
nGroupAddrThe multicast address of the group.
Return values
ERR_INVALID_HANDLEThe descriptor is not valid (EBADF).
ERR_MEMORYThe option value is not in a valid part of the process address space (EFAULT).
ERR_INVALID_FLAGSThe option length is invalid (EINVAL).
ERR_UNKNOWNThe option is unknown at the indicated level (ENOPROTOOPT).
Thedescriptor does not refer to a socket (ENOTSOCK).
tResult LeaveMulticastGroup ( tUInt32  nGroupAddr)

Leaves a specified multicast group.

Parameters
nGroupAddrThe multicast address of the group.
Return values
ERR_INVALID_HANDLEThe descriptor is not valid (EBADF).
ERR_MEMORYThe option value is not in a valid part of the process address space (EFAULT).
ERR_INVALID_FLAGSThe option length is invalid (EINVAL).
ERR_UNKNOWNThe option is unknown at the indicated level (ENOPROTOOPT).
Thedescriptor does not refer to a socket (ENOTSOCK).
tResult Open ( tInt  nPort = 0,
tUInt32  dwMode = cSocket::OM_Block,
tUInt32  ui32InterfaceAddress = 0 
)

Opens a listening socket.

Parameters
nPortThe port on which to listen for data.
dwModeThe mode in which to drive the socket instance (blocking or non-blocking mode, see tOpenMode).
ui32InterfaceAddressThe interface to bind to (network byte order). If 0 any address will be used.
Return values
ERR_INVALID_ARGIllegal port number committed
ERR_ACCESS_DENIEDPermission to create a socket of the specified type and/or protocol is denied (EACCES).
ERR_NOT_SUPPORTEDThe implementation does not support the specified address family or the protocol type or the specified protocol is not supported within this domain (EAFNOSUPPORT or EPROTONOSUPPORT).
ERR_INVALID_FLAGSUnknown protocol or protocol family not available (EINVAL).
ERR_MEMORYProcess file table overflow or the system limit on the total number of open files has been reached or insufficient memory is available (EMFILE or ENFILE or ENOBUFS or ENOMEM).
ERR_OPEN_FAILEDOther error detected
ERR_RESSOURCE_IN_USECould not set socket options
ERR_TIMEOUTA connection could not be established immediately. (Non-blocking only!)
tResult Read ( tVoid pBuffer,
tInt  nBufferSize,
tInt pnBytesRead = NULL,
tUInt32 pSenderAddr = NULL,
tUInt16 pSenderPort = NULL 
)

Read incoming data.

Parameters
pBufferThe buffer where the data should be stored.
nBufferSizeThe size of the buffer.
pnBytesReadIf specified, this value is filled with the actual amount of bytes copied into the buffer.
pSenderAddrIf specified, this will be filled with the senders address.
pSenderPortIf specified, this will be filled with the senders port.
Return values
ERR_POINTERNull-pointer committed
ERR_INVALID_ARGNegative buffer size committed
ERR_TIMEOUTThe socket is marked non-blocking and the receive operation would block or a receive timeout expored before data was received (EAGAIN or EWOULDBLOCK).
ERR_INVALID_HANDLEAn invalid descriptor was specified (EBADF).
ERR_ACCESS_DENIEDA remote host refused to allow the network connection (ECONNREFUSED).
ERR_MEMORYThe receive buffer pointer(s) point outside the process's address space or no memory could be allocated (EFAULT or ENOMEM).
ERR_CANCELLEDThe receive was interrupted by delivery of a signal before any data were available (EINTR).
ERR_INVALID_FLAGSInvalid argument passed (EINVAL).
ERR_BAD_DEVICEThe descriptor does not refer to a socket (ENOTSOCK).
ERR_DEVICE_IOOther error detected
tResult Write ( const cString strDest,
tInt  nPort,
const tVoid pData,
tInt  nDataLength,
tInt pnBytesWritten = NULL 
)

Sends a datagram packet.

Parameters
strDestThe destination address.
nPortThe destination port.
pDataThe data which is to be sent.
nDataLengthThe size of the data.
pnBytesWrittenIf specified, this value is filled with the actual amount of bytes sent.
Return values
ERR_POINTERNull-pointer committed
ERR_INVALID_ARGNegative data length committed
ERR_INVALID_ADDRESSHost resolving failed
ERR_ACCESS_DENIEDWrite permission is denied on the destination socket file (EACCES).
ERR_TIMEOUTThe socket is marked non-blocking and the requested operation would block (EAGAIN or EWOULDBLOCK). In normal mode, this simply implies write operation that has not returned immediately.
ERR_INVALID_HANDLEAn invalid descriptor was specified (EBADF).
ERR_CANCELLEDConnection reset by peer or a signal occurred before any data was transmitted (ECONNRESET or EINTR).
ERR_INVALID_ADDRESSNo peer address is set (EDESTADDRREQ).
ERR_MEMORYAn invalid user space address was specified for a parameter or the size of the message to be sent made automatic sending impossible or the output queue for a network interface was full or no memory available (EFAULT or EMSGSIZE or ENOBUFS or ENOMEM).
ERR_INVALID_FLAGSInvalid argument passed or some bit in the flags is inappropriate for the socket type (EINVAL or EOPNOTSUPP).
ERR_NOT_CONNECTEDThe socket is not connected (ENOTCONN).
ERR_BAD_DEVICEThe descriptor does not refer to a socket (ENOTSOCK).
ERR_DEVICE_IOOther error detected
tResult Write ( tUInt32  dwDest,
tInt  nPort,
const tVoid pData,
tInt  nDataLength,
tInt pnBytesWritten = NULL 
)

Sends a datagram packet.

Parameters
dwDestThe destination address.
nPortThe destination port.
pDataThe data which is to be sent.
nDataLengthThe size of the data.
pnBytesWrittenIf specified, this value is filled with the actual amount of bytes sent.
Return values
ERR_POINTERNull-pointer committed
ERR_INVALID_ARGNegative data length committed
ERR_INVALID_ADDRESSHost resolving failed
ERR_ACCESS_DENIEDWrite permission is denied on the destination socket file (EACCES).
ERR_TIMEOUTThe socket is marked non-blocking and the requested operation would block (EAGAIN or EWOULDBLOCK). In normal mode, this simply yields a write timeout.
ERR_INVALID_HANDLEAn invalid descriptor was specified (EBADF).
ERR_CANCELLEDConnection reset by peer or a signal occurred before any data was transmitted (ECONNRESET or EINTR).
ERR_INVALID_ADDRESSNo peer address is set (EDESTADDRREQ).
ERR_MEMORYAn invalid user space address was specified for a parameter or the size of the message to be sent made automatic sending impossible or the output queue for a network interface was full or no memory available (EFAULT or EMSGSIZE or ENOBUFS or ENOMEM).
ERR_INVALID_FLAGSInvalid argument passed or some bit in the flags is inappropriate for the socket type (EINVAL or EOPNOTSUPP).
ERR_NOT_CONNECTEDThe socket is not connected (ENOTCONN).
ERR_BAD_DEVICEThe descriptor does not refer to a socket (ENOTSOCK).
ERR_DEVICE_IOOther error detected

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Fri Mar 22 2019 by doxygen 1.8.10)