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);}
121 UDPSocket(
const char *name, Family family = IPV4);
146 inline Error setLoopback(
bool enable)
147 {
return Socket::setLoopbackByFamily(enable, family);}
152 inline Error setMulticast(
bool enable)
153 {
return Socket::setMulticastByFamily(enable, family);}
158 inline Error setTimeToLive(
char ttl)
159 {
return Socket::setTimeToLiveByFamily(ttl, family);}
171 void setPeer(
const IPV4Host &host, tpport_t port);
172 void connect(
const IPV4Host &host, tpport_t port);
174 void setPeer(
const IPV6Host &host, tpport_t port);
175 void connect(
const IPV6Host &host, tpport_t port);
185 Socket::Error getInterfaceIndex(
const char *ethX,
int& InterfaceIndex);
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);
227 IPV4Host getIPV4Peer(tpport_t *port = NULL);
228 inline IPV4Host getPeer(tpport_t *port)
229 {
return getIPV4Peer(port);}
232 IPV6Host getIPV6Peer(tpport_t *port = NULL);
242 inline ssize_t peek(
void *buf,
size_t len)
243 {return ::recv(so, (
char *)buf, (socksize_t)len, MSG_PEEK);}
248 void setPeer(
const char *service);
249 void connect(
const char *service);
255 Error disconnect(
void);
269 void setPeer(
const IPV4Host &ia, tpport_t port);
271 Error setBroadcast(
bool enable)
272 {
return Socket::setBroadcast(enable);}
312 Error cConnect(
const IPV4Address &ia, tpport_t port);
352 Error connect(
const IPV4Host &host, tpport_t port);
354 Error connect(
const IPV6Address &host, tpport_t port);
387 inline ssize_t send(
const void *buf,
size_t len)
388 {return ::send(so, (
const char *)buf, (socksize_t)len, MSG_NOSIGNAL);}
393 inline void endTransmitter(
void)
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);}
483 Error connect(
const IPV4Host &host, tpport_t port);
485 Error connect(
const IPV6Host &host, tpport_t port);
495 return Socket::isPending(Socket::pendingInput, timeout);
501 inline void endReceiver(
void)
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);}
540 inline ssize_t receive(
void *buf,
size_t len)
541 {return ::recv(so, (
char *)buf, (socksize_t)len, 0);}
550 return Socket::isPending(Socket::pendingInput, timeout);
593 Error connect(
const IPV4Host &host, tpport_t port);
595 Error connect(
const IPV6Host &host, tpport_t port);
604 Error disconnect(
void);