[Asterisk-code-review] utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT (testsuite[18])
George Joseph
asteriskteam at digium.com
Wed Apr 12 10:48:00 CDT 2023
George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/testsuite/+/20081 )
Change subject: utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT
......................................................................
utils_socket.py: Set SO_REUSEADDR and SO_REUSEPORT
Set SO_REUSEADDR and SO_REUSEPORT for both DGRAM and
STREAM sockets in an effort to reduce port exhaustion.
Change-Id: I913302fe69820ceb7c328fc846cd9af5551c9fdc
---
M lib/python/asterisk/utils_socket.py
1 file changed, 17 insertions(+), 4 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/81/20081/1
diff --git a/lib/python/asterisk/utils_socket.py b/lib/python/asterisk/utils_socket.py
index c8813bd..f52b0a1 100644
--- a/lib/python/asterisk/utils_socket.py
+++ b/lib/python/asterisk/utils_socket.py
@@ -107,16 +107,17 @@
res = 0
s = socket(family, socktype)
try:
- if socktype == SOCK_STREAM:
- s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+ s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+ s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
s.bind((host, port))
res = s.getsockname()[1]
except error as e:
# errno = 98 is 'Port already in use'. However, if any error occurs
# just fail since we probably don't want to bind to it anyway.
- LOGGER.debug("{0}/{1} port '{2}' is in use".format(
- socket_type(socktype), socket_family(family), port))
+ LOGGER.debug(e)
+ LOGGER.debug("{3}: {0}/{1} port '{2}' is in use".format(
+ socket_type(socktype), socket_family(family), port, host))
s.close()
return res
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/20081
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 18
Gerrit-Change-Id: I913302fe69820ceb7c328fc846cd9af5551c9fdc
Gerrit-Change-Number: 20081
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230412/6a20160e/attachment-0001.html>
More information about the asterisk-code-review
mailing list