[Cuis-dev] Cuis-dev Digest, Vol 67, Issue 44

Jon Raiford raiford at labware.com
Tue Oct 29 10:58:17 PDT 2024


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.

Jon

From: Cuis-dev <cuis-dev-bounces at lists.cuis.st> on behalf of r. clayton via Cuis-dev <cuis-dev at lists.cuis.st>
Date: Tuesday, October 29, 2024 at 1:46 PM
To: cuis-dev at lists.cuis.st <cuis-dev at lists.cuis.st>
Cc: r. clayton <factotum at rclayton.org>
Subject: Re: [Cuis-dev] Cuis-dev Digest, Vol 67, Issue 44
openPort
"Answer an open port number"
| port socket |

socket := Socket newTCP.
socket listenOn: 0. "gets an ephemeral port"
port := socket localPort.
socket close.
^port.

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?

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).
--
Cuis-dev mailing list
Cuis-dev at lists.cuis.st
https://lists.cuis.st/mailman/listinfo/cuis-dev<https://lists.cuis.st/mailman/listinfo/cuis-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20241029/1bc3b1a7/attachment.htm>


More information about the Cuis-dev mailing list