From 972283ff66a58987ca7f8416fa29810c507125bb Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Thu, 15 Apr 2010 13:14:53 +0000 Subject: [PATCH] adds possibility to set UDP receive buffer size in config. this can give the server some room for processing SIP messages in load spikes. Obviously that can not help against constant overload though... git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1786 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/SipCtrlInterface.cpp | 11 +++++++++++ core/SipCtrlInterface.h | 1 + core/etc/sems.conf.sample | 28 ++++++++++++++++++++++++++++ core/sip/udp_trsp.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp index 16832565..b41be772 100644 --- a/core/SipCtrlInterface.cpp +++ b/core/SipCtrlInterface.cpp @@ -57,6 +57,7 @@ unsigned int SipCtrlInterface::outbound_port = 0; bool SipCtrlInterface::accept_fr_without_totag = false; int SipCtrlInterface::log_raw_messages = 3; bool SipCtrlInterface::log_parsed_messages = true; +int SipCtrlInterface::udp_rcvbuf = -1; int SipCtrlInterface::load() { @@ -103,6 +104,16 @@ int SipCtrlInterface::load() DBG("log_parsed_messages = %s\n", log_parsed_messages?"yes":"no"); + if (cfg.hasParameter("udp_rcvbuf")) { + unsigned int config_udp_rcvbuf = -1; + if (str2i(cfg.getParameter("udp_rcvbuf"), config_udp_rcvbuf)) { + ERROR("invalid value specified for udp_rcvbuf\n"); + return false; + } + udp_rcvbuf = config_udp_rcvbuf; + DBG("sipctrl: udp_rcvbuf = %d\n", udp_rcvbuf); + } + } else { DBG("assuming SIP default settings.\n"); } diff --git a/core/SipCtrlInterface.h b/core/SipCtrlInterface.h index fe693223..852feaa4 100644 --- a/core/SipCtrlInterface.h +++ b/core/SipCtrlInterface.h @@ -62,6 +62,7 @@ public: static bool log_parsed_messages; static int log_raw_messages; static bool accept_fr_without_totag; + static int udp_rcvbuf; SipCtrlInterface(); ~SipCtrlInterface(){} diff --git a/core/etc/sems.conf.sample b/core/etc/sems.conf.sample index dc7c9fe3..e96fc79a 100644 --- a/core/etc/sems.conf.sample +++ b/core/etc/sems.conf.sample @@ -360,3 +360,31 @@ use_default_signature=yes # default: error # # unhandled_reply_loglevel=info + +############################################################ +# SIP stack settings +# default settings (i.e. leave out) for these should be OK +# for most applications + + +# +# Log raw messages? [no|debug|info|warn|error] +# +# Default: debug +# +#log_raw_messages=no + +# +# Log parsed received messages? [yes|no] +# +# Default: yes +# +#log_parsed_messages=no + +# SIP UDP socket receive buffer size (in bytes) +# +# if not set, system default is used (which usually +# is modest). set sytem wide upper limit with +# e.g. sysctl -w net.core.rmem_max=8388608 +# +# udp_rcvbuf = diff --git a/core/sip/udp_trsp.cpp b/core/sip/udp_trsp.cpp index 795ab613..a5a51e3a 100644 --- a/core/sip/udp_trsp.cpp +++ b/core/sip/udp_trsp.cpp @@ -222,6 +222,30 @@ int udp_trsp::bind(const string& address, unsigned short port) return -1; } + if (SipCtrlInterface::udp_rcvbuf > 0) { + DBG("trying to set SIP UDP socket buffer to %d\n", + SipCtrlInterface::udp_rcvbuf); + if(setsockopt(sd, SOL_SOCKET, SO_RCVBUF, + (void*)&SipCtrlInterface::udp_rcvbuf, + sizeof (SipCtrlInterface::udp_rcvbuf)) == -1) { + WARN("could not set SIP UDP socket buffer: '%s'\n", + strerror(errno)); + } else { + socklen_t optlen; + int set_rcvbuf_size=0; + if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, + &set_rcvbuf_size, &optlen) == -1) { + WARN("could not read back SIP UDP socket buffer length: '%s'\n", + strerror(errno)); + } else { + if (set_rcvbuf_size != SipCtrlInterface::udp_rcvbuf) { + WARN("failed to set SIP UDP RCVBUF size (wanted %d, got %d)\n", + SipCtrlInterface::udp_rcvbuf, set_rcvbuf_size); + } + } + } + } + local_port = port; local_ip = address;