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 struct sockaddr_in6 ipv6;
109 struct sockaddr_in ipv4;
113 struct sockaddr_in ipv4;
128 UDPSocket(
const char *name, Family family = IPV4);
153 {
return Socket::setLoopbackByFamily(enable, family);}
159 {
return Socket::setMulticastByFamily(enable, family);}
165 {
return Socket::setTimeToLiveByFamily(ttl, family);}
174 void setPeer(
const IPV4Host &host, tpport_t port);
175 void connect(
const IPV4Host &host, tpport_t port);
177 void setPeer(
const IPV6Host &host, tpport_t port);
178 void connect(
const IPV6Host &host, tpport_t port);
188 Socket::Error getInterfaceIndex(
const char *ethX,
int& InterfaceIndex);
198 Socket::Error join(
const IPV4Multicast &ia,
int InterfaceIndex);
207 ssize_t send(
const void *buf,
size_t len);
217 ssize_t receive(
void *buf,
size_t len,
bool reply =
false);
227 IPV4Host getIPV4Peer(tpport_t *port = NULL)
const;
228 inline IPV4Host getPeer(tpport_t *port = NULL)
const
229 {
return getIPV4Peer(port);}
232 IPV6Host getIPV6Peer(tpport_t *port = NULL)
const;
242 inline ssize_t
peek(
void *buf,
size_t len)
243 {return ::recv(so, (
char *)buf, len, MSG_PEEK);};
248 void setPeer(
const char *service);
249 void connect(
const char *service);
255 Error disconnect(
void);
271 Error setBroadcast(
bool enable)
272 {
return Socket::setBroadcast(enable);};
310 Error cConnect(
const IPV4Address &ia, tpport_t port);
343 Error connect(
const IPV4Host &host, tpport_t port);
345 Error connect(
const IPV6Address &host, tpport_t port);
378 inline ssize_t
send(
const void *buf,
size_t len)
379 {return ::send(so, (
const char *)buf, len, MSG_NOSIGNAL);}
385 {Socket::endSocket();}
392 inline SOCKET getTransmitter(
void)
396 {
return Socket::setMulticastByFamily(enable, family);}
399 {
return Socket::setTimeToLiveByFamily(ttl, family);};
411 inline ssize_t
transmit(
const char *buffer,
size_t len)
412 {return ::send(so, buffer, len, MSG_DONTWAIT|MSG_NOSIGNAL);}
421 {
return Socket::isPending(Socket::pendingOutput, timeout);};
424 inline Error setRouting(
bool enable)
425 {
return Socket::setRouting(enable);};
427 inline Error setTypeOfService(Tos tos)
428 {
return Socket::setTypeOfService(tos);};
430 inline Error setBroadcast(
bool enable)
431 {
return Socket::setBroadcast(enable);};
469 Error connect(
const IPV4Host &host, tpport_t port);
471 Error connect(
const IPV6Host &host, tpport_t port);
481 {
return Socket::isPending(Socket::pendingInput, timeout);};
487 {Socket::endSocket();}
489 inline SOCKET getReceiver(
void)
const
492 inline Error setRouting(
bool enable)
493 {
return Socket::setRouting(enable);}
496 {
return Socket::setMulticastByFamily(enable, family);}
498 inline Error
join(
const IPV4Multicast &ia)
499 {
return Socket::join(ia);}
502 inline Error
join(
const IPV6Multicast &ia)
503 {
return Socket::join(ia);}
506 inline Error drop(
const IPV4Multicast &ia)
507 {
return Socket::drop(ia);}
510 inline Error drop(
const IPV6Multicast &ia)
511 {
return Socket::drop(ia);}
523 {return ::recv(so, (
char *)buf, len, 0);};
532 {
return Socket::isPending(Socket::pendingInput, timeout);};
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.
Common C++ generic string class.
Representing a UDP socket used for subnet broadcasts, this class provides an alternate binding and se...
bool isPendingReceive(timeout_t timeout)
Check for pending data.
void endTransmitter(void)
Stop transmitter.
A specialization of IPV4Address that provides address validation for multicast addresses.
void endReceiver(void)
End receiver.
Network addresses and sockets related classes.
A specialization of IPV6Address that provides address validation for multicast addresses.
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
ssize_t send(const void *buf, size_t len)
Transmit "send" to use "connected" send rather than sendto.
The broadcast address object is used to store the broadcast address for a specific subnet...
Representing half of a two-way UDP connection, the UDP receiver can receive data from another peer ho...
Error setLoopback(bool enable)
Set the loopback.
Error setMulticast(bool enable)
Set the multicast.
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.
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...
unsigned long timeout_t
Typedef for millisecond timer values.
Socket::Error join(const IPV4Multicast &ia, int InterfaceIndex)
join a multicast group on a particular interface
This object is used to hold the actual and valid internet address of a specific host machine that wil...
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
The network name and address objects are all derived from a common IPV6Address base class...
void setPeer(const IPV4Host &host, tpport_t port)
set the peer address to send message packets to.
bool isOutputReady(unsigned long timeout=0l)
See if output queue is empty for sending more packets.
UDP duplex connections impliment a bi-directional point-to-point UDP session between two peer hosts...
Representing half of a two-way UDP connection, the UDP transmitter can broadcast data to another sele...
Error setTimeToLive(char ttl)
Set time to live.
This object is used to hold the actual and valid internet address of a specific host machine that wil...