author | Stefan Vogel <sv@exept.de> |
Fri, 20 Mar 2020 13:01:09 +0100 | |
changeset 5469 | d78065ee4cff |
parent 5052 | 82fd57c1de33 |
permissions | -rw-r--r-- |
5052 | 1 |
"{ Encoding: utf8 }" |
2 |
||
100 | 3 |
" |
4 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1164 | 14 |
"{ Package: 'stx:libbasic2' }" |
15 |
||
3463 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
818 | 18 |
SocketAddress variableByteSubclass:#UDSocketAddress |
1164 | 19 |
instanceVariableNames:'' |
488 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
816 | 22 |
category:'OS-Sockets' |
100 | 23 |
! |
24 |
||
25 |
!UDSocketAddress class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
111 | 43 |
Instances of UDSocketAddress represent unix-domain socket names. |
44 |
||
100 | 45 |
ST-80 compatibility class. |
46 |
This may be required when existing code has to be ported to ST/X; |
|
47 |
however, it may not be complete and more protocol may be added in the future. |
|
48 |
The code here was created when public domain code (Manchester) had to |
|
49 |
be ported to ST/X and missing classes/methods were encountered, and code added |
|
50 |
by reasoning 'what the original class could probably do there'. |
|
51 |
||
52 |
This is an additional goody class; therefore: |
|
53 |
||
54 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND |
|
55 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
56 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
57 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE |
|
58 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
59 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
60 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
61 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
62 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
63 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
64 |
SUCH DAMAGE. |
|
65 |
" |
|
66 |
! ! |
|
67 |
||
68 |
!UDSocketAddress class methodsFor:'instance creation'! |
|
69 |
||
1908
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
70 |
allForHostName:hostName serviceName:portNrOrName type:socketTypeSymbol |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
71 |
(hostName notNil and:[hostName ~= 'localhost']) ifTrue:[ |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
72 |
self error:'Only local connections possible with UD sockets'. |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
73 |
^ nil. |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
74 |
]. |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
75 |
|
2165
635929d2fe72
fix #allForHostName:serviceName:type::
Stefan Vogel <sv@exept.de>
parents:
1936
diff
changeset
|
76 |
^ Array with:(self name:portNrOrName). |
1908
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
77 |
! |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
78 |
|
1319
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
79 |
anyHost |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
80 |
"there is nothing like a 'host' for unix domain sockets. |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
81 |
answer an empty address" |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
82 |
|
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
83 |
^ self new |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
84 |
! |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
85 |
|
100 | 86 |
name: pathName |
87 |
^ self new name:pathName |
|
88 |
||
89 |
" |
|
90 |
UDSocketAddress name:'/tmp/aUnixDomainSocket' |
|
91 |
" |
|
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
92 |
! |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
93 |
|
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
94 |
peerName:peerName port:port |
1908
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
95 |
"use #name:" |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
96 |
|
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
97 |
<resource: #obsolete> |
7d5c6c7d805f
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
98 |
self obsoleteMethodWarning:'use name:'. |
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
99 |
^ self name:peerName |
100 | 100 |
! ! |
101 |
||
1164 | 102 |
!UDSocketAddress class methodsFor:'queries'! |
103 |
||
3054
6a30dfee6c5b
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3046
diff
changeset
|
104 |
domain |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
105 |
^ #'AF_UNIX' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
106 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
107 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
108 |
obsoleteDomainSymbol |
1164 | 109 |
^ #unix |
110 |
! |
|
111 |
||
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
112 |
peerNameFromPeer:peer |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
113 |
^ 'localhost' |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
114 |
! |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1228
diff
changeset
|
115 |
|
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
116 |
vwDomainSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
117 |
^ #afUnix |
100 | 118 |
! ! |
119 |
||
1164 | 120 |
!UDSocketAddress methodsFor:'accessing'! |
121 |
||
3046 | 122 |
hostAddress |
123 |
"unix domain sockets are local and do not have a host address" |
|
124 |
||
125 |
^ nil |
|
126 |
! |
|
127 |
||
1164 | 128 |
name |
129 |
^ self stringAt:3 |
|
130 |
! |
|
131 |
||
132 |
name:pathName |
|
3463 | 133 |
self stringAt:3 put:pathName asFilename osNameForFile. |
1319
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
134 |
! |
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
135 |
|
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
136 |
port |
1936 | 137 |
"compatibility with inet sockets" |
138 |
||
139 |
^ self name |
|
140 |
! |
|
1319
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
141 |
|
1936 | 142 |
port:pathName |
143 |
"compatibility with inet sockets" |
|
144 |
||
145 |
self name:pathName |
|
146 |
! |
|
147 |
||
148 |
portOrName |
|
1319
4b9a0784a799
Protocol compatibility: #anyHost, #port
Stefan Vogel <sv@exept.de>
parents:
1262
diff
changeset
|
149 |
^ self name |
1164 | 150 |
! ! |
151 |
||
3516 | 152 |
!UDSocketAddress methodsFor:'comparing'! |
153 |
||
3520 | 154 |
sameHostAddress:aSocketAddress |
3516 | 155 |
"answer true, if myself and aSocketAddress have the same host address |
156 |
(but possibly different ports). |
|
157 |
UnixDomainSockets are always on the same host." |
|
158 |
||
159 |
^ aSocketAddress class == self class |
|
160 |
! ! |
|
161 |
||
1164 | 162 |
!UDSocketAddress methodsFor:'obsolete'! |
100 | 163 |
|
488 | 164 |
address |
3046 | 165 |
<resource: #obsolete> |
488 | 166 |
^ nil |
167 |
! |
|
168 |
||
111 | 169 |
hostName |
3046 | 170 |
<resource: #obsolete> |
1164 | 171 |
^ 'local' |
172 |
! |
|
173 |
||
174 |
hostName:hostOrPathName port:portNrOrName |
|
3046 | 175 |
<resource: #obsolete> |
1164 | 176 |
self name:hostOrPathName |
177 |
! ! |
|
178 |
||
179 |
!UDSocketAddress methodsFor:'printing & storing'! |
|
180 |
||
181 |
printOn:aStream |
|
5052 | 182 |
aStream nextPutAll:self className; |
1164 | 183 |
nextPut:$(; nextPutAll:self name; nextPut:$) |
184 |
||
185 |
" |
|
186 |
(self name:'/tmp/abcde') printString |
|
187 |
" |
|
5052 | 188 |
|
189 |
"Modified: / 28-06-2019 / 09:24:10 / Claus Gittinger" |
|
100 | 190 |
! ! |
191 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
192 |
!UDSocketAddress methodsFor:'testing'! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
193 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
194 |
isLocal |
3987 | 195 |
"answer true, if this address addresses a peer on the same host" |
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
196 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
197 |
^ true |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
198 |
! ! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1319
diff
changeset
|
199 |
|
488 | 200 |
!UDSocketAddress class methodsFor:'documentation'! |
201 |
||
202 |
version |
|
3987 | 203 |
^ '$Header$' |
3054
6a30dfee6c5b
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3046
diff
changeset
|
204 |
! |
6a30dfee6c5b
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3046
diff
changeset
|
205 |
|
6a30dfee6c5b
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3046
diff
changeset
|
206 |
version_CVS |
3987 | 207 |
^ '$Header$' |
488 | 208 |
! ! |
3046 | 209 |