Does anybody have an idea of how to re-route Socket>>initialize: towards a primitive that actually exists?
'From Pharo1.3 of 16 June 2011 [Latest update: #13315] on 4 July 2014 at 3:20:20 pm'!
!TcpListener methodsFor: '*systemd' stamp: 'nl 07/04/2014 15:17'!
haveSystemdAssignedPort
"LISTEN_FDS is set by systemd if the process/pharo-vm is started via port activation"
^ (self primEnvironmentAtSymbol: 'LISTEN_FDS')
ifNotNilDo: [ :value | value asNumber = 1 ]
ifNil: [ false]! !
!TcpListener methodsFor: '*systemd' stamp: 'nl 07/04/2014 15:18'!
pvtNewListener: backlogSize
"Create a new socket that listens on our port. The backlog is how many simultaneous
connections to accept at the same time
Use the socket assigned by systemd if:
- the command-line port number is equal to the portNumber to be opened
- there is an environment variable LISTEN_FDS with value 1
Otherwise use normal port allocation.
"
| listener |
listener := (self haveSystemdAssignedPort
ifTrue: [ self socketClass newSystemd ]
ifFalse: [ self socketClass newTCP ]).
self socketsToDestroy add: listener.
self
bind: listener
withBacklogSize: backlogSize.
^ listener! !
!TcpListener methodsFor: '*systemd' stamp: 'nl 04/29/2013 14:04'!
primEnvironmentAtSymbol: aSymbol
"Copy-paste from UnixOSProcessPlugin: Answer the value of an environment variable in the external OS process."
<primitive: 'primitiveEnvironmentAtSymbol' module: 'UnixOSProcessPlugin'>
^ nil ! !
!Socket class methodsFor: '*systemd' stamp: 'nl 07/04/2014 15:23'!
newSystemd
"Create a socket assigned by systemd port activation"
| SystemdSocketType |
SystemdSocketType := 2.
self initializeNetwork.
^[ super new initialize: SystemdSocketType ]
repeatWithGCIf: [ :socket | socket isValid not ]! !