Add more functions for multicast.

This commit is contained in:
shuxin   zheng 2023-09-20 16:53:15 +08:00
parent fff2bed41b
commit e78c53d659
2 changed files with 52 additions and 0 deletions

View File

@ -81,6 +81,28 @@ public:
bool bind_multicast(const char* addr, const char* iface, int port,
int rw_timeout = -1, unsigned flags = 0);
/**
* bind_multicast 广 TTL
* @param ttl {int} 1--255
* @return {bool}
*/
bool multicast_set_ttl(int ttl);
/**
* bind_multicast 广 IP
* @param iface {const char*}
* @return {bool}
*/
bool multicast_set_if(const char* iface);
/**
* bind_multicast
* @param addr {const char*} 广 IP
* @param iface {const char*} IP
* @return {bool}
*/
bool multicast_drop(const char *addr, const char *iface);
/**
*
* @return {bool}

View File

@ -120,6 +120,36 @@ bool socket_stream::bind_multicast(const char *addr, const char *iface,
return true;
}
bool socket_stream::multicast_set_ttl(int ttl)
{
if (eof_ || stream_ == NULL) {
logger_error("Socket not opened yet");
return false;
}
return acl_multicast_set_ttl(ACL_VSTREAM_SOCK(stream_), ttl) == 0;
}
bool socket_stream::multicast_set_if(const char *iface)
{
if (eof_ || stream_ == NULL) {
logger_error("Socket not opened yet");
return false;
}
return acl_multicast_set_if(ACL_VSTREAM_SOCK(stream_), iface) == 0;
}
bool socket_stream::multicast_drop(const char *addr, const char *iface)
{
if (eof_ || stream_ == NULL) {
logger_error("Socket not opened yet");
return false;
}
return acl_multicast_drop(ACL_VSTREAM_SOCK(stream_), addr, iface) == 0;
}
bool socket_stream::shutdown_read(void)
{
if (stream_ == NULL) {