I wonder if there is a portable way to find out at image startup if a certain tcp/ip port is already in use on this machine.
I'd also like to be able to log an error if a server image is started but cannot use a certain port.
What do others think? What does Instantiations think? Is there some reason to handle things like that because it is the way SST has worked for decades now? Or has this just be overseen?
The great Bob Brodd wrote to me (INST50097):
We currently do not support this setting in VA Smalltalk, but here is how
you can set it. Once you have a handle to the socket, before binding to
it , execute the following snippet of code:
self setSockOpt: (SOREUSEADDR bitInvert) optionValue: true. "Exclusive Use"
You may want to modify the base method SstTcpTransport>>#basicOpenListeningSocket for now my hardcoding the setting of this value for your situation. You just want to avoid setting exclusive use on and reuse address on as well as they are incompatible settings. Here is something you can try out .. see italic part for my addition:
basicOpenListeningSocket
"Open a server socket bound to the address associated with the receiver's endpoint.
Answer an SstError on error."
| socket result |
(socket := configuration socketClass socket: AFINET type: SOCKSTREAM protocol: IP) isSciError
ifTrue: [^SstError for: SstInternalTransportError with: socket].
"Set socket to exclusive use unless reuseAddress is set to true "
( configuration reuseAddress == true )
ifFalse: [ socket setSockOpt: (SOREUSEADDR bitInvert) optionValue: true ].
((configuration reuseAddress == true
and: [(result := socket setSockOpt: SOREUSEADDR optionValue: true) isSciError])
or: [
(result := socket bind: self endpoint address sstTransportAddress) isSciError or: [
configuration allowIncomingConnections
and: [(result := socket listen: configuration listenBacklog) isSciError]]])
ifTrue: [
socket close.
^SstError for: SstInternalTransportError with: result].
^socket