From 8621717f4c5055b6549d3010227ae10f1693742d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 19 Apr 2012 09:18:54 +0200 Subject: [PATCH] Set SO_REUSEADDR for listeners. --- base/tcpsocket.cpp | 6 +++++- icinga/icingaapplication.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base/tcpsocket.cpp b/base/tcpsocket.cpp index dc23176ca..1d8b6dcba 100644 --- a/base/tcpsocket.cpp +++ b/base/tcpsocket.cpp @@ -29,8 +29,12 @@ void TCPSocket::Bind(unsigned short port) void TCPSocket::Bind(const char *hostname, unsigned short port) { - sockaddr_in sin; +#ifndef _WIN32 + const int optTrue = 1; + setsockopt(GetFD(), SOL_SOCKET, SO_REUSEADDR, (char *)&optTrue, sizeof(optTrue)); +#endif /* _WIN32 */ + sockaddr_in sin; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = hostname ? inet_addr(hostname) : htonl(INADDR_ANY); diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index a84023654..235d44292 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -67,7 +67,7 @@ int IcingaApplication::Main(const vector& args) m_TestEndpoint->RegisterMethodSource("test"); m_TestTimer = make_shared(); - m_TestTimer->SetInterval(5); + m_TestTimer->SetInterval(1); m_TestTimer->OnTimerExpired += bind_weak(&IcingaApplication::TestTimerHandler, shared_from_this()); m_TestTimer->Start(); @@ -84,7 +84,7 @@ int IcingaApplication::TestTimerHandler(const TimerEventArgs& tea) request.SetVersion("2.0"); request.SetMethod("test"); - for (int i = 0; i < 1000; i++) + for (int i = 0; i < 10000; i++) m_EndpointManager->SendMulticastRequest(m_TestEndpoint, request); return 0;