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);}
105 Socket::address peer;
118 UDPSocket(
const char *name, Family family = IPV4);
144 {
return Socket::setLoopbackByFamily(enable, family);}
150 {
return Socket::setMulticastByFamily(enable, family);}
156 {
return Socket::setTimeToLiveByFamily(ttl, family);}
168 void setPeer(
const IPV4Host &host, tpport_t port);
169 void connect(
const IPV4Host &host, tpport_t port);
171 void setPeer(
const IPV6Host &host, tpport_t port);
172 void connect(
const IPV6Host &host, tpport_t port);
182 Socket::Error getInterfaceIndex(
const char *ethX,
int& InterfaceIndex);
193 Socket::Error join(
const IPV4Multicast &ia,
int InterfaceIndex);
202 ssize_t send(
const void *buf,
size_t len);
212 ssize_t receive(
void *buf,
size_t len,
bool reply =
false);
224 IPV4Host getIPV4Peer(tpport_t *port = NULL);
225 inline IPV4Host getPeer(tpport_t *port)
226 {
return getIPV4Peer(port);}
229 IPV6Host getIPV6Peer(tpport_t *port = NULL);
239 inline ssize_t
peek(
void *buf,
size_t len)
240 {return ::recv(so, (
char *)buf, len, MSG_PEEK);}
245 void setPeer(
const char *service);
246 void connect(
const char *service);
252 Error disconnect(
void);
266 void setPeer(
const IPV4Host &ia, tpport_t port);
268 Error setBroadcast(
bool enable)
269 {
return Socket::setBroadcast(enable);}
307 Error cConnect(
const IPV4Address &ia, tpport_t port);
345 Error connect(
const IPV4Host &host, tpport_t port);
347 Error connect(
const IPV6Address &host, tpport_t port);
380 inline ssize_t
send(
const void *buf,
size_t len)
381 {return ::send(so, (
const char *)buf, len, MSG_NOSIGNAL);}
387 {Socket::endSocket();}
394 inline SOCKET getTransmitter(
void)
397 inline Error setMulticast(
bool enable)
398 {
return Socket::setMulticastByFamily(enable, family);}
400 inline Error setTimeToLive(
unsigned char ttl)
401 {
return Socket::setTimeToLiveByFamily(ttl, family);}
413 inline ssize_t
transmit(
const char *buffer,
size_t len)
414 {return ::send(so, buffer, len, MSG_DONTWAIT|MSG_NOSIGNAL);}
423 {
return Socket::isPending(Socket::pendingOutput, timeout);}
426 inline Error setRouting(
bool enable)
427 {
return Socket::setRouting(enable);}
429 inline Error setTypeOfService(Tos tos)
430 {
return Socket::setTypeOfService(tos);}
432 inline Error setBroadcast(
bool enable)
433 {
return Socket::setBroadcast(enable);}
472 Error connect(
const IPV4Host &host, tpport_t port);
474 Error connect(
const IPV6Host &host, tpport_t port);
484 {
return Socket::isPending(Socket::pendingInput, timeout);}
490 {Socket::endSocket();}
492 inline SOCKET getReceiver(
void)
const
495 inline Error setRouting(
bool enable)
496 {
return Socket::setRouting(enable);}
498 inline Error setMulticast(
bool enable)
499 {
return Socket::setMulticastByFamily(enable, family);}
502 {
return Socket::join(ia);}
504 inline Error join(
const IPV4Multicast &ia)
505 {
return Socket::join(ia);}
508 inline Error join(
const IPV6Multicast &ia)
509 {
return Socket::join(ia);}
512 inline Error drop(
const IPV4Multicast &ia)
513 {
return Socket::drop(ia);}
516 inline Error drop(
const IPV6Multicast &ia)
517 {
return Socket::drop(ia);}
529 {return ::recv(so, (
char *)buf, len, 0);}
538 {
return Socket::isPending(Socket::pendingInput, timeout);}
577 Error connect(
const IPV4Host &host, tpport_t port);
579 Error connect(
const IPV6Host &host, tpport_t port);
588 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.
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...
Network addresses and sockets related classes.
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...
A generic socket address class.
unsigned long timeout_t
Typedef for millisecond timer values.
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...