<p>Kevin Harwell <strong>posted comments</strong> on this change.</p><p><a href="https://gerrit.asterisk.org/8691">View Change</a></p><p>Patch set 5:</p><p>(7 comments)</p><ul style="list-style: none; padding-left: 20px;"><li><p><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py">File lib/python/asterisk/utils_socket.py:</a></p><ul style="list-style: none; padding-left: 20px;"><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@190">Patch Set #5, Line 190:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;"> for attempt in range(attempts):<br> p = get_unused_os_port(host, port, socktype, family)<br><br> if p != 0 and not self.is_reserved(p, socktype, family):<br> res.append(p)<br> break<br><br> if port: return []<br> else:<br> raise PortError(socktype, family, attempts)<br></pre></blockquote></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">I'm not sure this is correct. It looks like it will continuously try to get</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">The goal of this function is to check the availability of given ports, or if any port is 0 then it attempts to retrieve a valid one from the OS.</p><p style="white-space: pre-wrap; word-wrap: break-word;">If the port is 0 then this will try "attempt" times to get a free port from the OS and one not already reserved.</p><p style="white-space: pre-wrap; word-wrap: break-word;">What the "if port: return []" does here is short circuit the "attempts" if a port was specified (non 0) since you are correct we only want to check once in that case.</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@215">Patch Set #5, Line 215:</a> <code style="font-family:monospace,monospace">number(s)</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">Looks like this should be just for a single port. Doesn't check to see if i</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Originally this was going to be passed an array, but it complicated things for current use, so I dropped it. I just noticed I left out the 'span' arg as well.</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@222">Patch Set #5, Line 222:</a> <code style="font-family:monospace,monospace"> empty list.</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">Is this true? Seems like we throw an exception if we cannot get ports (or </blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Kinda. If passed a port and that port is not available or any of its spanned ports then an empty list is returned (only the single check is done)</p><p style="white-space: pre-wrap; word-wrap: break-word;">If port is initially 0 then "attempts" are tried to find a free port +/- its spanned ports. Once found those are returned, otherwise an exception is thrown.</p><p style="white-space: pre-wrap; word-wrap: break-word;">I will mention that to make it more clear.</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@228">Patch Set #5, Line 228:</a> <code style="font-family:monospace,monospace"> return self.get_avail(host, range(port, port + span + step,</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">This grabs an excess port if span > 0. If span = 4:</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Correct. I was thinking span would represent the number of extra ports *not* including the given port. As in give me a port plus "span" number of ports. </p><p style="white-space: pre-wrap; word-wrap: break-word;">If that seems counterintuitive or I need to rename the parameter (if that makes more sense) then I can change it. </p><p style="white-space: pre-wrap; word-wrap: break-word;">I guess too I could make it so a given span of 0 becomes 1, so things would even out for the inclusive way. Thoughts?</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@233">Patch Set #5, Line 233:</a> <code style="font-family:monospace,monospace"> ports = self.get_avail(host, range(port[0] + 1, port[0] + span +</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">I think this grabs excess ports. Example:</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Same reasoning as the other one (above). I was thinking span would represent the number of extra ports *not* including the given port. As in give me a port plus "span" number of ports.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Seems like that is more the expected behavior, so I'm leaning toward changing it.</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@233">Patch Set #5, Line 233:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;">range(port[0] + 1, port[0] + span +<br> step, step)<br></pre></blockquote></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">This is not returning what I would expect if span is 0. If I use a port of </blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">If given a port of '4' this code path would not be chosen, but instead the one just above it would - 'if port != 0: ....'</p></li><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/8691/5/lib/python/asterisk/utils_socket.py@238">Patch Set #5, Line 238:</a> <code style="font-family:monospace,monospace"> PortError(socktype, family, attempts)</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">Do you not need to 'raise PortError(...)'?</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">If searching for an available port and its 'spans' and nothing available can be found in "attempts" tries then we thrown an exception.</p><p style="white-space: pre-wrap; word-wrap: break-word;">(unless I misunderstand your question)</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.asterisk.org/8691">change 8691</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8691"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: comment </div>
<div style="display:none"> Gerrit-Change-Id: I3da461123afc30e1f5ca12e65d289eaa42d6de00 </div>
<div style="display:none"> Gerrit-Change-Number: 8691 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Wed, 18 Apr 2018 22:35:48 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>