<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Yes, that is certainly a race condition waiting to happen. I believe “open” here is acting as an adjective and not a verb, as in, I’ll answer a port that happens to be open (available) right now. I’m not sure
what the benefit is though. If you just want to listen on a random port that is guaranteed to be available then set the port to zero at the time you call listenOn: and don’t close the port until you are done with it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Cuis-dev <cuis-dev-bounces@lists.cuis.st> on behalf of r. clayton via Cuis-dev <cuis-dev@lists.cuis.st><br>
<b>Date: </b>Tuesday, October 29, 2024 at 1:46</span><span style="font-family:"Arial",sans-serif;color:black"> </span><span style="color:black">PM<br>
<b>To: </b>cuis-dev@lists.cuis.st <cuis-dev@lists.cuis.st><br>
<b>Cc: </b>r. clayton <factotum@rclayton.org><br>
<b>Subject: </b>Re: [Cuis-dev] Cuis-dev Digest, Vol 67, Issue 44<o:p></o:p></span></p>
</div>
<p class="MsoNormal">openPort<br>
"Answer an open port number"<br>
| port socket |<br>
<br>
socket := Socket newTCP.<br>
socket listenOn: 0. "gets an ephemeral port"<br>
port := socket localPort.<br>
socket close.<br>
^port.<br>
<br>
Forgive me for asking a possibly dumb question, but how is this not a race condition waiting to happen? Ports are a system-wide resource (considering ports above 1023). What prevents a process elsewhere on the system, not necessarily within Cuis, from allocating
the port returned by openPort?<br>
<br>
Also, since I'm being picky, "open" is probably not the best choice of words if I'm correctly understanding the code's intention. Despite being in the vernacular, "open" doesn't doesn't necessarily mean "available" or "unallocated." You could argue that "open"
means "unavailable" and "allocated" (consider TCP to make this argument clear).<br>
-- <br>
Cuis-dev mailing list<br>
Cuis-dev@lists.cuis.st<br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>