-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from JurajKubelka/master
Add support for Unix Domain Sockets
- Loading branch information
Showing
33 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"separateMethodMetaAndSource" : false, | ||
"noMethodMetaData" : true, | ||
"useCypressPropertiesFile" : true | ||
} |
7 changes: 7 additions & 0 deletions
7
repository/Zinc-HTTP-UnixSocket.package/Socket.extension/class/newIPC.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*Zinc-HTTP-UnixSocket | ||
newIPC | ||
"Create a socket and initialise it for IPC aka Unix domain." | ||
|
||
self initializeNetwork. | ||
^ [ super new initialize: TCPSocketType withDomain: 1 ] | ||
repeatWithGCIf: [ :socket | socket isValid not ] |
28 changes: 28 additions & 0 deletions
28
repository/Zinc-HTTP-UnixSocket.package/Socket.extension/instance/initialize.withDomain..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
*Zinc-HTTP-UnixSocket | ||
initialize: socketType withDomain: socketDomain | ||
"Initialize a new socket handle. If socket creation fails, socketHandle will be set to nil." | ||
|
||
| semaIndex readSemaIndex writeSemaIndex | | ||
socketHandle ifNotNil: [^Error signal: 'The socket is already bound']. | ||
semaphore := Semaphore new. | ||
readSemaphore := Semaphore new. | ||
writeSemaphore := Semaphore new. | ||
semaIndex := Smalltalk registerExternalObject: semaphore. | ||
readSemaIndex := Smalltalk registerExternalObject: readSemaphore. | ||
writeSemaIndex := Smalltalk registerExternalObject: writeSemaphore. | ||
socketHandle := self | ||
primSocketCreateNetwork: socketDomain | ||
type: socketType | ||
receiveBufferSize: 8000 | ||
sendBufSize: 8000 | ||
semaIndex: semaIndex | ||
readSemaIndex: readSemaIndex | ||
writeSemaIndex: writeSemaIndex. | ||
socketHandle | ||
ifNil: [ | ||
"socket creation failed" | ||
Smalltalk unregisterExternalObject: semaphore. | ||
Smalltalk unregisterExternalObject: readSemaphore. | ||
Smalltalk unregisterExternalObject: writeSemaphore. | ||
readSemaphore := writeSemaphore := semaphore := nil ] | ||
ifNotNil: [ self register ] |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/Socket.extension/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name" : "Socket" | ||
} |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotConnectUnixSocket.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ZnCannotConnectUnixSocket is signalled when a Unix Domain Socket connection should be established but was not. | ||
|
||
Part of Zinc HTTP Components. |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotConnectUnixSocket.class/instance/file..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file: anObject | ||
file := anObject |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotConnectUnixSocket.class/instance/file.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file | ||
^ file |
4 changes: 4 additions & 0 deletions
4
...tory/Zinc-HTTP-UnixSocket.package/ZnCannotConnectUnixSocket.class/instance/messageText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
messageText | ||
^ super messageText | ||
ifEmpty: [ self file ifNotNil: [ self file fullName ] ifNil: [ '' ] ] |
13 changes: 13 additions & 0 deletions
13
repository/Zinc-HTTP-UnixSocket.package/ZnCannotConnectUnixSocket.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "<historical>", | ||
"super" : "Error", | ||
"category" : "Zinc-HTTP-UnixSocket-Exceptions", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"file" | ||
], | ||
"name" : "ZnCannotConnectUnixSocket", | ||
"type" : "normal" | ||
} |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotCreateUnixSocket.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ZnCannotCreateUnixSocket is signalled when a Unix Domain Socket should be instantiated but was not. | ||
|
||
Part of Zinc HTTP Components. |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotCreateUnixSocket.class/instance/file..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file: anObject | ||
file := anObject |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnCannotCreateUnixSocket.class/instance/file.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file | ||
^ file |
4 changes: 4 additions & 0 deletions
4
...itory/Zinc-HTTP-UnixSocket.package/ZnCannotCreateUnixSocket.class/instance/messageText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
messageText | ||
^ super messageText | ||
ifEmpty: [ self file ifNotNil: [ self file fullName ] ifNil: [ '' ] ] |
13 changes: 13 additions & 0 deletions
13
repository/Zinc-HTTP-UnixSocket.package/ZnCannotCreateUnixSocket.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "<historical>", | ||
"super" : "Error", | ||
"category" : "Zinc-HTTP-UnixSocket-Exceptions", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"file" | ||
], | ||
"name" : "ZnCannotCreateUnixSocket", | ||
"type" : "normal" | ||
} |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnMissingUnixSocket.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ZnMissingUnixSocket is signalled when a Unix Domain Socket file does not exist but should exist. | ||
|
||
Part of Zinc HTTP Components. |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnMissingUnixSocket.class/instance/file..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file: anObject | ||
file := anObject |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnMissingUnixSocket.class/instance/file.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
file | ||
^ file |
4 changes: 4 additions & 0 deletions
4
repository/Zinc-HTTP-UnixSocket.package/ZnMissingUnixSocket.class/instance/messageText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
messageText | ||
^ super messageText | ||
ifEmpty: [ self file ifNotNil: [ self file fullName ] ifNil: [ '' ] ] |
13 changes: 13 additions & 0 deletions
13
repository/Zinc-HTTP-UnixSocket.package/ZnMissingUnixSocket.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "<historical>", | ||
"super" : "Error", | ||
"category" : "Zinc-HTTP-UnixSocket-Exceptions", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"file" | ||
], | ||
"name" : "ZnMissingUnixSocket", | ||
"type" : "normal" | ||
} |
4 changes: 4 additions & 0 deletions
4
...TTP-UnixSocket.package/ZnNetworkingUtils.extension/class/socketStreamToUnixSocketFile..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*Zinc-HTTP-UnixSocket | ||
socketStreamToUnixSocketFile: socketFile | ||
^ self default | ||
socketStreamToUnixSocketFile: socketFile |
5 changes: 5 additions & 0 deletions
5
...-UnixSocket.package/ZnNetworkingUtils.extension/instance/socketStreamToUnixSocketFile..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*Zinc-HTTP-UnixSocket | ||
socketStreamToUnixSocketFile: socketFile | ||
| ipcSocket | | ||
ipcSocket := self unixSocketOnFile: socketFile. | ||
^ ZnNetworkingUtils socketStreamOn: ipcSocket. |
24 changes: 24 additions & 0 deletions
24
...ry/Zinc-HTTP-UnixSocket.package/ZnNetworkingUtils.extension/instance/unixSocketOnFile..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
*Zinc-HTTP-UnixSocket | ||
unixSocketOnFile: socketFile | ||
| addressSize socketAddress ipcSocket | | ||
socketFile exists ifFalse: [ | ||
ZnMissingUnixSocket new file: socketFile; signal ]. | ||
|
||
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. | ||
|
||
ipcSocket := Socket newIPC. | ||
ipcSocket ifNil: [ | ||
ZnCannotCreateUnixSocket new file: socketFile; signal ]. | ||
ipcSocket connectTo: socketAddress. | ||
ipcSocket isConnected ifFalse: [ | ||
ZnCannotConnectUnixSocket new file: socketFile; signal ]. | ||
^ ipcSocket |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnNetworkingUtils.extension/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name" : "ZnNetworkingUtils" | ||
} |
14 changes: 14 additions & 0 deletions
14
repository/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
I am ZnClient. | ||
I am ZnUnixSocketClient, an object to build, execute, and process HTTP client request over Unix Domain Sockets. | ||
|
||
Simplest possible invocation: | ||
|
||
ZnUnixSocketClient new | ||
unixSocket: '/var/run/docker.sock'; | ||
get: 'http://localhost/v1.43/containers/json'. | ||
|
||
It is equivalent to the following cURL command: | ||
|
||
curl --unix-socket /var/run/docker.sock http://localhost/v1.43/containers/json | ||
|
||
Part of Zinc HTTP Components. |
5 changes: 5 additions & 0 deletions
5
...sitory/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/instance/newConnectionTo..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
private | ||
newConnectionTo: url | ||
self unixSocket | ||
ifNil: [ super newConnectionTo: url ] | ||
ifNotNil: [ :socketPath | self newConnectionToUnixSocketFile: socketPath asFileReference ] |
9 changes: 9 additions & 0 deletions
9
...TP-UnixSocket.package/ZnUnixSocketClient.class/instance/newConnectionToUnixSocketFile..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
private | ||
newConnectionToUnixSocketFile: socketFile | ||
| initialMilliseconds | | ||
self signalHTTPProgress: 'Connecting to ', socketFile asString. | ||
initialMilliseconds := Time millisecondClockValue. | ||
(connection notNil and: [ connection isConnected ]) | ||
ifTrue: [ connection close ]. | ||
connection := ZnNetworkingUtils socketStreamToUnixSocketFile: socketFile. | ||
self logConnectionEstablishedTo: socketFile asZnUrl started: initialMilliseconds |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/instance/unixSocket..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
unixSocket: socketPath | ||
self optionAt: #unixSocket put: socketPath |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/instance/unixSocket.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
unixSocket | ||
^ self optionAt: #unixSocket ifAbsent: [ nil ] |
11 changes: 11 additions & 0 deletions
11
repository/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "<historical>", | ||
"super" : "ZnClient", | ||
"category" : "Zinc-HTTP-UnixSocket-Client-Server", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "ZnUnixSocketClient", | ||
"type" : "normal" | ||
} |
3 changes: 3 additions & 0 deletions
3
repository/Zinc-HTTP-UnixSocket.package/monticello.meta/categories.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SystemOrganization addCategory: #'Zinc-HTTP-UnixSocket'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-UnixSocket-Client-Server'! | ||
SystemOrganization addCategory: #'Zinc-HTTP-UnixSocket-Exceptions'! |
Empty file.
1 change: 1 addition & 0 deletions
1
repository/Zinc-HTTP-UnixSocket.package/monticello.meta/package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(name 'Zinc-HTTP-UnixSocket') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ } |