Skip to content

Commit

Permalink
Refactoring: Introduce extension NetNameResolver class>>#addressForSo…
Browse files Browse the repository at this point in the history
…cketPath: and use it in ZnNetworkingUtils>>#unixSocketOnFile:
  • Loading branch information
Sven Van Caekenberghe committed Sep 5, 2023
1 parent b772d56 commit a6f7fa3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*Zinc-HTTP-UnixSocket
addressForSocketPath: socketPath
"Resolve a socketPath, a Unix Domain Socket, to a SocketAddress"

| addressSize socketAddress |
self initializeNetwork.
self primGetAddressInfoHost: '' service: socketPath flags: 0 family: 1 type: 0 protocol: 0.
addressSize := self primGetAddressInfoSize.
socketAddress := SocketAddress new: addressSize withAll: 0.
self primGetAddressInfoResult: socketAddress.
^ socketAddress
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "NetNameResolver"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
socketStreamToUnixSocketFile: socketFile
| ipcSocket |
ipcSocket := self unixSocketOnFile: socketFile.
^ ZnNetworkingUtils socketStreamOn: ipcSocket.
^ self socketStreamOn: ipcSocket
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
*Zinc-HTTP-UnixSocket
unixSocketOnFile: socketFile
| addressSize socketAddress ipcSocket |
| socketAddress ipcSocket |
socketFile exists ifFalse: [
ZnMissingUnixSocket new file: socketFile; signal ].

NetNameResolver initializeNetwork.
NetNameResolver
primGetAddressInfoHost: ''
service: socketFile fullName
flags: 0
family: 1
type: 0
protocol: 0.
addressSize := NetNameResolver primGetAddressInfoSize.
socketAddress := SocketAddress new: addressSize withAll: 0.
NetNameResolver primGetAddressInfoResult: socketAddress.

socketAddress := NetNameResolver addressForSocketPath: socketFile fullName.
ipcSocket := Socket newIPC.
ipcSocket ifNil: [
ZnCannotCreateUnixSocket new file: socketFile; signal ].
ZnCannotCreateUnixSocket new file: socketFile; signal ].
ipcSocket connectTo: socketAddress.
ipcSocket isConnected ifFalse: [
ZnCannotConnectUnixSocket new file: socketFile; signal ].
ZnCannotConnectUnixSocket new file: socketFile; signal ].
^ ipcSocket

0 comments on commit a6f7fa3

Please sign in to comment.