Set buffer size and non blocking option on reactor.

This commit is contained in:
Pedro Pinto committed 2021-01-08 10:57:03 -05:00
1 parent 1f159aacf0
commit b4eced0cd3
1 file changed
+10 -2
@@ -69,9 +69,14 @@ struct Reactor::UDPMulticastConnection : Reactor::Connection {
my_fd = socket(AF_INET, SOCK_DGRAM, 0);
bts_assert(my_fd >= 0);
// Increase socket buffer size to a generous default
int n = 1024 * 1024;
auto result = setsockopt(my_fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
bts_assert(result == 0);
// Set the reuse flag so multiple processes can bind to this socket
int reuse = 1;
auto result = ::setsockopt(
result = ::setsockopt(
my_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(int));
bts_assert(result == 0);
@@ -87,7 +92,7 @@ struct Reactor::UDPMulticastConnection : Reactor::Connection {
// Join the group
struct ip_mreq group;
group.imr_multiaddr.s_addr = mc_group;
group.imr_multiaddr.s_addr = mc_group;
// Use provided interface if specified, otherwise use any
if (end_point.interface_ip.empty())
group.imr_interface.s_addr = INADDR_ANY;
@@ -108,6 +113,9 @@ struct Reactor::PImpl {
Reactor::Reactor() : me(new PImpl()) {
me->epoll_fd = epoll_create(100);
bts_assert(me->epoll_fd >= 0);
int flags = fcntl(me->epoll_fd, F_GETFL, 0);
auto result = fcntl(me->epoll_fd, F_SETFL, flags | O_NONBLOCK);
bts_assert(result == 0);
}
Reactor::~Reactor() {