Go to the documentation of this file.
44 #ifndef COMMONCPP_UDP_H_
45 #define COMMONCPP_UDP_H_
49 #ifndef COMMONCPP_CONFIG_H_
50 #include <commoncpp/config.h>
53 #ifndef COMMONCPP_STRING_H_
57 #ifndef COMMONCPP_ADDRESS_H_
61 #ifndef COMMONCPP_SOCKET_H_
102 inline Error setKeepAlive(
bool enable)
103 {
return Socket::setKeepAlive(enable);}
108 Socket::address peer;
147 {
return Socket::setLoopbackByFamily(enable, family);}
153 {
return Socket::setMulticastByFamily(enable, family);}
159 {
return Socket::setTimeToLiveByFamily(ttl, family);}
196 Socket::Error join(
const IPV4Multicast &ia,
int InterfaceIndex);
205 ssize_t
send(
const void *buf,
size_t len);
215 ssize_t
receive(
void *buf,
size_t len,
bool reply =
false);
229 {
return getIPV4Peer(port);}
242 inline ssize_t
peek(
void *buf,
size_t len)
243 {return ::recv(so, (
char *)buf, (socksize_t)len, MSG_PEEK);}
249 void connect(
const char *service);
271 Error setBroadcast(
bool enable)
272 {
return Socket::setBroadcast(enable);}
387 inline ssize_t
send(
const void *buf,
size_t len)
388 {return ::send(so, (
const char *)buf, (socksize_t)len, MSG_NOSIGNAL);}
394 {Socket::endSocket();}
401 inline SOCKET getTransmitter(
void)
404 inline Error setMulticast(
bool enable)
405 {
return Socket::setMulticastByFamily(enable, family);}
407 inline Error setTimeToLive(uint8_t ttl)
408 {
return Socket::setTimeToLiveByFamily(ttl, family);}
420 inline ssize_t
transmit(
const char *buffer,
size_t len)
421 {return ::send(so, buffer, (socksize_t)len, MSG_DONTWAIT|MSG_NOSIGNAL);}
430 return Socket::isPending(Socket::pendingOutput, timeout);
434 inline Error setRouting(
bool enable)
435 {
return Socket::setRouting(enable);}
437 inline Error setTypeOfService(Tos tos)
438 {
return Socket::setTypeOfService(tos);}
440 inline Error setBroadcast(
bool enable)
441 {
return Socket::setBroadcast(enable);}
495 return Socket::isPending(Socket::pendingInput, timeout);
502 {Socket::endSocket();}
504 inline SOCKET getReceiver(
void)
const
507 inline Error setRouting(
bool enable)
508 {
return Socket::setRouting(enable);}
510 inline Error setMulticast(
bool enable)
511 {
return Socket::setMulticastByFamily(enable, family);}
514 {
return Socket::join(ia);}
516 inline Error join(
const IPV4Multicast &ia)
517 {
return Socket::join(ia);}
520 inline Error join(
const IPV6Multicast &ia)
521 {
return Socket::join(ia);}
524 inline Error drop(
const IPV4Multicast &ia)
525 {
return Socket::drop(ia);}
528 inline Error drop(
const IPV6Multicast &ia)
529 {
return Socket::drop(ia);}
541 {return ::recv(so, (
char *)buf, (socksize_t)len, 0);}
550 return Socket::isPending(Socket::pendingInput, timeout);
ssize_t send(const void *buf, size_t len)
Transmit "send" to use "connected" send rather than sendto.
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
ssize_t receive(void *buf, size_t len)
Receive a data packet from the connected peer host.
Representing half of a two-way UDP connection, the UDP transmitter can broadcast data to another sele...
in_port_t tpport_t
Transport Protocol Ports.
void endReceiver(void)
End receiver.
void endTransmitter(void)
Stop transmitter.
ssize_t receive(void *buf, size_t len, bool reply=false)
Receive a message from any host.
UDPSocket(Family family=IPV4)
Create an unbound UDP socket, mostly for internal use.
ucommon::Socket::address getPeer()
Examine address of sender of next waiting packet.
UDPSocket(const ucommon::Socket::address &bind)
Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on...
Representing a UDP socket used for subnet broadcasts, this class provides an alternate binding and se...
virtual ~UDPSocket()
Destroy a UDP socket as a socket.
Socket::Error getInterfaceIndex(const char *ethX, int &InterfaceIndex)
get the interface index for a named network device
Socket::Error join(const ucommon::Socket::address &ia, int InterfaceIndex=0)
join a multicast group on a particular interface
Error connect(const IPV4Multicast &mgroup, tpport_t port)
Associate this socket with a multicast group.
bool isOutputReady(unsigned long timeout=0l)
See if output queue is empty for sending more packets.
void setPeer(const ucommon::Socket::address &host)
set the peer address to send message packets to.
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
Network addresses and sockets related classes.
void setPeer(const IPV4Broadcast &subnet, tpport_t port)
Set peer by subnet rather than specific host.
UDPTransmit(Family family=IPV4)
Create a UDP transmitter.
Common C++ generic string class.
Error setTimeToLive(char ttl)
Set time to live.
A generic socket address class.
ssize_t send(const void *buf, size_t len)
Send a message packet to a peer host.
A specialization of IPV6Address that provides address validation for multicast addresses.
Error disconnect(void)
Disassociate this socket from any host connection.
The broadcast address object is used to store the broadcast address for a specific subnet.
UDPDuplex(const ucommon::Socket::address &bind)
Create a UDP duplex as a pair of UDP simplex objects bound to alternating and interconnected port add...
UDPReceive(const ucommon::Socket::address &bind)
Create a UDP receiver, bind it to a specific interface and port address so that other UDP sockets on ...
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Error connect(const ucommon::Socket::address &host)
Associate the duplex with a specified peer host.
UDPSocket(const char *name, Family family=IPV4)
Create a UDP socket bound by a service name.
ssize_t transmit(const char *buffer, size_t len)
Transmit "send" to use "connected" send rather than sendto.
UDP duplex connections impliment a bi-directional point-to-point UDP session between two peer hosts.
Error disconnect(void)
Disassociate this duplex from any host connection.
UDPTransmit(const ucommon::Socket::address &bind)
Create a UDP transmitter, bind it to a specific interface and port address so that other UDP sockets ...
bool isPendingReceive(timeout_t timeout)
Check for pending data.
Error connect(const ucommon::Socket::address &host)
Associate this socket with a specified peer host.
Error setMulticast(bool enable)
Set the multicast.
The network name and address objects are all derived from a common IPV6Address base class.
UDPBroadcast(const IPV4Address &ia, tpport_t port)
Create and bind a subnet broadcast socket.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
void setPeer(const char *service)
Associate socket with a named connection.
bool isInputReady(timeout_t timeout=ucommon::Timer::inf)
See if input queue has data packets available.
Error setLoopback(bool enable)
Set the loopback.
Error connect(const IPV4Broadcast &subnet, tpport_t port)
Associate this socket with a subnet of peer hosts for subnet broadcasting.
Error connect(const ucommon::Socket::address &host)
Associate this socket with a specified peer host.
The network name and address objects are all derived from a common IPV4Address base class.
Representing half of a two-way UDP connection, the UDP receiver can receive data from another peer ho...
A specialization of IPV4Address that provides address validation for multicast addresses.