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