43 #ifndef COMMONCPP_UDP_H_
44 #define COMMONCPP_UDP_H_
48 #ifndef COMMONCPP_CONFIG_H_
49 #include <commoncpp/config.h>
52 #ifndef COMMONCPP_STRING_H_
56 #ifndef COMMONCPP_ADDRESS_H_
60 #ifndef COMMONCPP_SOCKET_H_
101 inline Error setKeepAlive(
bool enable)
102 {
return Socket::setKeepAlive(enable);};
107 struct sockaddr_in6 ipv6;
108 struct sockaddr_in ipv4;
112 struct sockaddr_in ipv4;
127 UDPSocket(
const char *name, Family family = IPV4);
152 {
return Socket::setLoopbackByFamily(enable, family);}
158 {
return Socket::setMulticastByFamily(enable, family);}
164 {
return Socket::setTimeToLiveByFamily(ttl, family);}
173 void setPeer(
const IPV4Host &host, tpport_t port);
174 void connect(
const IPV4Host &host, tpport_t port);
176 void setPeer(
const IPV6Host &host, tpport_t port);
177 void connect(
const IPV6Host &host, tpport_t port);
187 Socket::Error getInterfaceIndex(
const char *ethX,
int& InterfaceIndex);
197 Socket::Error join(
const IPV4Multicast &ia,
int InterfaceIndex);
206 ssize_t send(
const void *buf,
size_t len);
216 ssize_t receive(
void *buf,
size_t len,
bool reply =
false);
226 IPV4Host getIPV4Peer(tpport_t *port = NULL)
const;
227 inline IPV4Host getPeer(tpport_t *port = NULL)
const
228 {
return getIPV4Peer(port);}
231 IPV6Host getIPV6Peer(tpport_t *port = NULL)
const;
241 inline ssize_t
peek(
void *buf,
size_t len)
242 {return ::recv(so, (
char *)buf, len, MSG_PEEK);};
247 void setPeer(
const char *service);
248 void connect(
const char *service);
254 Error disconnect(
void);
270 Error setBroadcast(
bool enable)
271 {
return Socket::setBroadcast(enable);};
309 Error cConnect(
const IPV4Address &ia, tpport_t port);
342 Error connect(
const IPV4Host &host, tpport_t port);
344 Error connect(
const IPV6Address &host, tpport_t port);
377 inline ssize_t
send(
const void *buf,
size_t len)
378 {return ::send(so, (
const char *)buf, len, MSG_NOSIGNAL);}
384 {Socket::endSocket();}
391 inline SOCKET getTransmitter(
void)
395 {
return Socket::setMulticastByFamily(enable, family);}
398 {
return Socket::setTimeToLiveByFamily(ttl, family);};
410 inline ssize_t
transmit(
const char *buffer,
size_t len)
411 {return ::send(so, buffer, len, MSG_DONTWAIT|MSG_NOSIGNAL);}
420 {
return Socket::isPending(Socket::pendingOutput, timeout);};
423 inline Error setRouting(
bool enable)
424 {
return Socket::setRouting(enable);};
426 inline Error setTypeOfService(Tos tos)
427 {
return Socket::setTypeOfService(tos);};
429 inline Error setBroadcast(
bool enable)
430 {
return Socket::setBroadcast(enable);};
468 Error connect(
const IPV4Host &host, tpport_t port);
470 Error connect(
const IPV6Host &host, tpport_t port);
480 {
return Socket::isPending(Socket::pendingInput, timeout);};
486 {Socket::endSocket();}
488 inline SOCKET getReceiver(
void)
const
491 inline Error setRouting(
bool enable)
492 {
return Socket::setRouting(enable);}
495 {
return Socket::setMulticastByFamily(enable, family);}
497 inline Error
join(
const IPV4Multicast &ia)
498 {
return Socket::join(ia);}
501 inline Error
join(
const IPV6Multicast &ia)
502 {
return Socket::join(ia);}
505 inline Error drop(
const IPV4Multicast &ia)
506 {
return Socket::drop(ia);}
509 inline Error drop(
const IPV6Multicast &ia)
510 {
return Socket::drop(ia);}
522 {return ::recv(so, (
char *)buf, len, 0);};
531 {
return Socket::isPending(Socket::pendingInput, timeout);};
bool isOutputReady(unsigned long timeout=0l)
See if output queue is empty for sending more packets.
The broadcast address object is used to store the broadcast address for a specific subnet...
bool isInputReady(timeout_t timeout=ucommon::Timer::inf)
See if input queue has data packets available.
ssize_t receive(void *buf, size_t len)
Receive a data packet from the connected peer host.
UDP duplex connections impliment a bi-directional point-to-point UDP session between two peer hosts...
A specialization of IPV4Address that provides address validation for multicast addresses.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Representing half of a two-way UDP connection, the UDP transmitter can broadcast data to another sele...
void endReceiver(void)
End receiver.
Error connect(const IPV4Host &host, tpport_t port)
Associate this socket with a specified peer host.
The network name and address objects are all derived from a common IPV4Address base class...
Representing a UDP socket used for subnet broadcasts, this class provides an alternate binding and se...
Socket::Error join(const IPV4Multicast &ia, int InterfaceIndex)
join a multicast group on a particular interface
The network name and address objects are all derived from a common IPV6Address base class...
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
ssize_t send(const void *buf, size_t len)
Transmit "send" to use "connected" send rather than sendto.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Network addresses and sockets related classes.
Error setLoopback(bool enable)
Set the loopback.
Common C++ generic string class.
Error setMulticast(bool enable)
Set the multicast.
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
Error setTimeToLive(char ttl)
Set time to live.
ssize_t transmit(const char *buffer, size_t len)
Transmit "send" to use "connected" send rather than sendto.
Error disconnect(void)
Disassociate this socket from any host connection.
A specialization of IPV6Address that provides address validation for multicast addresses.
unsigned long timeout_t
Typedef for millisecond timer values.
Representing half of a two-way UDP connection, the UDP receiver can receive data from another peer ho...
bool isPendingReceive(timeout_t timeout)
Check for pending data.
void endTransmitter(void)
Stop transmitter.
void setPeer(const IPV4Host &host, tpport_t port)
set the peer address to send message packets to.