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);}
106 Socket::address peer;
119 UDPSocket(
const char *name, Family family = IPV4);
145 {
return Socket::setLoopbackByFamily(enable, family);}
151 {
return Socket::setMulticastByFamily(enable, family);}
157 {
return Socket::setTimeToLiveByFamily(ttl, family);}
169 void setPeer(
const IPV4Host &host, tpport_t port);
170 void connect(
const IPV4Host &host, tpport_t port);
172 void setPeer(
const IPV6Host &host, tpport_t port);
173 void connect(
const IPV6Host &host, tpport_t port);
183 Socket::Error getInterfaceIndex(
const char *ethX,
int& InterfaceIndex);
194 Socket::Error join(
const IPV4Multicast &ia,
int InterfaceIndex);
203 ssize_t send(
const void *buf,
size_t len);
213 ssize_t receive(
void *buf,
size_t len,
bool reply =
false);
225 IPV4Host getIPV4Peer(tpport_t *port = NULL);
226 inline IPV4Host getPeer(tpport_t *port)
227 {
return getIPV4Peer(port);}
230 IPV6Host getIPV6Peer(tpport_t *port = NULL);
240 inline ssize_t
peek(
void *buf,
size_t len)
241 {return ::recv(so, (
char *)buf, (socksize_t)len, MSG_PEEK);}
246 void setPeer(
const char *service);
247 void connect(
const char *service);
253 Error disconnect(
void);
267 void setPeer(
const IPV4Host &ia, tpport_t port);
269 Error setBroadcast(
bool enable)
270 {
return Socket::setBroadcast(enable);}
308 Error cConnect(
const IPV4Address &ia, tpport_t port);
346 Error connect(
const IPV4Host &host, tpport_t port);
348 Error connect(
const IPV6Address &host, tpport_t port);
381 inline ssize_t
send(
const void *buf,
size_t len)
382 {return ::send(so, (
const char *)buf, (socksize_t)len, MSG_NOSIGNAL);}
388 {Socket::endSocket();}
395 inline SOCKET getTransmitter(
void)
398 inline Error setMulticast(
bool enable)
399 {
return Socket::setMulticastByFamily(enable, family);}
401 inline Error setTimeToLive(
unsigned char ttl)
402 {
return Socket::setTimeToLiveByFamily(ttl, family);}
414 inline ssize_t
transmit(
const char *buffer,
size_t len)
415 {return ::send(so, buffer, (socksize_t)len, MSG_DONTWAIT|MSG_NOSIGNAL);}
424 {
return Socket::isPending(Socket::pendingOutput, timeout);}
427 inline Error setRouting(
bool enable)
428 {
return Socket::setRouting(enable);}
430 inline Error setTypeOfService(Tos tos)
431 {
return Socket::setTypeOfService(tos);}
433 inline Error setBroadcast(
bool enable)
434 {
return Socket::setBroadcast(enable);}
473 Error connect(
const IPV4Host &host, tpport_t port);
475 Error connect(
const IPV6Host &host, tpport_t port);
485 {
return Socket::isPending(Socket::pendingInput, timeout);}
491 {Socket::endSocket();}
493 inline SOCKET getReceiver(
void)
const
496 inline Error setRouting(
bool enable)
497 {
return Socket::setRouting(enable);}
499 inline Error setMulticast(
bool enable)
500 {
return Socket::setMulticastByFamily(enable, family);}
503 {
return Socket::join(ia);}
505 inline Error join(
const IPV4Multicast &ia)
506 {
return Socket::join(ia);}
509 inline Error join(
const IPV6Multicast &ia)
510 {
return Socket::join(ia);}
513 inline Error drop(
const IPV4Multicast &ia)
514 {
return Socket::drop(ia);}
517 inline Error drop(
const IPV6Multicast &ia)
518 {
return Socket::drop(ia);}
530 {return ::recv(so, (
char *)buf, (socksize_t)len, 0);}
539 {
return Socket::isPending(Socket::pendingInput, timeout);}
578 Error connect(
const IPV4Host &host, tpport_t port);
580 Error connect(
const IPV6Host &host, tpport_t port);
589 Error disconnect(
void);
ssize_t transmit(const char *buffer, size_t len)
Transmit "send" to use "connected" send rather than sendto.
A specialization of IPV4Address that provides address validation for multicast addresses.
ssize_t receive(void *buf, size_t len)
Receive a data packet from the connected peer host.
A specialization of IPV6Address that provides address validation for multicast addresses.
Representing half of a two-way UDP connection, the UDP receiver can receive data from another peer ho...
bool isInputReady(timeout_t timeout=ucommon::Timer::inf)
See if input queue has data packets available.
Network addresses and sockets related classes.
The broadcast address object is used to store the broadcast address for a specific subnet...
Error setLoopback(bool enable)
Set the loopback.
UDP duplex connections impliment a bi-directional point-to-point UDP session between two peer hosts...
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.
void endReceiver(void)
End receiver.
The network name and address objects are all derived from a common IPV4Address base class...
Common C++ generic string class.
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...
bool isPendingReceive(timeout_t timeout)
Check for pending data.
void endTransmitter(void)
Stop transmitter.
Error setTimeToLive(char ttl)
Set time to live.
The network name and address objects are all derived from a common IPV6Address base class...
Error setMulticast(bool enable)
Set the multicast.
Representing a UDP socket used for subnet broadcasts, this class provides an alternate binding and se...
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
bool isOutputReady(unsigned long timeout=0l)
See if output queue is empty for sending more packets.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
A generic socket address class.