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

r. clayton factotum at rclayton.org
Tue Oct 29 10:40:29 PDT 2024


  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).


More information about the Cuis-dev mailing list