author | Claus Gittinger <cg@exept.de> |
Tue, 25 Jun 2019 14:28:51 +0200 | |
changeset 5050 | 44fa8672d102 |
parent 5001 | 11cbbbcbc87e |
child 5196 | f2b4c109c24f |
permissions | -rw-r--r-- |
4795 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
4 | 4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
42 | 5 |
All Rights Reserved |
0 | 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 |
" |
|
888 | 14 |
"{ Package: 'stx:libbasic2' }" |
15 |
||
3462 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
63 | 18 |
NonPositionableExternalStream subclass:#Socket |
4234 | 19 |
instanceVariableNames:'domain socketType protocol port peer peerName listening' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
20 |
classVariableNames:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
21 |
poolDictionaries:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
22 |
category:'Streams-External' |
0 | 23 |
! |
24 |
||
126 | 25 |
!Socket primitiveDefinitions! |
26 |
%{ |
|
1009 | 27 |
/* #define DGRAM_DEBUG /* */ |
28 |
||
3590 | 29 |
#ifdef __MINGW__ |
30 |
# include <stdio.h> |
|
31 |
#endif |
|
1343 | 32 |
#include "stxOSDefs.h" |
126 | 33 |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
34 |
#ifdef __win32__ |
3123 | 35 |
//#define DEBUG 1 |
2818 | 36 |
/* this is to catch uses of those - there should be none */ |
1503 | 37 |
# undef __BEGIN_INTERRUPTABLE__ |
38 |
# undef __END_INTERRUPTABLE__ |
|
2818 | 39 |
# ifdef __TCC__ |
40 |
# define __BEGIN_INTERRUPTABLE__ xxxx |
|
41 |
# define __END_INTERRUPTABLE__ yyyy |
|
42 |
# else |
|
43 |
# define __BEGIN_INTERRUPTABLE__ .. |
|
44 |
# define __END_INTERRUPTABLE__ .. |
|
45 |
# endif |
|
1503 | 46 |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
47 |
# define WRAP_STDIO |
2823
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
48 |
// The default is linger until all data is sent in background |
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
49 |
// so the close on the socket is non-blocking |
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
50 |
// linger.onoff=off linger.time= *irrelevant* |
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
51 |
//# define SET_LINGER_WHEN_CREATING_SOCKET |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
52 |
|
3742 | 53 |
# ifdef __xxMINGW__ |
2909 | 54 |
extern HANDLE _get_osfhandle(); |
1845 | 55 |
# endif |
56 |
||
3620 | 57 |
# if defined(__BORLANDC__) |
58 |
// not defined in borland headers |
|
59 |
typedef unsigned int socklen_t; |
|
60 |
# endif |
|
61 |
||
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
62 |
# if 0 && (defined( __BORLANDC__ ) || defined( __MINGW__ )) |
2915 | 63 |
# define SOCKET_FROM_FD(fd) (SOCKET)(_get_osfhandle(fd)) |
2909 | 64 |
# else |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
65 |
# define SOCKET_FROM_FD(fd) (SOCKET)(fd) |
2909 | 66 |
# endif |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
67 |
#else /* not __win32__ */ |
3215 | 68 |
# define SOCKET_FROM_FD(fd) (fd) |
69 |
# define closesocket(sock) close(sock) |
|
70 |
# define SOCKET int |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
71 |
#endif /* ! __win32__ */ |
1503 | 72 |
|
1843
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
73 |
#define SOCKET_FROM_FILE(f) (SOCKET_FROM_FD(fileno(f))) |
5001 | 74 |
#define SOCKET_FROM_FILE_OBJECT(f) (__INST(handleType) == @symbol(socketHandle) ? SOCKET_FROM_FD((INT)(__FILEVal(f))) : SOCKET_FROM_FILE(__FILEVal(f))) |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
75 |
|
3590 | 76 |
#ifndef __MINGW__ |
77 |
# include <stdio.h> |
|
78 |
#endif |
|
126 | 79 |
#include <errno.h> |
80 |
||
1343 | 81 |
#ifdef WANT__TCP_DOT_H |
82 |
# include <netinet/tcp.h> |
|
83 |
#endif |
|
84 |
||
1344 | 85 |
#ifdef WANT__NETDB_DOT_H |
86 |
# include <netdb.h> |
|
1343 | 87 |
#endif |
88 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
89 |
#if defined(TRY_AGAIN) || defined(HOST_NOT_FOUND) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
90 |
# define USE_H_ERRNO |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
91 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
92 |
|
126 | 93 |
/* |
94 |
* on some systems errno is a macro ... check for it here |
|
95 |
*/ |
|
96 |
#ifndef errno |
|
97 |
extern errno; |
|
98 |
#endif |
|
99 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
100 |
#ifdef USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
101 |
# ifndef h_errno |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
102 |
extern h_errno; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
103 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
104 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
105 |
|
126 | 106 |
#ifdef DEBUG |
1839 | 107 |
# define DBGPRINTF(x) { if (__debugging__) console_printf x; } |
108 |
# define DBGFPRINTF(x) { if (__debugging__) console_fprintf x; } |
|
126 | 109 |
#else |
110 |
# define DBGPRINTF(x) /* as nothing */ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
111 |
# define DBGFPRINTF(x) /* as nothing */ |
126 | 112 |
#endif |
113 |
||
1531 | 114 |
#ifndef TRUE |
1535 | 115 |
# define TRUE 1 |
1531 | 116 |
#endif |
117 |
#ifndef FALSE |
|
1535 | 118 |
# define FALSE 0 |
1531 | 119 |
#endif |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
120 |
#ifndef __win32__ |
1531 | 121 |
typedef int BOOL; |
122 |
#endif |
|
123 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
124 |
#ifdef __win32__ |
1843
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
125 |
# undef stdout |
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
126 |
# undef stderr |
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
127 |
# define stdout __win32_stdout() |
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
128 |
# define stderr __win32_stderr() |
8ee90d243b49
closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents:
1842
diff
changeset
|
129 |
#endif |
126 | 130 |
%} |
131 |
! ! |
|
132 |
||
511 | 133 |
!Socket primitiveVariables! |
134 |
%{ |
|
1844 | 135 |
static int __debugging__ = 0; |
511 | 136 |
%} |
137 |
! ! |
|
138 |
||
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
139 |
!Socket primitiveFunctions! |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
140 |
%{ |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
141 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
142 |
static int |
3616 | 143 |
setupBufferParameters(OBJ aDataBuffer, OBJ startIndex, char **p_extPtr, INT *p_offs, size_t *p_objSize) |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
144 |
{ |
3657 | 145 |
char *extPtr = 0; |
146 |
int sIdx = 0, objSize = 0, offs = 0; |
|
147 |
||
148 |
sIdx = 0; |
|
149 |
if (__isSmallInteger(startIndex)) { |
|
150 |
sIdx = __intVal(startIndex) - 1; |
|
151 |
} |
|
152 |
||
153 |
if (__isExternalBytesLike(aDataBuffer)) { |
|
154 |
OBJ sz; |
|
155 |
||
156 |
extPtr = (char *)(__externalBytesAddress(aDataBuffer)); |
|
157 |
sz = __externalBytesSize(aDataBuffer); |
|
158 |
if (__isSmallInteger(sz)) { |
|
159 |
objSize = __intVal(sz); |
|
160 |
} else { |
|
161 |
objSize = 0; /* unknown */ |
|
162 |
} |
|
163 |
offs = sIdx; |
|
164 |
} else { |
|
165 |
OBJ oClass; |
|
166 |
int nInstVars, nInstBytes; |
|
167 |
||
168 |
extPtr = (char *)0; |
|
169 |
oClass = __Class(aDataBuffer); |
|
170 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
171 |
case BYTEARRAY: |
|
172 |
offs = sIdx; |
|
173 |
break; |
|
174 |
case WORDARRAY: |
|
175 |
case SWORDARRAY: |
|
176 |
offs = sIdx * 2; |
|
177 |
break; |
|
178 |
case LONGARRAY: |
|
179 |
case SLONGARRAY: |
|
180 |
offs = sIdx * 4; |
|
181 |
break; |
|
182 |
case LONGLONGARRAY: |
|
183 |
case SLONGLONGARRAY: |
|
184 |
offs = sIdx * 8; |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
185 |
# ifdef __NEED_LONGLONG_ALIGN |
3657 | 186 |
offs += 4; |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
187 |
# endif |
3657 | 188 |
break; |
189 |
case FLOATARRAY: |
|
190 |
offs = sIdx * sizeof(float); |
|
191 |
break; |
|
192 |
case DOUBLEARRAY: |
|
193 |
offs = sIdx * sizeof(double); |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
194 |
# ifdef __NEED_DOUBLE_ALIGN |
3657 | 195 |
offs += 4; |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
196 |
# endif |
3657 | 197 |
break; |
198 |
default: |
|
199 |
*p_objSize = -1; |
|
200 |
return 0; |
|
201 |
} |
|
202 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
203 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
204 |
offs = offs + nInstBytes; |
|
205 |
objSize = __Size(aDataBuffer) - offs; |
|
206 |
} |
|
207 |
*p_extPtr = extPtr; |
|
208 |
*p_objSize = objSize; |
|
209 |
*p_offs = offs; |
|
210 |
return 1; |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
211 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
212 |
%} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
213 |
! ! |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
214 |
|
464 | 215 |
!Socket class methodsFor:'documentation'! |
25 | 216 |
|
31 | 217 |
copyright |
218 |
" |
|
219 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
42 | 220 |
All Rights Reserved |
31 | 221 |
|
222 |
This software is furnished under a license and may be used |
|
223 |
only in accordance with the terms of that license and with the |
|
224 |
inclusion of the above copyright notice. This software may not |
|
225 |
be provided or otherwise made available to, or used by, any |
|
226 |
other person. No title to or ownership of the software is |
|
227 |
hereby transferred. |
|
228 |
" |
|
229 |
! |
|
230 |
||
25 | 231 |
documentation |
232 |
" |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
233 |
This class provides access to sockets for interprocess communication. |
25 | 234 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
235 |
Currently, only IP and UNIX domain sockets are really fully |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
236 |
tested and supported. |
525 | 237 |
Code for appletalk is included, but was never tested ... |
238 |
More may be added in the future. |
|
239 |
(the code is prepared for things like SNA or decNet; |
|
240 |
however, right now, this code is empty and needs a little work. |
|
3989 | 241 |
Implementing those is pretty straightforward, once the address |
525 | 242 |
data structures are known.) |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
243 |
|
28 | 244 |
Due to historic reasons (I started this class, before I got hold of some |
245 |
code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface |
|
3481 | 246 |
which is still supported. |
247 |
This may vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces, |
|
71 | 248 |
together with the bind/listen and accept calls, |
249 |
which are meant to be compatible to ST-80's UnixSocketAccessor interface. |
|
250 |
||
3481 | 251 |
TODO: cleanup historic leftovers, |
4414 | 252 |
change to raise more signals on errors. |
259 | 253 |
|
254 |
[author:] |
|
4414 | 255 |
Claus Gittinger |
48 | 256 |
" |
257 |
! |
|
28 | 258 |
|
48 | 259 |
examples |
260 |
" |
|
28 | 261 |
example (get help info from an nntp server): |
5001 | 262 |
[exBegin] |
263 |
|sock| |
|
264 |
||
265 |
sock := Socket newTCPclientToHost:'smtp.exept.de' port:'smtp'. |
|
266 |
sock isNil ifTrue:[ |
|
267 |
self warn:'no smtp daemon is running'. |
|
268 |
^ self |
|
269 |
]. |
|
270 |
Transcript showCR:sock nextLine. |
|
271 |
||
272 |
sock nextPutAll:'HELO STX socket test'; cr. |
|
273 |
Transcript showCR:sock nextLine. |
|
274 |
sock close |
|
275 |
[exEnd] |
|
209 | 276 |
|
28 | 277 |
|
209 | 278 |
example (connect to finger daemon, get users entry): |
5001 | 279 |
[exBegin] |
280 |
|sock entry| |
|
281 |
||
282 |
sock := Socket newTCPclientToHost:'localhost' port:'finger'. |
|
283 |
sock isNil ifTrue:[ |
|
284 |
self warn:'no finger daemon is running'. |
|
285 |
^ self |
|
286 |
]. |
|
287 |
sock useCRLF:true. |
|
288 |
sock buffered:false. |
|
289 |
sock isNil ifTrue:[ |
|
290 |
Transcript showCR:'cannot connect to local finger daemon' |
|
291 |
] ifFalse:[ |
|
292 |
sock nextPutAll:(OperatingSystem getLoginName). |
|
293 |
sock cr. |
|
294 |
||
295 |
entry := sock nextLine. |
|
296 |
Transcript showCR:entry. |
|
297 |
||
298 |
sock close |
|
299 |
] |
|
300 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
301 |
|
28 | 302 |
example (connect to an ftp server): |
5001 | 303 |
[exBegin] |
304 |
|sock| |
|
305 |
||
306 |
sock := Socket newTCPclientToHost:'www.exept.de' port:'ftp'. |
|
307 |
||
308 |
sock buffered:false. |
|
309 |
Transcript showCR:sock nextLine. |
|
310 |
sock nextPutAll:('USER ' , 'anonymous'); cr. |
|
311 |
Transcript showCR:sock nextLine. |
|
312 |
sock nextPutAll:('PASS ' , 'fooBar'); cr. |
|
313 |
Transcript showCR:sock nextLine. |
|
314 |
sock nextPutAll:'HELP'; cr. |
|
315 |
[ |
|
316 |
|line| |
|
317 |
line := sock nextLine. |
|
318 |
Transcript showCR:line. |
|
319 |
(line at:4) = $- |
|
320 |
] whileTrue. |
|
321 |
sock close. |
|
322 |
||
323 |
'don't know enough of the ftp protocol to continue here ...' |
|
324 |
[exEnd] |
|
28 | 325 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
326 |
|
93 | 327 |
example (connect to an snmp server [UDP]): |
3985 | 328 |
Note: this is not a real connection, only the destination address is |
5001 | 329 |
being fixed. |
330 |
[exBegin] |
|
331 |
|sock port| |
|
332 |
||
333 |
sock := Socket newUDP. |
|
334 |
port := Socket portOfService:'snmp'. |
|
335 |
sock connectTo:'224.1.2.3' port:port. |
|
336 |
sock buffered:false. |
|
337 |
Transcript showCR:'got it'. |
|
338 |
sock close. |
|
339 |
[exEnd] |
|
42 | 340 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
341 |
|
42 | 342 |
example (await connection from a client and read some data): |
5001 | 343 |
[exBegin] |
344 |
|connectSock sock| |
|
345 |
||
346 |
connectSock := Socket newTCPserverAtPort:9998. |
|
347 |
connectSock isNil ifTrue:[ |
|
348 |
Transcript showCR:'socket setup failed.'. |
|
349 |
] ifFalse:[ |
|
350 |
Transcript showCR:'listen ..'. |
|
351 |
(connectSock listenFor:5) ifFalse:[ |
|
352 |
Transcript showCR:'listen failed.'. |
|
353 |
] ifTrue:[ |
|
354 |
Transcript showCR:'wait'. |
|
355 |
connectSock readWait. |
|
356 |
Transcript showCR:'accept'. |
|
357 |
sock := connectSock accept. |
|
358 |
sock isNil ifTrue:[ |
|
359 |
Transcript showCR:'accept failed.'. |
|
360 |
] ifFalse:[ |
|
361 |
sock buffered:false. |
|
362 |
Transcript showCR:'server: got it'. |
|
363 |
'can now do transfer via sock'. |
|
364 |
Transcript showCR:'read'. |
|
365 |
Transcript showCR:('got: ' , sock nextLine). |
|
366 |
||
367 |
Transcript showCR:'close'. |
|
368 |
sock close |
|
369 |
]. |
|
370 |
connectSock close. |
|
371 |
] |
|
372 |
] |
|
373 |
[exEnd] |
|
42 | 374 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
375 |
|
42 | 376 |
example (connect to above server and send some data): |
5001 | 377 |
[exBegin] |
378 |
|sock| |
|
379 |
||
380 |
sock := Socket newTCPclientToHost:'localhost' port:9998. |
|
381 |
sock isNil ifTrue:[ |
|
382 |
Transcript showCR:'nope' |
|
383 |
] ifFalse:[ |
|
384 |
sock buffered:false. |
|
385 |
Transcript showCR:'client: got it'. |
|
386 |
'can now do transfer via sock'. |
|
387 |
Transcript showCR:'sending <hello>'. |
|
388 |
sock nextPutLine:'hello'. |
|
389 |
sock close |
|
390 |
] |
|
391 |
[exEnd] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
392 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
393 |
example: UNIX domain socket (await connection from a client and read some data): |
1009 | 394 |
|
5001 | 395 |
|connectSock sock| |
396 |
||
397 |
'/tmp/ud_socket' asFilename remove. |
|
398 |
connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'. |
|
399 |
connectSock isNil ifTrue:[ |
|
400 |
Transcript showCR:'socket setup failed.'. |
|
401 |
] ifFalse:[ |
|
402 |
Transcript showCR:'listen ..'. |
|
403 |
(connectSock listenFor:5) ifFalse:[ |
|
404 |
Transcript showCR:'listen failed.'. |
|
405 |
] ifTrue:[ |
|
406 |
Transcript showCR:'wait'. |
|
407 |
connectSock buffered:false. |
|
408 |
connectSock readWait. |
|
409 |
Transcript showCR:'accept'. |
|
410 |
sock := connectSock accept. |
|
411 |
sock isNil ifTrue:[ |
|
412 |
Transcript showCR:'accept failed.'. |
|
413 |
] ifFalse:[ |
|
414 |
sock buffered:false. |
|
415 |
Transcript showCR:'server: got it'. |
|
416 |
'can now do transfer via sock'. |
|
417 |
Transcript showCR:'read'. |
|
418 |
Transcript showCR:('got: ' , sock nextLine). |
|
419 |
||
420 |
Transcript showCR:'close'. |
|
421 |
sock close |
|
422 |
]. |
|
423 |
connectSock close. |
|
424 |
] |
|
425 |
] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
426 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
427 |
|
118 | 428 |
example (connect to above server and send some data; |
5001 | 429 |
Notice, this fails, if above server code is executed in the same ST/X image |
430 |
(at least on LINUX), since the OS does not correctly handle |
|
431 |
a connect from within an interrupted accept system call |
|
432 |
On SGI's SVR4, this works ok |
|
433 |
[exBegin] |
|
434 |
|sock| |
|
435 |
||
436 |
sock := Socket newUNIXclientTo:'/tmp/ud_socket'. |
|
437 |
sock isNil ifTrue:[ |
|
438 |
Transcript showCR:'nope' |
|
439 |
] ifFalse:[ |
|
440 |
sock buffered:false. |
|
441 |
Transcript showCR:'client: got it'. |
|
442 |
'can now do transfer via sock'. |
|
443 |
Transcript showCR:'sending <hello>'. |
|
444 |
sock nextPutLine:'hello'. |
|
445 |
sock close |
|
446 |
] |
|
447 |
[exEnd] |
|
1007 | 448 |
|
449 |
||
450 |
example (UDP await packet from a client and read some data): |
|
5001 | 451 |
[exBegin] |
452 |
|udpSock sock addr n dataBuffer| |
|
453 |
||
454 |
udpSock := Socket newUDPserverAtPort:9999. |
|
455 |
udpSock isNil ifTrue:[ |
|
456 |
Transcript showCR:'socket setup failed.'. |
|
457 |
] ifFalse:[ |
|
458 |
Transcript showCR:'wait'. |
|
459 |
udpSock readWait. |
|
460 |
||
461 |
addr := IPSocketAddress new. |
|
462 |
dataBuffer := ByteArray new:1000. |
|
463 |
n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size. |
|
464 |
n > 0 ifTrue:[ |
|
465 |
Transcript showCR:('got: ' , n printString , 'bytes from ' , addr printString). |
|
466 |
Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString). |
|
467 |
] ifFalse:[ |
|
468 |
Transcript showCR:'read failed'. |
|
469 |
]. |
|
470 |
||
471 |
Transcript showCR:'close'. |
|
472 |
udpSock close |
|
473 |
] |
|
474 |
[exEnd] |
|
4738 | 475 |
|
1007 | 476 |
example (connect to above UDP server and send some data; |
5001 | 477 |
[exBegin] |
478 |
|sock| |
|
479 |
||
480 |
sock := Socket newUDP. |
|
481 |
sock isNil ifTrue:[ |
|
482 |
Transcript showCR:'nope' |
|
483 |
] ifFalse:[ |
|
484 |
sock |
|
485 |
sendTo:(IPSocketAddress hostName:'127.0.0.1' port:9999) buffer:'hello world'. |
|
486 |
sock close |
|
487 |
] |
|
488 |
[exEnd] |
|
4738 | 489 |
|
490 |
||
491 |
example (UDP await packet from a client and read some multicast data): |
|
5001 | 492 |
[exBegin] |
493 |
|udpSock sock addr n dataBuffer| |
|
494 |
||
495 |
udpSock := Socket newUDPserverAtPort:9999. |
|
496 |
udpSock isNil ifTrue:[ |
|
497 |
Transcript showCR:'socket setup failed.'. |
|
498 |
] ifFalse:[ |
|
499 |
udpSock setSocketOption:#'IP_ADD_MEMBERSHIP' argument:#[224 1 2 3] argument:#[0 0 0 0]. |
|
500 |
Transcript showCR:'wait'. |
|
501 |
udpSock readWait. |
|
502 |
||
503 |
addr := IPSocketAddress new. |
|
504 |
dataBuffer := ByteArray new:1000. |
|
505 |
n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size. |
|
506 |
n > 0 ifTrue:[ |
|
507 |
Transcript showCR:('got: ' , n printString , 'bytes from ' , addr printString). |
|
508 |
Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString). |
|
509 |
] ifFalse:[ |
|
510 |
Transcript showCR:'read failed'. |
|
511 |
]. |
|
512 |
||
513 |
Transcript showCR:'close'. |
|
514 |
udpSock close |
|
515 |
] |
|
516 |
[exEnd] |
|
4738 | 517 |
|
518 |
example (connect to above UDP server and send some multicast data): |
|
5001 | 519 |
[exBegin] |
520 |
|sock| |
|
521 |
||
522 |
sock := Socket newUDP. |
|
523 |
sock isNil ifTrue:[ |
|
524 |
Transcript showCR:'nope' |
|
525 |
] ifFalse:[ |
|
526 |
sock |
|
527 |
setSocketOption:#'IP_MULTICAST_TTL' argument:3 argument:nil; |
|
528 |
sendTo:(IPSocketAddress hostName:'224.1.2.3' port:9999) buffer:'hello world'. |
|
529 |
sock close |
|
530 |
] |
|
531 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
532 |
|
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
533 |
example: pingWalk (try to ping hosts on the local network) |
2824 | 534 |
Note: it dosen't use ICMP ping, but tries to reache the echo service, |
5001 | 535 |
which is disabled on most OS. |
536 |
[exBegin] |
|
537 |
|myAddress list top hosts walkProcess port| |
|
538 |
||
539 |
myAddress := OperatingSystem getNetworkAddresses |
|
540 |
keysAndValuesSelect:[:eachIFName :eachAddress| |
|
541 |
eachAddress isLocal not |
|
542 |
and:[eachIFName = 'wlan0'] |
|
543 |
]. |
|
544 |
myAddress := myAddress first hostAddress. |
|
545 |
||
546 |
port := Socket portOfService:'echo'. |
|
547 |
port isNil ifTrue:[ |
|
548 |
self error:'dont know echo port'. |
|
549 |
^ self |
|
550 |
]. |
|
551 |
||
552 |
top := StandardSystemView new. |
|
553 |
top label:'PING net walk'. |
|
554 |
||
555 |
list := ScrollableView for:ListView in:top. |
|
556 |
list origin:0.0@0.0 corner:1.0@1.0. |
|
557 |
||
558 |
top openAndWait. |
|
559 |
||
560 |
walkProcess := [ |
|
561 |
|l low hi direction tryHostID dottedName hostName conn addr| |
|
562 |
||
563 |
l := SortedCollection new. |
|
564 |
||
565 |
' only works with type C-net |
|
566 |
the code below could simply do 1 to:254 do:[:hostID } |
|
567 |
but, to probe likely hosts earlier, the probing is done |
|
568 |
ping-pong like around my ip-address (assuming, that other machines |
|
569 |
have numbers around my own)'. |
|
570 |
||
571 |
low := hi := (myAddress at:4). |
|
572 |
direction := 1. |
|
573 |
||
574 |
[low > 0 or:[hi < 255]] whileTrue:[ |
|
575 |
direction > 0 ifTrue:[ |
|
576 |
hi := hi + 1. |
|
577 |
tryHostID := hi. |
|
578 |
direction := -1. |
|
579 |
] ifFalse:[ |
|
580 |
low := low - 1. |
|
581 |
tryHostID := low. |
|
582 |
direction := 1. |
|
583 |
]. |
|
584 |
(tryHostID between:1 and:254) ifTrue:[ |
|
585 |
dottedName := (myAddress at:1) printString |
|
586 |
, '.' , (myAddress at:2) printString |
|
587 |
, '.' , (myAddress at:3) printString |
|
588 |
, '.' , tryHostID printString. |
|
589 |
||
590 |
top label:'PING net walk - trying ' , dottedName. |
|
591 |
||
592 |
top windowGroup withCursor:Cursor wait do:[ |
|
593 |
conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000. |
|
594 |
conn notNil ifTrue:[ |
|
595 |
addr := Socket ipAddressOfHost:dottedName. |
|
596 |
hostName := Socket hostWithIpAddress:addr. |
|
597 |
hostName isNil ifTrue:[ |
|
598 |
hostName :='?' |
|
599 |
]. |
|
600 |
l add:(dottedName paddedTo:15 with:Character space) |
|
601 |
, ' ' |
|
602 |
, (hostName paddedTo:15 with:Character space) |
|
603 |
, ' up & reachable'. |
|
604 |
list list:l. |
|
605 |
conn close. |
|
606 |
] |
|
607 |
]. |
|
608 |
]. |
|
609 |
]. |
|
610 |
top label:'PING reachable hosts'. |
|
611 |
] forkAt:(Processor userBackgroundPriority). |
|
612 |
walkProcess name:'ping net walker'. |
|
613 |
[exEnd] |
|
614 |
||
615 |
||
616 |
This example creates a simple UDP server that accepts |
|
617 |
single packets from anybody and broadcasts them to all |
|
618 |
clients that have connected so far. |
|
619 |
||
620 |
[exBegin] |
|
621 |
| socket address buffer msgSize clients | |
|
622 |
clients := Set new. |
|
623 |
address := IPSocketAddress new. |
|
624 |
buffer := String new: 1024. |
|
625 |
||
626 |
socket := self newUDPserverAtPort: 6666. |
|
627 |
||
628 |
Transcript showCR: 'server starting'. |
|
629 |
||
630 |
[ |
|
631 |
[true] whileTrue: [ |
|
632 |
(socket readWaitWithTimeoutMs: 200) ifFalse: [ |
|
633 |
msgSize := socket |
|
634 |
receiveFrom: address |
|
635 |
buffer: buffer |
|
636 |
start: 1 |
|
637 |
for: buffer size. |
|
638 |
||
639 |
clients add: address copy. |
|
640 |
clients do: [ :clientAddress | |
|
641 |
socket |
|
642 |
sendTo: clientAddress |
|
643 |
buffer: buffer |
|
644 |
start: 1 |
|
645 |
for: msgSize]] |
|
646 |
] |
|
647 |
] ensure:[ |
|
648 |
Transcript showCR: 'server shutting down'. |
|
649 |
socket close |
|
650 |
] |
|
651 |
[exEnd] |
|
817 | 652 |
|
653 |
send a datagram to above server: |
|
5001 | 654 |
[exBegin] |
655 |
||
656 |
| socket address buffer host msg | |
|
657 |
||
658 |
host := Dialog |
|
659 |
request: 'What is the name of the server''s host?' |
|
660 |
initialAnswer: 'localhost'. |
|
661 |
||
662 |
socket := self newUDP. |
|
663 |
||
664 |
address := IPSocketAddress hostName: host port: 6666. |
|
665 |
||
666 |
buffer := ByteArray new: 1000. |
|
667 |
[ |
|
668 |
[(msg := Dialog request: 'Say something') isEmpty] whileFalse:[ |
|
669 |
| replySize stream | |
|
670 |
||
671 |
socket writeWait. |
|
672 |
stream := buffer writeStream. |
|
673 |
stream nextPutAll: msg. |
|
674 |
socket sendTo:address buffer:buffer start:1 for:stream position. |
|
675 |
socket readWait. |
|
676 |
||
677 |
replySize := socket receiveFrom:address buffer:buffer. |
|
678 |
replySize > 0 ifTrue: [ |
|
679 |
Transcript cr; nextPutAll: 'Server acknowledged: '. |
|
680 |
Transcript show: ((buffer copyFrom: 1 to: replySize) asString) |
|
681 |
] |
|
682 |
] |
|
683 |
] ensure: [socket close]. |
|
684 |
Transcript cr |
|
685 |
[exEnd] |
|
1316 | 686 |
|
687 |
||
688 |
loopBack: |
|
5001 | 689 |
[exBegin] |
690 |
||
691 |
|readerTask readingSocket writingSocket| |
|
692 |
||
693 |
readingSocket := self newTCPserverAtPort:9999. |
|
694 |
readerTask := |
|
695 |
[ |
|
696 |
|connection| |
|
697 |
||
698 |
readingSocket listenFor:1. |
|
699 |
connection := readingSocket accept. |
|
700 |
readingSocket close. |
|
701 |
[connection atEnd] whileFalse:[ |
|
702 |
Transcript showCR:(connection nextLine). |
|
703 |
]. |
|
704 |
connection close. |
|
705 |
] fork. |
|
706 |
||
707 |
Delay waitForSeconds:1. |
|
708 |
writingSocket := self newTCPclientToHost:'localhost' port:9999. |
|
709 |
writingSocket nextPutLine:'Hello'. |
|
710 |
writingSocket nextPutLine:'World'. |
|
711 |
writingSocket close. |
|
712 |
[exEnd] |
|
25 | 713 |
" |
714 |
! ! |
|
715 |
||
1462 | 716 |
!Socket class methodsFor:'instance creation'! |
126 | 717 |
|
3059 | 718 |
bindTo:aSocketAddress type:aTypeSymbol |
719 |
"create a socket for a specific type |
|
720 |
and bind it to aSocketAddress. |
|
721 |
Type must be: |
|
3217 | 722 |
#stream, #datagram or #raw |
3059 | 723 |
|
724 |
Neither connect nor connect-wait is done." |
|
725 |
||
726 |
|newSock| |
|
727 |
||
728 |
newSock := self domain:aSocketAddress domain type:aTypeSymbol. |
|
729 |
[ |
|
3217 | 730 |
newSock bindTo:aSocketAddress reuseAddress:true. |
3059 | 731 |
] ifCurtailed:[ |
3217 | 732 |
newSock close. |
3059 | 733 |
]. |
734 |
^ newSock |
|
735 |
||
736 |
||
737 |
" |
|
3217 | 738 |
Socket bindTo:(IPSocketAddress anyHost port:8081) type:#stream. |
739 |
Socket bindTo:(IPv6SocketAddress anyHost port:8081) type:#datagram. |
|
3059 | 740 |
" |
741 |
! |
|
742 |
||
126 | 743 |
domain:domainSymbol type:type |
744 |
"create a socket for domain and type - |
|
745 |
neither any connect nor binding is done. |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
746 |
Domain must be one of the symbols: |
3217 | 747 |
#inet, #unix, #appletalk, #decnet, #xns, ...; |
819 | 748 |
Type must be: |
3217 | 749 |
#stream, #datagram or #raw |
3059 | 750 |
|
751 |
XXX: currently only the #AF_INET and #AF_INET6 and #AF_UNIX domains are supported" |
|
126 | 752 |
|
753 |
^ self new domain:domainSymbol type:type |
|
754 |
||
755 |
" |
|
3059 | 756 |
Socket domain:#AF_INET type:#stream |
757 |
Socket domain:#AF_INET type:#datagram |
|
758 |
Socket domain:#AF_INET6 type:#stream |
|
759 |
Socket domain:#AF_INET6 type:#datagram |
|
760 |
Socket domain:#AF_UNIX type:#stream |
|
126 | 761 |
" |
762 |
! |
|
763 |
||
4955 | 764 |
newIPv6 |
765 |
"create an IPv6 socket - no binding or other setup is done, |
|
766 |
neither connect nor connect-wait is done." |
|
767 |
||
768 |
^ self new domain:#'AF_INET6' type:#stream |
|
769 |
||
770 |
" |
|
771 |
Socket newIPv6 |
|
772 |
" |
|
773 |
||
774 |
"Created: / 27-05-2019 / 14:06:23 / Claus Gittinger" |
|
775 |
! |
|
776 |
||
777 |
newIPv6:portNrOrServiceName |
|
778 |
"create an IPv6 socket for a service - |
|
779 |
neither connect nor connect-wait is done." |
|
780 |
||
781 |
|newSock socketAddress socketAddressClass| |
|
782 |
||
783 |
newSock := self newIPv6. |
|
784 |
(newSock notNil and:[portNrOrServiceName notNil]) ifTrue:[ |
|
5001 | 785 |
[ |
786 |
socketAddressClass := newSock socketAddressClass. |
|
787 |
socketAddress := socketAddressClass hostName:nil serviceName:portNrOrServiceName type:#stream. |
|
788 |
socketAddress hostAddress:socketAddressClass anyAddress. |
|
789 |
newSock bindTo:socketAddress reuseAddress:true. |
|
790 |
] ifCurtailed:[ |
|
791 |
newSock close. |
|
792 |
] |
|
4955 | 793 |
]. |
794 |
^ newSock |
|
795 |
||
796 |
||
797 |
" |
|
798 |
(Socket newIPv6:9996). |
|
799 |
||
4961 | 800 |
test (eval the code below, then open a browser on (replace by your own IPv6 address) |
5001 | 801 |
http://[2003:a:e4d:bb01:a17f:9312:54cb:fed7]:9997/ |
802 |
||
803 |
(Socket newIPv6:9997) |
|
804 |
listenFor:1; |
|
805 |
readWait; |
|
806 |
accept. |
|
807 |
||
4955 | 808 |
" |
809 |
||
810 |
"Created: / 27-05-2019 / 14:06:49 / Claus Gittinger" |
|
811 |
! |
|
812 |
||
126 | 813 |
newTCP |
814 |
"create a TCP socket - no binding or other setup is done, |
|
815 |
neither connect nor connect-wait is done." |
|
816 |
||
3059 | 817 |
^ self new domain:#'AF_INET' type:#stream |
818 |
||
819 |
" |
|
820 |
Socket newTCP |
|
821 |
" |
|
126 | 822 |
! |
823 |
||
4944 | 824 |
newTCP:portNrOrServiceName |
126 | 825 |
"create a TCP socket for a service - |
826 |
neither connect nor connect-wait is done." |
|
827 |
||
3059 | 828 |
|newSock socketAddress socketAddressClass| |
126 | 829 |
|
830 |
newSock := self newTCP. |
|
4944 | 831 |
(newSock notNil and:[portNrOrServiceName notNil]) ifTrue:[ |
5001 | 832 |
[ |
833 |
socketAddressClass := newSock socketAddressClass. |
|
834 |
socketAddress := socketAddressClass hostName:nil serviceName:portNrOrServiceName type:#stream. |
|
835 |
socketAddress hostAddress:socketAddressClass anyAddress. |
|
836 |
newSock bindTo:socketAddress reuseAddress:true. |
|
837 |
] ifCurtailed:[ |
|
838 |
newSock close. |
|
839 |
] |
|
126 | 840 |
]. |
841 |
^ newSock |
|
842 |
||
843 |
||
1911 | 844 |
" |
5001 | 845 |
Socket newTCP:'http-alt'. |
846 |
Socket newTCP:9996. |
|
1911 | 847 |
" |
4944 | 848 |
|
849 |
"Modified (comment): / 17-05-2019 / 13:10:18 / Claus Gittinger" |
|
126 | 850 |
! |
851 |
||
576 | 852 |
newTCPclientToAddress:aHostAddress port:aService |
853 |
"create a new TCP client socket connecting to a service. |
|
854 |
Return a socket instance if ok, nil on failure. |
|
855 |
Block until a connection is established (but only the current thread; |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
856 |
not the whole smalltalk). |
576 | 857 |
See also: #newTCPclientToAddress:port:withTimeout:" |
858 |
||
859 |
^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil |
|
860 |
! |
|
861 |
||
4570 | 862 |
newTCPclientToAddress:aSocketAddressOrByteArray port:aService withTimeout:milliSecondsOrTimeDuration |
576 | 863 |
"create a new TCP client socket connecting to a service. |
864 |
Return a socket instance if ok, nil on failure. |
|
865 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 866 |
and return nil." |
576 | 867 |
|
3059 | 868 |
|port socketAddress| |
869 |
||
870 |
aService isString ifTrue:[ |
|
5001 | 871 |
port := self portOfService:aService protocol:#tcp. |
3059 | 872 |
] ifFalse:[ |
5001 | 873 |
port := aService. |
3059 | 874 |
]. |
3217 | 875 |
socketAddress := aSocketAddressOrByteArray isSocketAddress |
5001 | 876 |
ifTrue:[aSocketAddressOrByteArray] |
877 |
ifFalse:[ |
|
878 |
"Passing ByteArrays is obsolete and only supported for IPv4" |
|
879 |
IPSocketAddress hostAddress:aSocketAddressOrByteArray |
|
880 |
]. |
|
3059 | 881 |
port notNil ifTrue:[ |
5001 | 882 |
socketAddress port:port. |
3059 | 883 |
]. |
4570 | 884 |
^ self newTCPclientToAddress:socketAddress withTimeout:milliSecondsOrTimeDuration |
885 |
||
886 |
"Modified (format): / 19-01-2018 / 18:26:51 / stefan" |
|
576 | 887 |
! |
888 |
||
4570 | 889 |
newTCPclientToAddress:aSocketAddress withTimeout:milliSecondsOrTimeDuration |
126 | 890 |
"create a new TCP client socket connecting to a service. |
891 |
Return a socket instance if ok, nil on failure. |
|
3059 | 892 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
893 |
and return nil." |
|
894 |
||
895 |
|socket| |
|
896 |
||
897 |
socket := self domain:aSocketAddress domain type:#stream. |
|
4570 | 898 |
^ [ |
5001 | 899 |
(socket connectTo:aSocketAddress withTimeout:milliSecondsOrTimeDuration) |
900 |
ifTrue:[socket] ifFalse:[socket close. nil] |
|
4570 | 901 |
] ifCurtailed:[ |
5001 | 902 |
socket close. |
3059 | 903 |
]. |
904 |
||
905 |
" |
|
5001 | 906 |
self newTCPclientToAddress:(IPv6SocketAddress hostName:'www.exept.de' port:80) withTimeout:nil |
3059 | 907 |
" |
4570 | 908 |
|
909 |
"Modified (format): / 19-01-2018 / 18:22:30 / stefan" |
|
3059 | 910 |
! |
911 |
||
912 |
newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName |
|
913 |
"create a new TCP client socket connecting to a service. |
|
3985 | 914 |
If hostNameOrAddress is a string, try all the resolved addresses regardless |
3988 | 915 |
whether for IPv4 or IPv6. |
3059 | 916 |
Return a socket instance if ok, nil on failure. |
126 | 917 |
Block until a connection is established (but only the current thread; |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
918 |
not the whole smalltalk). |
126 | 919 |
See also: #newTCPclientToHost:port:withTimeout:" |
920 |
||
3590 | 921 |
^ self |
4414 | 922 |
newTCPclientToHost:hostNameOrAddress |
923 |
port:aPortOrServiceName |
|
924 |
domain:self defaultIpDomainForConnect |
|
925 |
withTimeout:nil |
|
126 | 926 |
|
927 |
" |
|
4239 | 928 |
Socket newTCPclientToHost:'www.exept.de' port:'https' |
126 | 929 |
" |
930 |
||
931 |
"Created: 31.10.1995 / 18:54:11 / cg" |
|
932 |
! |
|
933 |
||
4570 | 934 |
newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName domain:aDomainSymbolOrNil withTimeout:milliSecondsOrTimeDuration |
3059 | 935 |
"create a new TCP client socket connecting to a service on hostNameOrAddress. |
3985 | 936 |
If hostNameOrAddress is a string, try all the resolved addresses. |
126 | 937 |
Return a socket instance if ok, nil on failure. |
3059 | 938 |
Set aDomainSymbolOrNil to #AF_INET of #AF_INET6 to connect via a defined protocol. |
939 |
Set aDomainSymbolOrNil to nil, to try all protocols. |
|
4570 | 940 |
If the milliSecondsOrTimeDuration arg is nonNil, stop trying to connect after that many milliSecondsOrTimeDurationeconds |
3059 | 941 |
and return nil." |
942 |
||
4570 | 943 |
|socket addressList lastDomainSymbol lastNotification| |
3059 | 944 |
|
945 |
hostNameOrAddress isString ifFalse:[ |
|
5001 | 946 |
^ self newTCPclientToAddress:hostNameOrAddress port:aPortOrServiceName withTimeout:milliSecondsOrTimeDuration. |
126 | 947 |
]. |
3059 | 948 |
|
4341 | 949 |
addressList := SocketAddress |
5001 | 950 |
allForHostName:hostNameOrAddress |
951 |
serviceName:aPortOrServiceName |
|
952 |
domain:aDomainSymbolOrNil |
|
953 |
type:#stream. |
|
4341 | 954 |
|
955 |
addressList do:[:eachAddress| |
|
5001 | 956 |
|domainSymbol| |
957 |
||
958 |
domainSymbol := eachAddress domain. |
|
959 |
domainSymbol ~~ lastDomainSymbol ifTrue:[ |
|
960 |
socket notNil ifTrue:[ |
|
961 |
socket close. |
|
962 |
]. |
|
963 |
socket := self new domain:domainSymbol type:#stream. |
|
964 |
lastDomainSymbol := domainSymbol. |
|
965 |
]. |
|
966 |
[ |
|
967 |
(socket connectTo:eachAddress withTimeout:milliSecondsOrTimeDuration) ifTrue:[ |
|
968 |
^ socket. |
|
969 |
]. |
|
970 |
] on:SocketErrorNotification do:[:ex| |
|
971 |
lastNotification := ex. |
|
972 |
]. |
|
3059 | 973 |
]. |
974 |
socket notNil ifTrue:[ |
|
5001 | 975 |
socket close. |
4570 | 976 |
]. |
977 |
lastNotification notNil ifTrue:[ |
|
5001 | 978 |
"if someone is interested in the notification - raise the last one" |
979 |
lastNotification raiseRequest. |
|
3059 | 980 |
]. |
981 |
^ nil. |
|
982 |
||
4791 | 983 |
"<<EOC |
3059 | 984 |
Socket newTCPclientToHost:'www.exept.de' port:80 domain:#'AF_INET' withTimeout:1000. |
985 |
Socket newTCPclientToHost:'www.exept.de' port:80 domain:#'AF_INET6' withTimeout:1000. |
|
986 |
Socket newTCPclientToHost:'www.exept.de' port:80 domain:nil withTimeout:1000. |
|
4791 | 987 |
|
988 |
[ |
|
5001 | 989 |
"if nobody is listening (Connection refused") the timeout does not apply" |
990 |
Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:10s |
|
4791 | 991 |
] on:SocketErrorNotification do:[:ex| |
5001 | 992 |
ex halt. |
4791 | 993 |
]. |
994 |
EOC" |
|
604 | 995 |
|
4570 | 996 |
"Modified: / 19-01-2018 / 18:12:29 / stefan" |
4791 | 997 |
"Modified: / 28-01-2019 / 10:48:18 / Stefan Vogel" |
126 | 998 |
! |
999 |
||
4570 | 1000 |
newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName withTimeout:milliSecondsOrTimeDuration |
3059 | 1001 |
"create a new TCP client socket connecting to a service on hostNameOrAddress. |
3985 | 1002 |
If hostNameOrAddress is a string, try all the resolved addresses regardless |
3988 | 1003 |
whether for IPv4 or IPv6. |
3059 | 1004 |
Return a socket instance if ok, nil on failure. |
1005 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
1006 |
and return nil." |
|
3217 | 1007 |
|
1008 |
^ self |
|
5001 | 1009 |
newTCPclientToHost:hostNameOrAddress |
1010 |
port:aPortOrServiceName |
|
1011 |
domain:self defaultIpDomainForConnect |
|
1012 |
withTimeout:milliSecondsOrTimeDuration |
|
4570 | 1013 |
|
1014 |
"Modified (format): / 19-01-2018 / 18:24:57 / stefan" |
|
3059 | 1015 |
! |
1016 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1017 |
newTCPserverAtAnonymousPort |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1018 |
"create a new TCP server socket providing service on |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1019 |
a new anonymous port. The portNr is assigned by the OS." |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1020 |
|
811 | 1021 |
^ self newTCPserverAtPort:0 |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1022 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1023 |
! |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1024 |
|
4944 | 1025 |
newTCPserverAtPort:portNrOrServiceName |
126 | 1026 |
"create a new TCP server socket providing service." |
1027 |
||
4944 | 1028 |
^ self newTCP:portNrOrServiceName |
1029 |
||
1030 |
"Modified (format): / 17-05-2019 / 13:10:33 / Claus Gittinger" |
|
126 | 1031 |
! |
1032 |
||
1033 |
newUDP |
|
1034 |
"create a UDP socket - no binding or other setup is done, |
|
1035 |
neither connect nor connect-wait is done." |
|
1036 |
||
3059 | 1037 |
^ self new domain:#'AF_INET' type:#datagram |
126 | 1038 |
|
1039 |
"Socket newUDP" |
|
1040 |
! |
|
1041 |
||
1042 |
newUDP:aServiceOrNil |
|
1043 |
"create a UDP socket for a service - |
|
1044 |
neither connect nor connect-wait is done." |
|
1045 |
||
3059 | 1046 |
|newSock socketAddressClass socketAddress| |
126 | 1047 |
|
1048 |
newSock := self newUDP. |
|
1049 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
3217 | 1050 |
[ |
1051 |
socketAddressClass := newSock socketAddressClass. |
|
1052 |
socketAddress := socketAddressClass hostName:nil serviceName:aServiceOrNil type:#stream. |
|
1053 |
socketAddress hostAddress:socketAddressClass anyAddress. |
|
1054 |
newSock bindTo:socketAddress reuseAddress:true. |
|
1055 |
] ifCurtailed:[ |
|
1056 |
newSock close. |
|
1057 |
] |
|
126 | 1058 |
]. |
1059 |
^ newSock |
|
1060 |
||
1911 | 1061 |
" |
3217 | 1062 |
Socket newUDP:4444. |
1063 |
Socket newUDP:'activesync'. |
|
1911 | 1064 |
" |
126 | 1065 |
! |
1066 |
||
1067 |
newUDPserverAtPort:aService |
|
1068 |
"create a new UDP server socket providing service." |
|
1069 |
||
1911 | 1070 |
^ self newUDP:aService |
126 | 1071 |
! |
1072 |
||
1073 |
newUNIX |
|
1074 |
"create a UNIX domain socket - no binding or other setup is done, |
|
811 | 1075 |
neither connect nor connect-wait is done. |
1076 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1077 |
return nil." |
|
126 | 1078 |
|
3059 | 1079 |
^ self new domain:#'AF_UNIX' type:#stream |
126 | 1080 |
|
1081 |
" |
|
1082 |
Socket newUNIX |
|
1083 |
" |
|
1084 |
! |
|
1085 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1086 |
newUNIXclientTo:pathName |
126 | 1087 |
"create a new UNIX client socket connecting to a pathname. |
1088 |
Return a socket instance if ok, nil on failure. |
|
1089 |
Block until a connection is established (but only the current thread; |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1090 |
not the whole smalltalk). |
811 | 1091 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
1092 |
return nil. |
|
126 | 1093 |
See also: #newUNIXclientTo:withTimeout:" |
1094 |
||
1095 |
^ self newUNIXclientTo:pathName withTimeout:nil |
|
1096 |
||
1097 |
! |
|
1098 |
||
4570 | 1099 |
newUNIXclientTo:pathName withTimeout:milliSecondsOrTimeDuration |
126 | 1100 |
"create a new UNIX client socket connecting to a pathname. |
1101 |
Return a socket instance if ok, nil on failure. |
|
1102 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 1103 |
and return nil. |
1104 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1105 |
return nil." |
|
126 | 1106 |
|
4570 | 1107 |
|socket| |
1108 |
||
1109 |
socket := self newUNIX. |
|
1110 |
socket isNil ifTrue:[ |
|
5001 | 1111 |
^ nil. |
126 | 1112 |
]. |
4570 | 1113 |
^ [ |
5001 | 1114 |
(socket connectTo:(UDSocketAddress name:pathName) withTimeout:milliSecondsOrTimeDuration) |
1115 |
ifTrue:[socket] ifFalse:[socket close. nil] |
|
4570 | 1116 |
] ifCurtailed:[ |
5001 | 1117 |
socket close. |
4570 | 1118 |
]. |
126 | 1119 |
|
1120 |
" |
|
5001 | 1121 |
Socket newUNIXclientTo:'/tmp/foo' |
1122 |
||
1123 |
[ |
|
1124 |
Socket newUNIXclientTo:'/tmp/foo' |
|
1125 |
] on:SocketErrorNotification do:[:ex| |
|
1126 |
ex halt. |
|
1127 |
] |
|
126 | 1128 |
" |
4570 | 1129 |
|
1130 |
"Modified (format): / 19-01-2018 / 18:23:24 / stefan" |
|
126 | 1131 |
! |
1132 |
||
1133 |
newUNIXserverAt:pathName |
|
811 | 1134 |
"create a new UNIX server socket providing service at a pathname. |
1135 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1136 |
return nil." |
|
126 | 1137 |
|
3059 | 1138 |
^ self bindTo:(UDSocketAddress name:pathName) type:#stream. |
126 | 1139 |
|
1140 |
" |
|
1141 |
|s s2| |
|
1142 |
||
3059 | 1143 |
'/tmp/foo' asFilename remove. |
126 | 1144 |
s := Socket newUNIXserverAt:'/tmp/foo'. |
1145 |
s listenFor:5. |
|
1146 |
s2 := s accept. |
|
1147 |
" |
|
1148 |
! ! |
|
1149 |
||
1462 | 1150 |
!Socket class methodsFor:'Compatibility-ST80'! |
1151 |
||
1152 |
family:domainSymbol type:typeSymbol |
|
1153 |
"create a socket for domain and type - ST80 simply uses a different name. |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1154 |
Domain must be one of the symbols: #inet, #unix, #appletalk or #ns; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1155 |
Type must be #stream, #datagram or #raw." |
1462 | 1156 |
|
1157 |
^ self domain:domainSymbol type:typeSymbol |
|
1158 |
||
1159 |
" |
|
3059 | 1160 |
Socket family:#AF_INET type:#stream |
1161 |
Socket family:#AF_INET type:#datagram |
|
1162 |
Socket family:#AF_UNIX type:#stream |
|
1462 | 1163 |
" |
1164 |
! |
|
1165 |
||
1166 |
getHostname |
|
3462 | 1167 |
"return the computer's hostname string" |
1462 | 1168 |
|
1169 |
^ OperatingSystem getHostName |
|
1170 |
||
1171 |
"Created: / 27.2.1998 / 02:32:17 / cg" |
|
1172 |
! |
|
1173 |
||
1174 |
sockStream |
|
1175 |
"return the type code for stream sockets" |
|
1176 |
||
1177 |
^ #stream |
|
1178 |
! ! |
|
1179 |
||
1600 | 1180 |
!Socket class methodsFor:'Compatibility-Squeak'! |
1181 |
||
2900 | 1182 |
deadlineSecs:seconds |
1183 |
^ Timestamp now addSeconds:seconds |
|
1184 |
! |
|
1185 |
||
1600 | 1186 |
initializeNetwork |
1187 |
"/ intentionally left blank here |
|
1188 |
! |
|
1189 |
||
4587 | 1190 |
openConnectionToHostNamed:hostName port:portNr |
1191 |
^ self newTCPclientToHost:hostName port:portNr |
|
1192 |
! |
|
1193 |
||
3485 | 1194 |
standardDeadline |
1195 |
"a standard timeout in seconds for connection setup; |
|
1196 |
not really used in ST/X code (but by some code ported from squeak)" |
|
1197 |
||
1198 |
^ 30 |
|
1199 |
! |
|
1200 |
||
2292 | 1201 |
standardTimeout |
3485 | 1202 |
"a standard timeout in seconds for transfers; |
1203 |
not really used in ST/X code (but by some code ported from squeak)" |
|
1204 |
||
2292 | 1205 |
^ 30 |
1206 |
! |
|
1207 |
||
1600 | 1208 |
wildcardPort |
1209 |
^ nil |
|
1210 |
! ! |
|
1211 |
||
1462 | 1212 |
!Socket class methodsFor:'Compatibility-VW'! |
1213 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1214 |
AF_INET |
1462 | 1215 |
^ #AF_INET |
1216 |
! |
|
1217 |
||
1218 |
SOCK_STREAM |
|
1219 |
^ #SOCK_STREAM |
|
1220 |
! ! |
|
1221 |
||
1222 |
!Socket class methodsFor:'Signal constants'! |
|
1223 |
||
1224 |
brokenConnectionSignal |
|
1225 |
"return the signal used to tell broken connections. |
|
1226 |
Since in unix, this is the same as the broken pipe signal, |
|
1227 |
return that one. |
|
1228 |
(for other Operatingsystems, this may change ..)" |
|
1229 |
||
1230 |
^ PipeStream brokenPipeSignal |
|
1231 |
! |
|
1232 |
||
1233 |
invalidArgumentsSignal |
|
1234 |
"dummy for compatibility" |
|
1235 |
||
1236 |
^ self errorSignal |
|
1237 |
! ! |
|
1238 |
||
1239 |
!Socket class methodsFor:'debugging'! |
|
1240 |
||
1241 |
debug:aBoolean |
|
1242 |
"turn on/off internal debugprints. |
|
1243 |
This method is for ST/X debugging only and |
|
1244 |
may be removed in later versions" |
|
1245 |
||
1246 |
%{ /* NOCONTEXT */ |
|
1247 |
||
1248 |
__debugging__ = (aBoolean == true); |
|
1249 |
%} |
|
1250 |
" |
|
1251 |
Socket debug:true |
|
1252 |
Socket debug:false |
|
1253 |
" |
|
1254 |
! ! |
|
1255 |
||
3059 | 1256 |
!Socket class methodsFor:'defaults'! |
1257 |
||
1258 |
defaultIpDomainForConnect |
|
1259 |
"answer the domain used to look up host names for connect: |
|
4414 | 1260 |
#AF_INET use only IPv4 |
1261 |
#AF_INET6 use only IPv6 |
|
1262 |
nil use both IPv4 and IPv6" |
|
4239 | 1263 |
|
1264 |
^ nil |
|
3059 | 1265 |
! ! |
1266 |
||
1911 | 1267 |
!Socket class methodsFor:'obsolete'! |
1268 |
||
1269 |
connectTo:service on:host |
|
1270 |
<resource: #obsolete> |
|
1271 |
"standard & easy client setup: |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1272 |
create new client tcp socket, bind and connect; |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1273 |
return the socket. |
1911 | 1274 |
The thread blocks (interruptable), until the connection is established." |
1275 |
||
1276 |
^ self newTCPclientToHost:host port:(self portOfService:service). |
|
1277 |
||
1278 |
" |
|
1279 |
Socket connectTo:9995 on:'clam' |
|
1280 |
Socket connectTo:4711 on:'exept' |
|
1281 |
Socket connectTo:'finger' on:'clam' |
|
1282 |
Socket connectTo:'ftp' on:'exept' |
|
1283 |
Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER') |
|
1284 |
" |
|
1285 |
! |
|
1286 |
||
1287 |
networkLongOrderIsMSB |
|
1288 |
"return the well known fact, that network byte order is most significant byte first" |
|
1289 |
||
1290 |
<resource: #obsolete> |
|
1291 |
||
1292 |
^ true |
|
1293 |
! |
|
1294 |
||
1295 |
networkShortOrderIsMSB |
|
1296 |
"return the well known fact, that network byte order is most significant byte first" |
|
1297 |
||
1298 |
<resource: #obsolete> |
|
1299 |
||
1300 |
^ true |
|
1301 |
! |
|
1302 |
||
1303 |
provide:aService |
|
1304 |
"standard & easy server setup: |
|
1305 |
create a new TCP server socket providing a service." |
|
1306 |
||
1307 |
<resource:#obsolete> |
|
1308 |
||
1309 |
|newSock| |
|
1310 |
||
1311 |
self obsoleteMethodWarning:'use #newTCPserverAtPort: / #listen'. |
|
1312 |
||
1313 |
newSock := self newTCPserverAtPort:(self portOfService:aService). |
|
1314 |
newSock notNil ifTrue:[ |
|
1315 |
newSock listenFor:5. |
|
1316 |
]. |
|
1317 |
^ newSock |
|
1318 |
||
1319 |
" |
|
1320 |
Socket provide:9995 |
|
1321 |
(Socket provide:9996) accept |
|
1322 |
Socket provide:'nntp' |
|
1323 |
" |
|
1324 |
! ! |
|
1325 |
||
1326 |
!Socket class methodsFor:'obsolete host queries'! |
|
525 | 1327 |
|
1328 |
appletalkAddressOfHost:aHostName |
|
1911 | 1329 |
<resource: #obsolete> |
525 | 1330 |
"return the APPLETALK address for a hostname as a byteArray, |
819 | 1331 |
where the network bytes come first (no matter what the local byteorder is) |
1332 |
followed by the node byte. |
|
525 | 1333 |
If the host is unknown, return nil. |
812 | 1334 |
This is the reverse operation to #hostWithAppletalkAddress:. |
1335 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1336 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1337 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1338 |
handle:[:ex | |
1343 | 1339 |
^ nil |
1340 |
] |
|
1341 |
do:[ |
|
1342 |
^ (AppletalkSocketAddress hostName:aHostName) address |
|
1343 |
] |
|
525 | 1344 |
! |
1345 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1346 |
hostWithAppletalkAddress:addrByteArray |
1911 | 1347 |
<resource: #obsolete> |
525 | 1348 |
"return the hostname for an APPLETALK address. |
1349 |
The address is supposed to be a byteArray consisting of 3 bytes, |
|
1350 |
the network bytes come first (no matter what the local byteorder is). |
|
1351 |
The last byte is the node number. |
|
4320 | 1352 |
Nil is returned for an unknown host or if it's not an appletalk host. |
812 | 1353 |
This is is the reverse operation to #appletalkAddressOfHost:. |
1354 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1355 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1356 |
NameLookupError |
4414 | 1357 |
handle:[:ex | |
1358 |
^ nil |
|
1359 |
] |
|
1360 |
do:[ |
|
1361 |
^ (AppletalkSocketAddress hostAddress:addrByteArray) hostName |
|
1362 |
] |
|
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1363 |
|
525 | 1364 |
" |
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1365 |
Socket appletalkAddressOfHost:'yourAppleHere' |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1366 |
Socket hostWithAppletalkAddress:#[1 2 3] |
525 | 1367 |
" |
4320 | 1368 |
|
1369 |
"Modified (comment): / 13-02-2017 / 20:30:56 / cg" |
|
126 | 1370 |
! |
1371 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1372 |
hostWithIpAddress:addrByteArray |
1911 | 1373 |
<resource: #obsolete> |
126 | 1374 |
"return the hostname for an IP (internet-) address. |
1375 |
The address is supposed to be a byteArray consisting of 4 bytes, |
|
1376 |
the network bytes come first (no matter what the local byteorder is). |
|
4320 | 1377 |
Nil is returned for an unknown host or if it's not an internet host. |
126 | 1378 |
This is the reverse operation to #ipAddressOfHost:." |
1379 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1380 |
NameLookupError |
4414 | 1381 |
handle:[:ex | |
1382 |
^ nil |
|
1383 |
] |
|
1384 |
do:[ |
|
1385 |
^ (IPSocketAddress hostAddress:addrByteArray) hostName |
|
1386 |
] |
|
126 | 1387 |
|
1388 |
" |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1389 |
Socket ipAddressOfHost:'clam' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1390 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1391 |
Socket ipAddressOfHost:'porty' |
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1392 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1393 |
Socket hostWithIpAddress:#[1 2 3 4] |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1394 |
Socket hostWithIpAddress:#[127 0 0 1] |
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1395 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4') |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1396 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'www.altavista.com') |
126 | 1397 |
" |
4320 | 1398 |
|
1399 |
"Modified (comment): / 13-02-2017 / 20:31:01 / cg" |
|
126 | 1400 |
! |
1401 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1402 |
hostWithIpV6Address:addrByteArray |
1911 | 1403 |
<resource: #obsolete> |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1404 |
"return the hostname for an IPv6 (internet-) address. |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1405 |
The address is supposed to be a byteArray consisting ??? bytes, |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1406 |
the network bytes come first (no matter what the local byteorder is). |
4320 | 1407 |
Nil is returned for an unknown host or if it's not an internet host. |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1408 |
This is the reverse operation to #ipV6AddressOfHost:." |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1409 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1410 |
NameLookupError |
4414 | 1411 |
handle:[:ex | |
1412 |
^ nil |
|
1413 |
] |
|
1414 |
do:[ |
|
1415 |
^ (IPv6SocketAddress hostAddress:addrByteArray) hostName |
|
1416 |
] |
|
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1417 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1418 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1419 |
Socket ipV6AddressOfHost:'clam' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1420 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1421 |
Socket ipV6AddressOfHost:'porty' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1422 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1423 |
Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14] |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1424 |
Socket ipV6AddressOfHost:'www.exept.de' |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1425 |
" |
4320 | 1426 |
|
1427 |
"Modified (comment): / 13-02-2017 / 20:31:08 / cg" |
|
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1428 |
! |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1429 |
|
6 | 1430 |
ipAddressOfHost:aHostName |
1911 | 1431 |
<resource: #obsolete> |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1432 |
"return the IP (internet-) number for a hostname as a byteArray, |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1433 |
where the network bytes come first (no matter what the cpus byteOrder is). |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1434 |
If the host is unknown, return nil. |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1435 |
This is the reverse operation to #hostWithIpAddress:." |
6 | 1436 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1437 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1438 |
handle:[:ex | |
1343 | 1439 |
^ nil |
1440 |
] |
|
1441 |
do:[ |
|
1442 |
^ (IPSocketAddress hostName:aHostName) address |
|
1443 |
] |
|
21 | 1444 |
|
71 | 1445 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1446 |
Socket ipAddressOfHost:'localhost' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1447 |
Socket ipAddressOfHost:'exept' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1448 |
Socket ipAddressOfHost:'1.2.3.4' |
1274
f257a1b16b4d
use naemLookup from SocketAddress for ipv6
Claus Gittinger <cg@exept.de>
parents:
1263
diff
changeset
|
1449 |
Socket ipAddressOfHost:'193.15.16.17' |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1450 |
Socket ipAddressOfHost:'josef' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1451 |
Socket ipAddressOfHost:'styx.com' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1452 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1453 |
Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') |
71 | 1454 |
" |
819 | 1455 |
! |
1456 |
||
1457 |
ipV6AddressOfHost:aHostName |
|
1911 | 1458 |
<resource: #obsolete> |
819 | 1459 |
"return the IPv6 (internet-) number for a hostname as a byteArray, |
1460 |
where the network bytes come first (no matter what the cpus byteOrder is). |
|
1461 |
If the host is unknown, return nil. |
|
1462 |
This is the reverse operation to #hostWithIpV6Address:." |
|
1463 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1464 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1465 |
handle:[:ex | |
1343 | 1466 |
^ nil |
1467 |
] |
|
1468 |
do:[ |
|
1469 |
^ (IPv6SocketAddress hostName:aHostName) address |
|
1470 |
] |
|
819 | 1471 |
|
1472 |
" |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1473 |
Socket ipV6AddressOfHost:'localhost' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1474 |
Socket ipV6AddressOfHost:'exept' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1475 |
Socket ipV6AddressOfHost:'exept.exept.de' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1476 |
Socket ipV6AddressOfHost:'www.google.de' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1477 |
Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1478 |
Socket ipV6AddressOfHost:'josef' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1479 |
Socket ipV6AddressOfHost:'styx.com' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1480 |
Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1481 |
Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') |
819 | 1482 |
" |
531 | 1483 |
! ! |
1484 |
||
1485 |
!Socket class methodsFor:'queries'! |
|
1486 |
||
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1487 |
peerFromDomain:domain name:peerName port:port |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1488 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1489 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1490 |
addrClass := self socketAddressClassForDomain:domain. |
1263
23161346a162
no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents:
1260
diff
changeset
|
1491 |
^ addrClass hostName:peerName serviceName:port type:nil |
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1492 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1493 |
|
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1494 |
peerNameFromDomain:domain peer:peer |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1495 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1496 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1497 |
addrClass := self socketAddressClassForDomain:domain. |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1498 |
^ addrClass peerNameFromPeer:peer |
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1499 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1500 |
|
0 | 1501 |
portOfService:aNameOrNumber |
819 | 1502 |
"returns the port-number for a given IP-service |
0 | 1503 |
or nil if no such service exists; |
1504 |
- used to convert service names to portNumbers" |
|
1505 |
||
91 | 1506 |
^ self portOfService:aNameOrNumber protocol:nil |
1507 |
||
28 | 1508 |
" |
1509 |
Socket portOfService:'finger' |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1510 |
Socket portOfService:'nntp' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1511 |
Socket portOfService:'echo' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1512 |
Socket portOfService:'snmp' |
28 | 1513 |
" |
0 | 1514 |
! |
1515 |
||
91 | 1516 |
portOfService:aNameOrNumber protocol:aProtocol |
819 | 1517 |
"returns the port-number for a given IP-service |
91 | 1518 |
or nil if no such service exists; |
1519 |
- used to convert service names to portNumbers" |
|
1520 |
||
2909 | 1521 |
%{ /* UNLIMITEDSTACK(noWIN32) */ |
418 | 1522 |
#ifndef NO_SOCKET |
91 | 1523 |
struct servent *servent = NULL; |
1524 |
char *protocol; |
|
1525 |
int tryBoth = 0; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1526 |
short portNo; |
91 | 1527 |
|
604 | 1528 |
if (__isSmallInteger(aNameOrNumber)) { |
2340 | 1529 |
RETURN ( aNameOrNumber ); |
92 | 1530 |
} |
1531 |
||
2331 | 1532 |
if (__isStringLike(aProtocol)) { |
2340 | 1533 |
protocol = (char *)__stringVal(aProtocol); |
604 | 1534 |
} else { |
2340 | 1535 |
protocol = "tcp"; |
1536 |
tryBoth = 1; |
|
91 | 1537 |
} |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1538 |
|
2331 | 1539 |
if (__isStringLike(aNameOrNumber)) { |
2340 | 1540 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol); |
1541 |
if (servent != NULL) { |
|
1542 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
|
1543 |
} |
|
1544 |
if (tryBoth) { |
|
1545 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
|
1546 |
if (servent != NULL) { |
|
1547 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
|
1548 |
} |
|
1549 |
} |
|
1550 |
RETURN ( nil ); |
|
91 | 1551 |
} |
418 | 1552 |
#endif |
91 | 1553 |
RETURN ( nil ); |
1554 |
%} |
|
1555 |
" |
|
1556 |
Socket portOfService:'echo' protocol:'udp' |
|
1557 |
Socket portOfService:'echo' protocol:'tcp' |
|
1558 |
" |
|
1559 |
! |
|
1560 |
||
0 | 1561 |
protocolOfService:aNameOrNumber |
819 | 1562 |
"returns the protocol (as string) for a given IP-service |
28 | 1563 |
or nil if no such service exists." |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1564 |
|
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1565 |
%{ /* UNLIMITEDSTACK(noWIN32) */ |
418 | 1566 |
#ifndef NO_SOCKET |
0 | 1567 |
struct servent *servent = NULL; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1568 |
short portNo; |
0 | 1569 |
|
58 | 1570 |
if (__isSmallInteger(aNameOrNumber)) { |
2340 | 1571 |
portNo = __intVal(aNameOrNumber); |
1572 |
servent = getservbyport(htons(portNo), "tcp") ; |
|
1573 |
if (servent == NULL) { |
|
1574 |
servent = getservbyport(htons(portNo), "udp") ; |
|
1575 |
if (servent == NULL) { |
|
1576 |
RETURN ( nil ); |
|
1577 |
} |
|
1578 |
} |
|
0 | 1579 |
} else { |
2340 | 1580 |
if (__isStringLike(aNameOrNumber)) { |
1581 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp"); |
|
1582 |
if (servent == NULL) { |
|
1583 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
|
1584 |
if (servent == NULL) { |
|
1585 |
RETURN ( nil ); |
|
1586 |
} |
|
1587 |
} |
|
1588 |
} |
|
0 | 1589 |
} |
1590 |
if (servent) { |
|
2340 | 1591 |
RETURN ( __MKSTRING(servent->s_proto) ); |
0 | 1592 |
} |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1593 |
#endif /* !NO_SOCKET */ |
0 | 1594 |
RETURN ( nil ); |
1595 |
%} |
|
28 | 1596 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1597 |
Socket protocolOfService:'finger' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1598 |
Socket protocolOfService:'nntp' |
28 | 1599 |
Socket protocolOfService:'xxx' |
1600 |
Socket protocolOfService:79 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1601 |
Socket protocolOfService:'snmp' |
28 | 1602 |
" |
1603 |
! |
|
1604 |
||
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1605 |
socketAddressClassForDomain:domain |
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1606 |
^ SocketAddress knownClassFromCode:domain |
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1607 |
|
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1608 |
" |
3059 | 1609 |
self socketAddressClassForDomain:#AF_INET |
1610 |
self socketAddressClassForDomain:#AF_UNIX |
|
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1611 |
" |
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1612 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1613 |
|
532 | 1614 |
supportedProtocolFamilies |
1615 |
"return a collection of supported protocol families. |
|
1616 |
This list specifies what the Socket class supports - |
|
1617 |
socket creation may still fail, if your system was built |
|
1618 |
without it." |
|
1619 |
||
1280
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
1620 |
^ OperatingSystem supportedProtocolFamilies |
532 | 1621 |
|
1622 |
" |
|
1623 |
Socket supportedProtocolFamilies |
|
1624 |
" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1625 |
! |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1626 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1627 |
typeOfProtocol:aProtocol |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1628 |
"given a protocols name (i.e. tcp, udp etc) return the connection type. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1629 |
This method needs more ... - or is there a way to get this from the system ?" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1630 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1631 |
(aProtocol = 'tcp') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1632 |
(aProtocol = 'udp') ifTrue:[^ #datagram]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1633 |
(aProtocol = 'ip') ifTrue:[^ #raw]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1634 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1635 |
unix domain |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1636 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1637 |
(aProtocol = 'ud') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1638 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1639 |
add x25 stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1640 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1641 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1642 |
add appletalk stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1643 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1644 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1645 |
add other stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1646 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1647 |
^ nil |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1648 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1649 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1650 |
Socket typeOfProtocol:'tcp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1651 |
Socket typeOfProtocol:'ucp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1652 |
Socket typeOfProtocol:(Socket protocolOfService:'nntp') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1653 |
Socket typeOfProtocol:(Socket protocolOfService:'echo') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1654 |
" |
28 | 1655 |
! ! |
1656 |
||
1202 | 1657 |
!Socket methodsFor:'Compatibility-Dolphin'! |
1110 | 1658 |
|
1659 |
setReceiveTimeout: milliseconds |
|
1660 |
self receiveTimeout:(milliseconds / 1000) |
|
1661 |
! |
|
1662 |
||
1663 |
setSendTimeout: milliseconds |
|
1664 |
self sendTimeout:(milliseconds / 1000) |
|
1665 |
! ! |
|
1666 |
||
1202 | 1667 |
!Socket methodsFor:'Compatibility-ST80'! |
28 | 1668 |
|
887 | 1669 |
acceptNonBlock |
1670 |
^ self accept |
|
1671 |
! |
|
1672 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1673 |
ioConnection |
887 | 1674 |
^ self |
1675 |
! |
|
1676 |
||
126 | 1677 |
notReadySignal |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1678 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1679 |
for now - this is not yet raised" |
71 | 1680 |
|
126 | 1681 |
^ Signal new |
486 | 1682 |
! |
1683 |
||
576 | 1684 |
readAppendStream |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1685 |
"ST-80 mimicry. |
4293 | 1686 |
In ST-80, socket is not a stream, but refers to one. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1687 |
ST-80 code therefore uses 'Socket readWriteStream' to access |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1688 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1689 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1690 |
this method returns the receiver, for transparency" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1691 |
|
576 | 1692 |
^ self |
1693 |
! |
|
1694 |
||
486 | 1695 |
readStream |
1696 |
"ST-80 mimicry. |
|
4293 | 1697 |
In ST-80, socket is not a stream, but refers to one. |
486 | 1698 |
ST-80 code therefore uses 'Socket readStream' to access |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1699 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1700 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1701 |
this method returns the receiver, for transparency" |
486 | 1702 |
|
1703 |
^ self |
|
1704 |
||
1705 |
"Created: 24.1.1997 / 23:52:57 / cg" |
|
1706 |
! |
|
1707 |
||
1708 |
writeStream |
|
1709 |
"ST-80 mimicry. |
|
4293 | 1710 |
In ST-80, socket is not a stream, but refers to one. |
486 | 1711 |
ST-80 code therefore uses 'Socket writeStream' to access |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1712 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1713 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1714 |
this method returns the receiver, for transparency" |
486 | 1715 |
|
1716 |
^ self |
|
1717 |
||
1718 |
"Created: 24.1.1997 / 10:34:35 / cg" |
|
1719 |
"Modified: 24.1.1997 / 23:52:52 / cg" |
|
71 | 1720 |
! ! |
1721 |
||
1202 | 1722 |
!Socket methodsFor:'Compatibility-Squeak'! |
771 | 1723 |
|
1462 | 1724 |
address |
1725 |
^ self getSocketAddress |
|
1726 |
! |
|
1727 |
||
2308
d8b410a4f38b
added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
1728 |
connectToHostNamed:hostName port:portNr |
d8b410a4f38b
added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
1729 |
self connectTo:hostName port:portNr |
d8b410a4f38b
added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
1730 |
! |
d8b410a4f38b
added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
1731 |
|
1462 | 1732 |
dataAvailable |
1733 |
^ self canReadWithoutBlocking |
|
1734 |
! |
|
1735 |
||
1886 | 1736 |
destroy |
1737 |
self close |
|
1738 |
||
1739 |
"Created: / 04-06-2007 / 21:29:03 / cg" |
|
1740 |
! |
|
1741 |
||
1462 | 1742 |
listenOn:aPortNr |
1882 | 1743 |
self listenOn:aPortNr backlogSize:5 |
1744 |
||
1745 |
"Modified: / 31-05-2007 / 17:59:53 / cg" |
|
1746 |
! |
|
1747 |
||
1748 |
listenOn:aPortNr backlogSize:aNumber |
|
1462 | 1749 |
self bindTo:aPortNr address:nil. |
1935 | 1750 |
self listenFor:aNumber |
1882 | 1751 |
|
1752 |
"Created: / 31-05-2007 / 17:59:47 / cg" |
|
1462 | 1753 |
! |
1754 |
||
4587 | 1755 |
noTimeout |
1756 |
"disable timeouts - dummy for now" |
|
1757 |
||
5001 | 1758 |
^ self |
4587 | 1759 |
! |
1760 |
||
1885 | 1761 |
peerName |
1762 |
"return my peer (i.e. ipAddr + port); |
|
1763 |
May return nil if not yet setup completely." |
|
1764 |
||
1765 |
^ self getPeer |
|
1766 |
! |
|
1767 |
||
1768 |
sendData: aStringOrByteArray |
|
3155
d1884a37375c
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
3152
diff
changeset
|
1769 |
"Send all of the data in the given array, even if it requires multiple calls to send it all. |
d1884a37375c
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
3152
diff
changeset
|
1770 |
Return the number of bytes sent." |
d1884a37375c
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
3152
diff
changeset
|
1771 |
|
d1884a37375c
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
3152
diff
changeset
|
1772 |
^ self nextPutBytes:aStringOrByteArray size from:aStringOrByteArray startingAt:1. |
1600 | 1773 |
! |
1774 |
||
2904 | 1775 |
waitForConnectionUntil:aTimestamp |
1776 |
"return true if connected" |
|
1777 |
||
1778 |
self readWaitWithTimeoutMs: (aTimestamp millisecondDeltaFrom:Timestamp now). |
|
1779 |
^ self isConnected |
|
771 | 1780 |
! ! |
1781 |
||
1935 | 1782 |
!Socket methodsFor:'accepting connections'! |
1783 |
||
1784 |
accept |
|
1785 |
"create a new TCP socket from accepting on the receiver. |
|
1786 |
This method will suspend the current process if no connection is waiting. |
|
1787 |
For ST-80 compatibility" |
|
1788 |
||
3633 | 1789 |
^ self waitForNewConnectionWithTimeout:nil |
1935 | 1790 |
|
1791 |
" |
|
1792 |
|sock newSock| |
|
1793 |
||
1794 |
sock := Socket provide:8004. |
|
1795 |
sock listenFor:5. |
|
1796 |
newSock := sock accept. |
|
1797 |
" |
|
1798 |
! |
|
1799 |
||
1800 |
blockingAccept |
|
1801 |
"create a new TCP socket from accepting on the receiver. |
|
1802 |
This method will suspend the smalltalk image with all smalltalk processes if no connection is waiting. |
|
1803 |
For ST-80 compatibility" |
|
1804 |
||
1805 |
|newSock| |
|
1806 |
||
1807 |
newSock := self class new. |
|
1808 |
(newSock primAcceptOn:self blocking:true) ifFalse:[ |
|
5001 | 1809 |
"should raise an error here - primitive code raises a notification" |
1810 |
^ nil |
|
1935 | 1811 |
]. |
1812 |
^ newSock |
|
4568 | 1813 |
|
1814 |
"Modified (format): / 19-01-2018 / 13:32:25 / stefan" |
|
1935 | 1815 |
! ! |
1816 |
||
1817 |
!Socket methodsFor:'binding'! |
|
1818 |
||
1819 |
bindAnonymously |
|
1820 |
"bind to any address. A free port will be allocated. |
|
4942 | 1821 |
Our own socket address will be determined after connection set up. |
1935 | 1822 |
This is the default after the socket has been created" |
1823 |
||
3059 | 1824 |
^ self bindTo:nil reuseAddress:false |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1825 |
|
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1826 |
" |
1938 | 1827 |
self newTCP bindAnonymously; listenFor:1; yourself |
4206 | 1828 |
self newTCP bindAnonymously; port |
1938 | 1829 |
" |
4942 | 1830 |
|
1831 |
"Modified (comment): / 08-05-2019 / 14:40:11 / Claus Gittinger" |
|
1935 | 1832 |
! |
1833 |
||
3059 | 1834 |
bindAnonymouslyToAddress:aSocketAddress |
1935 | 1835 |
"bind to address addressString. |
1836 |
A free port will be allocated" |
|
1837 |
||
1838 |
^ self |
|
3217 | 1839 |
bindTo:0 |
1840 |
address:aSocketAddress |
|
1841 |
reuseAddress:false |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1842 |
|
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1843 |
" |
3059 | 1844 |
self newTCP bindAnonymouslyToAddress:IPSocketAddress localHost; listenFor:1; yourself |
1938 | 1845 |
" |
1935 | 1846 |
! |
1847 |
||
1848 |
bindTo:aSocketAddress |
|
1849 |
"ST80 compatible bind, expecting a socketAddress argument. |
|
1850 |
The socketAddress object (an instance of SocketAddress) |
|
1851 |
is supposed to respond to #portOrName and #address requests." |
|
1852 |
||
3059 | 1853 |
^ self bindTo:aSocketAddress reuseAddress:true |
1935 | 1854 |
! |
1855 |
||
1856 |
bindTo:portNrOrNameString address:addressString |
|
3059 | 1857 |
"Old interface: bind the socket to an address |
1858 |
- returns true if ok, false otherwise. |
|
4568 | 1859 |
Notify with a SocketErrorNotification on error. |
3059 | 1860 |
|
1861 |
The interpretation of hostOrPathNameOrSocketAddrOrNil portNrOrName depends on the domain: |
|
5001 | 1862 |
Best use a SocketAddress |
1863 |
For backward compatibility: |
|
1864 |
AF_INET domain can also use (4byte) byteArray like internet numbers, |
|
1865 |
AF_UNIX domain cab use pathname strings." |
|
1935 | 1866 |
|
1867 |
^ self |
|
5001 | 1868 |
bindTo:portNrOrNameString |
1869 |
address:addressString |
|
1870 |
reuseAddress:true |
|
4568 | 1871 |
|
1872 |
"Modified (comment): / 19-01-2018 / 13:36:54 / stefan" |
|
1935 | 1873 |
! |
1874 |
||
1875 |
bindTo:portNrOrNameOrNil address:hostOrPathNameOrSocketAddrOrNil reuseAddress:reuse |
|
3059 | 1876 |
"Old interface: bind the socket to an address |
4568 | 1877 |
Notify with a SocketErrorNotification on error. |
3059 | 1878 |
- returns true if ok, false otherwise. |
1879 |
||
1880 |
The interpretation of hostOrPathNameOrSocketAddrOrNil portNrOrName depends on the domain: |
|
5001 | 1881 |
Best use a SocketAddress |
1882 |
For backward compatibility: |
|
1883 |
AF_INET domain can also use (4byte) byteArray like internet numbers, |
|
1884 |
AF_UNIX domain can use pathname strings. |
|
1935 | 1885 |
|
1886 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
1887 |
is to be set (to avoid the 'bind: address in use' error). |
|
1888 |
" |
|
1889 |
||
3059 | 1890 |
|socketAddress| |
1935 | 1891 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1892 |
handle isNil ifTrue:[ |
5001 | 1893 |
^ self errorNotOpen |
1935 | 1894 |
]. |
1895 |
||
1896 |
hostOrPathNameOrSocketAddrOrNil isNil ifTrue:[ |
|
5001 | 1897 |
socketAddress := self socketAddressClass anyHost. |
1935 | 1898 |
] ifFalse:[ |
5001 | 1899 |
(hostOrPathNameOrSocketAddrOrNil isSocketAddress) ifTrue:[ |
1900 |
socketAddress := hostOrPathNameOrSocketAddrOrNil. |
|
1901 |
] ifFalse:[ |
|
1902 |
"backward compatibility: support for byteArray and string arg" |
|
1903 |
hostOrPathNameOrSocketAddrOrNil isString ifTrue:[ |
|
1904 |
socketAddress := self socketAddressClass hostName:hostOrPathNameOrSocketAddrOrNil. |
|
1905 |
] ifFalse:[ |
|
1906 |
hostOrPathNameOrSocketAddrOrNil isByteCollection ifFalse:[ |
|
1907 |
^ self error:'bindTo: bad host (socketAddress) argument' |
|
1908 |
]. |
|
1909 |
socketAddress := self socketAddressClass hostAddress:hostOrPathNameOrSocketAddrOrNil. |
|
1910 |
]. |
|
1911 |
]. |
|
1935 | 1912 |
]. |
1913 |
portNrOrNameOrNil notNil ifTrue:[ |
|
5001 | 1914 |
socketAddress port:portNrOrNameOrNil. |
1935 | 1915 |
]. |
3059 | 1916 |
|
1917 |
^ self bindTo:socketAddress reuseAddress:reuse. |
|
1918 |
||
1919 |
" |
|
1920 |
(Socket domain:#'AF_INET' type:#stream) |
|
5001 | 1921 |
bindTo:2144 address:nil; yourself |
3059 | 1922 |
" |
4568 | 1923 |
|
1924 |
"Modified (comment): / 19-01-2018 / 13:37:13 / stefan" |
|
3059 | 1925 |
! |
1926 |
||
1927 |
bindTo:aSocketAddress reuseAddress:reuse |
|
1928 |
"Bind the socket to aSocketAddress - returns true if ok, false otherwise. |
|
4568 | 1929 |
Notify with a SocketErrorNotification on error. |
3059 | 1930 |
|
1931 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
1932 |
is to be set (to avoid the 'bind: address in use' error). |
|
1933 |
||
3137 | 1934 |
You can bind to nil to bind to anyHost and assign a random port." |
3059 | 1935 |
|
1936 |
|ok error socketAddress| |
|
1937 |
||
1938 |
handle isNil ifTrue:[ |
|
5001 | 1939 |
^ self errorNotOpen |
3059 | 1940 |
]. |
1941 |
socketAddress := aSocketAddress. |
|
1942 |
socketAddress isNil ifTrue:[ |
|
5001 | 1943 |
"ok, get an all zero socket address, so it is for anyHost |
1944 |
and the port will be assigned" |
|
1945 |
socketAddress := self socketAddressClass new. |
|
3513 | 1946 |
]. |
1947 |
domain == #'AF_INET6' ifTrue:[ |
|
5001 | 1948 |
"accept also IPv4 connections on IPv6 sockets (this is off by default for windows" |
1949 |
self setSocketOption:#'IPV6_V6ONLY' argument:false argument:nil. |
|
1935 | 1950 |
]. |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1951 |
ok := false. |
1935 | 1952 |
|
1953 |
%{ /* STACK: 100000 */ |
|
1954 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1955 |
OBJ fp = __INST(handle); |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1956 |
SOCKET sock; |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1957 |
union sockaddr_u sa; |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1958 |
int sockaddr_size; |
2909 | 1959 |
INT ret; |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1960 |
int sockAddrOffs; |
1935 | 1961 |
|
3059 | 1962 |
if (fp == nil) { |
5001 | 1963 |
goto getOutOfHere; |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1964 |
} |
3059 | 1965 |
|
1966 |
if (! __isBytes(socketAddress)) { |
|
5001 | 1967 |
error = __mkSmallInteger(-1); |
1968 |
goto getOutOfHere; |
|
1935 | 1969 |
} |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1970 |
/* get the socket-address */ |
3059 | 1971 |
if (__isNonNilObject(socketAddress)){ |
5001 | 1972 |
int nIndex; |
1973 |
OBJ cls = __qClass(socketAddress); |
|
1974 |
||
1975 |
sockAddrOffs = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1976 |
nIndex = __qSize(socketAddress) - OHDR_SIZE; |
|
1977 |
sockaddr_size = nIndex - sockAddrOffs; |
|
1978 |
if (sockaddr_size > sizeof(sa)) { |
|
1979 |
error=__mkSmallInteger(-2); |
|
1980 |
goto getOutOfHere; |
|
1981 |
} |
|
1982 |
memcpy(&sa, __byteArrayVal(socketAddress) + sockAddrOffs, sockaddr_size); |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1983 |
} |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1984 |
|
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1985 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
1935 | 1986 |
|
1987 |
# ifdef SO_REUSEADDR |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1988 |
if (reuse == true) { |
5001 | 1989 |
int on = 1; |
1990 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
1991 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
1992 |
} |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1993 |
} |
1935 | 1994 |
# endif /* SO_REUSEADDR */ |
1995 |
||
1996 |
# ifdef BIND_BLOCKS |
|
1997 |
# ifdef DO_WRAP_CALLS |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
1998 |
do { |
5001 | 1999 |
__threadErrno = 0; |
2000 |
ret = STX_WSA_NOINT_CALL3("bind", bind, sock, &sa, sockaddr_size); |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2001 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3126 | 2002 |
if (ret < 0) { |
5001 | 2003 |
errno = __threadErrno; |
3126 | 2004 |
} |
1935 | 2005 |
# else |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2006 |
__BEGIN_INTERRUPTABLE__ |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2007 |
do { |
5001 | 2008 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2009 |
} while ((ret < 0) && (errno == EINTR)); |
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2010 |
__END_INTERRUPTABLE__ |
1935 | 2011 |
# endif |
2012 |
# else |
|
3126 | 2013 |
errno = 0; |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2014 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
1935 | 2015 |
# endif |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2016 |
if (ret < 0) { |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2017 |
# ifdef __win32__ |
5001 | 2018 |
if (errno == 0) { |
2019 |
errno = WSAGetLastError(); |
|
2020 |
} |
|
3126 | 2021 |
# endif |
5001 | 2022 |
DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno)); |
2023 |
error = __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2024 |
goto getOutOfHere; |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2025 |
} else { |
5001 | 2026 |
ok = true; |
1935 | 2027 |
} |
2028 |
#endif /* NO_SOCKET */ |
|
2029 |
||
2030 |
getOutOfHere: ; |
|
2031 |
%}. |
|
4234 | 2032 |
ok ifFalse:[ |
5001 | 2033 |
|errorHolder errorString| |
2034 |
||
2035 |
error isInteger ifTrue:[ |
|
2036 |
errorHolder := OperatingSystem errorHolderForNumber:error. |
|
2037 |
errorString := errorHolder errorString. |
|
2038 |
] ifFalse:[ |
|
2039 |
errorString := error. |
|
2040 |
]. |
|
2041 |
OpenError newException |
|
2042 |
errorString:('cannot bind socket to address: %1 (%2)' |
|
2043 |
bindWith:socketAddress |
|
2044 |
with:errorString); |
|
2045 |
errorCode:error; |
|
2046 |
osErrorHolder:errorHolder; |
|
2047 |
parameter:self; |
|
2048 |
raiseRequest. |
|
2049 |
"maybe someone catches the error and binds to some other port..." |
|
2050 |
^ true. |
|
1935 | 2051 |
]. |
2052 |
||
3059 | 2053 |
port := socketAddress port. |
2054 |
port == 0 ifTrue:[ |
|
5001 | 2055 |
"this is a bind to a random port, now we can get the real port" |
2056 |
port := self getFullSocketAddress port. |
|
3059 | 2057 |
]. |
1935 | 2058 |
^ true |
2059 |
||
2060 |
" |
|
3059 | 2061 |
(Socket domain:#'AF_INET' type:#stream) |
5001 | 2062 |
bindTo:(IPSocketAddress anyHost port:445) reuseAddress:false; |
2063 |
yourself. |
|
3059 | 2064 |
|
2065 |
(Socket domain:#'AF_INET' type:#stream) |
|
5001 | 2066 |
bindTo:139 reuseAddress:false; |
2067 |
yourself. |
|
3059 | 2068 |
|
2069 |
(Socket domain:#'AF_INET6' type:#stream) |
|
5001 | 2070 |
bindTo:nil reuseAddress:false; |
2071 |
yourself. |
|
3059 | 2072 |
|
2073 |
(Socket domain:#'AF_INET' type:#stream) |
|
5001 | 2074 |
bindTo:(IPSocketAddress localHost port:2122) reuseAddress:false; |
2075 |
yourself. |
|
3059 | 2076 |
|
2077 |
(Socket domain:#'AF_UNIX' type:#stream) |
|
5001 | 2078 |
bindTo:nil reuseAddress:false; |
2079 |
yourself. |
|
1935 | 2080 |
" |
4568 | 2081 |
|
2082 |
"Modified: / 19-01-2018 / 13:37:21 / stefan" |
|
4942 | 2083 |
"Modified (format): / 08-05-2019 / 14:41:18 / Claus Gittinger" |
1935 | 2084 |
! |
2085 |
||
2086 |
listenFor:aNumber |
|
4568 | 2087 |
"start listening; return true if ok, false on error. |
2088 |
Notify with a SocketErrorNotification on error. |
|
1935 | 2089 |
aNumber is the number of connect requests, that may be queued on the socket" |
2090 |
||
4568 | 2091 |
|err| |
2092 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2093 |
handle isNil ifTrue:[ |
5001 | 2094 |
^ self errorNotOpen |
1935 | 2095 |
]. |
2096 |
%{ |
|
2097 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2098 |
OBJ fp = __INST(handle); |
1935 | 2099 |
SOCKET sock; |
2100 |
int ret; |
|
2101 |
||
2102 |
if (! __isSmallInteger(aNumber)) { |
|
5001 | 2103 |
DBGPRINTF(("SOCKET: invalid arg\n")); |
2104 |
err = @symbol(badArgument); |
|
2105 |
goto out; |
|
1935 | 2106 |
} |
2107 |
||
2108 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2109 |
||
2110 |
#ifdef LISTEN_BLOCKS |
|
2111 |
# ifdef DO_WRAP_CALLS |
|
2112 |
do { |
|
5001 | 2113 |
__threadErrno = 0; |
2114 |
ret = STX_WSA_NOINT_CALL2("listen", listen, sock, __intVal(aNumber)); |
|
1935 | 2115 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3126 | 2116 |
if (ret < 0) { |
5001 | 2117 |
errno = __threadErrno; |
3126 | 2118 |
} |
1935 | 2119 |
# else |
2120 |
__BEGIN_INTERRUPTABLE__ |
|
2121 |
do { |
|
5001 | 2122 |
ret = listen(sock, __intVal(aNumber)); |
1935 | 2123 |
} while ((ret < 0) && (errno == EINTR)); |
2124 |
__END_INTERRUPTABLE__ |
|
2125 |
# endif |
|
2126 |
#else |
|
3126 | 2127 |
errno = 0; |
1935 | 2128 |
ret = listen(sock, __intVal(aNumber)); |
2129 |
#endif |
|
2130 |
||
2131 |
if (ret < 0) { |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2132 |
# ifdef __win32__ |
5001 | 2133 |
if (errno == 0) { |
2134 |
errno = WSAGetLastError(); |
|
2135 |
} |
|
3126 | 2136 |
# endif |
5001 | 2137 |
err = __MKSMALLINT(errno); |
2138 |
DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno)); |
|
2139 |
goto out; |
|
1935 | 2140 |
} |
2141 |
#else |
|
2142 |
RETURN (false); |
|
2143 |
#endif |
|
4568 | 2144 |
out:; |
1935 | 2145 |
%}. |
4568 | 2146 |
err notNil ifTrue:[ |
5001 | 2147 |
err isSymbol ifTrue:[ |
2148 |
self error:err. |
|
2149 |
]. |
|
2150 |
^ self reportError:err. |
|
4568 | 2151 |
]. |
2152 |
||
3157 | 2153 |
listening := aNumber. |
1935 | 2154 |
^ true |
4568 | 2155 |
|
2156 |
" |
|
2157 |
[ |
|
5001 | 2158 |
|sock| |
2159 |
sock := Socket newTCP. |
|
2160 |
sock listenFor:1. |
|
2161 |
sock |
|
4568 | 2162 |
] on:SocketErrorNotification do:[:ex| |
5001 | 2163 |
ex halt. |
4568 | 2164 |
]. |
2165 |
" |
|
2166 |
||
2167 |
"Modified (comment): / 19-01-2018 / 13:50:09 / stefan" |
|
1935 | 2168 |
! ! |
2169 |
||
1576
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2170 |
!Socket methodsFor:'closing'! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2171 |
|
4172 | 2172 |
abortAndClose |
2173 |
"immediately abort the connection: |
|
4414 | 2174 |
discard buffered data and close the stream" |
2175 |
||
2176 |
self linger:0. |
|
2177 |
self close. |
|
3224 | 2178 |
! |
2179 |
||
1885 | 2180 |
shutDown |
4414 | 2181 |
"shutDown (initiate a graceful close) |
4172 | 2182 |
and close (free the filedescriptor) the socket. |
4414 | 2183 |
The close will return immediately and buffered data will be sent in the |
4172 | 2184 |
background, unless you set linger" |
1885 | 2185 |
|
2186 |
self shutdown:2. |
|
2187 |
self close |
|
1576
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2188 |
! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2189 |
|
1885 | 2190 |
shutDownInput |
2191 |
"shutDown the input side of the socket. |
|
2192 |
Any read on the socket will signal end-of-file from now on. |
|
1839 | 2193 |
The other side MAY be informed, that no more data will be accepted |
1576
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2194 |
(e.g. setting the TCP-Windowsize to 0)" |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2195 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
2196 |
self shutdown:0. |
1885 | 2197 |
! |
2198 |
||
2199 |
shutDownOutput |
|
2200 |
"shutDown the output side of the socket. |
|
2201 |
Any write to the socket will signal end-of-file from now on. |
|
4172 | 2202 |
An orderly release (TCP FIN) will be initiated after the last buffered data |
2203 |
has been sent, so the other side will get a end-of-file condition eventually. |
|
4414 | 2204 |
If you set linger > 0, the operation will wait until buffered data |
4172 | 2205 |
has been delivered to the peer. |
2206 |
Otherwise the operation returns immediately." |
|
1343 | 2207 |
|
1884 | 2208 |
self shutdown:1. |
1885 | 2209 |
! ! |
2210 |
||
1935 | 2211 |
!Socket methodsFor:'connecting'! |
2212 |
||
3059 | 2213 |
connectTo:aSocketAddress |
2214 |
^ self connectTo:aSocketAddress withTimeout:nil |
|
2215 |
! |
|
2216 |
||
1935 | 2217 |
connectTo:hostOrPathName port:portNrOrName |
3655 | 2218 |
<resource: #obsolete> |
3059 | 2219 |
"Backward compatibility connect; connect to port, portNrOrNameOrNil on host, hostOrPathNameOrSocketAddr. |
2220 |
For backward compatibility, hostOrPathNameOrSocketAddr may be also a string or a byteArray, |
|
2221 |
but it is recommended to pass SocketAddress instances. |
|
1935 | 2222 |
|
2223 |
Return true if ok, false otherwise. |
|
2224 |
The current process will block (but not the whole Smalltalk) until the connection is established. |
|
2225 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
|
2226 |
||
2227 |
^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil |
|
2228 |
! |
|
2229 |
||
4570 | 2230 |
connectTo:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil withTimeout:milliSecondsOrTimeDuration |
3655 | 2231 |
<resource: #obsolete> |
3059 | 2232 |
"Backward compatibility connect; connect to port, portNrOrNameOrNil on host, hostOrPathNameOrSocketAddr. |
2233 |
For backward compatibility, hostOrPathNameOrSocketAddr may be also a string or a byteArray, |
|
2234 |
but it is recommended to pass SocketAddress instances. |
|
1935 | 2235 |
|
2236 |
Return true if ok, false otherwise. |
|
4568 | 2237 |
Notify with a SocketErrorNotification on error. |
2238 |
||
1935 | 2239 |
The current process will block (but not the whole Smalltalk) until the connection is established, |
4570 | 2240 |
or milliSecondsOrTimeDuration milliseconds have passed." |
1935 | 2241 |
|
3059 | 2242 |
|domainClass socketAddress| |
2243 |
||
2244 |
(hostOrPathNameOrSocketAddr isSocketAddress) ifTrue:[ |
|
5001 | 2245 |
socketAddress := hostOrPathNameOrSocketAddr. |
2246 |
portNrOrNameOrNil notNil ifTrue:[ |
|
2247 |
socketAddress port:portNrOrNameOrNil. |
|
2248 |
]. |
|
3059 | 2249 |
] ifFalse:[ |
5001 | 2250 |
"backward compatibility: support for byteArray and string arg" |
2251 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2252 |
domainClass isNil ifTrue:[ |
|
2253 |
^ self error:'invalid (unsupported) domain'. |
|
2254 |
]. |
|
2255 |
||
2256 |
hostOrPathNameOrSocketAddr isString ifTrue:[ |
|
2257 |
socketAddress := domainClass hostName:hostOrPathNameOrSocketAddr serviceName:portNrOrNameOrNil type:#SOCK_STREAM. |
|
2258 |
peerName := hostOrPathNameOrSocketAddr. |
|
2259 |
] ifFalse:[ |
|
2260 |
hostOrPathNameOrSocketAddr isByteCollection ifFalse:[ |
|
2261 |
^ self error:'connectTo: bad host (socketAddress) argument' |
|
2262 |
]. |
|
2263 |
socketAddress := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil. |
|
2264 |
]. |
|
3059 | 2265 |
]. |
2266 |
||
4570 | 2267 |
^ self connectTo:socketAddress withTimeout:milliSecondsOrTimeDuration. |
3059 | 2268 |
|
2269 |
" |
|
2270 |
|sock| |
|
2271 |
sock := Socket newTCP. |
|
2272 |
sock connectTo:'localhost' port:21 withTimeout:1000. |
|
2273 |
sock |
|
2274 |
||
2275 |
|sock| |
|
2276 |
sock := Socket newTCP. |
|
2277 |
sock connectTo:'localhost' port:9876 withTimeout:2000. |
|
2278 |
sock |
|
2279 |
" |
|
4568 | 2280 |
|
4570 | 2281 |
"Modified (comment): / 19-01-2018 / 17:48:08 / stefan" |
3059 | 2282 |
! |
2283 |
||
4570 | 2284 |
connectTo:aSocketAddress withTimeout:milliSecondsOrTimeDuration |
3059 | 2285 |
"Connect to a SocketAddress. |
2286 |
||
2287 |
Return true if ok, false otherwise. |
|
4568 | 2288 |
Notify with a SocketErrorNotification on error. |
2289 |
||
3059 | 2290 |
The current process will block (but not the whole Smalltalk) until the connection is established, |
4038 | 2291 |
or timeout milliseconds have passed." |
3059 | 2292 |
|
4570 | 2293 |
|isAsync err timeoutMs milliSeconds| |
1935 | 2294 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2295 |
handle isNil ifTrue:[ |
5001 | 2296 |
^ self errorNotOpen |
1935 | 2297 |
]. |
4234 | 2298 |
isAsync := false. |
1935 | 2299 |
|
2300 |
%{ /* STACK: 100000 */ |
|
2301 |
#ifndef NO_SOCKET |
|
3123 | 2302 |
//#define DUMP_ADDRESS 1 |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2303 |
OBJ fp = __INST(handle); |
1935 | 2304 |
union sockaddr_u sa; |
2305 |
SOCKET sock; |
|
2306 |
int a; |
|
2909 | 2307 |
INT ret; |
2308 |
int oldFlags; |
|
3741 | 2309 |
# ifdef __MINGW64__ |
2310 |
unsigned long on = 1; |
|
2311 |
# else |
|
1935 | 2312 |
int on = 1; |
3741 | 2313 |
#endif |
1935 | 2314 |
int sockaddr_size; |
2315 |
||
3059 | 2316 |
if (!__isNonNilObject(aSocketAddress) || !__isBytes(aSocketAddress)) { |
5001 | 2317 |
DBGPRINTF(("SOCKET: invalid socketAddress\n")); |
2318 |
err = @symbol(argumentError); |
|
2319 |
goto out; |
|
1935 | 2320 |
} |
2321 |
||
2322 |
{ |
|
5001 | 2323 |
int sockAddrOffs = 0; |
2324 |
int nIndex =__byteArraySize(aSocketAddress); |
|
2325 |
OBJ cls = __qClass(aSocketAddress); |
|
2326 |
||
2327 |
//if (cls != @global(ByteArray)) |
|
2328 |
// sockAddrOffs = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2329 |
sockaddr_size = nIndex - sockAddrOffs; |
|
2330 |
if (sockaddr_size > sizeof(sa)) { |
|
2331 |
DBGPRINTF(("SOCKET: invalid (short) socketAddress\n")); |
|
2332 |
err = @symbol(argumentError); |
|
2333 |
goto out; |
|
2334 |
} |
|
2335 |
memcpy(&sa, __byteArrayVal(aSocketAddress) + sockAddrOffs, sockaddr_size); |
|
1935 | 2336 |
} |
2337 |
||
2338 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2339 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2340 |
#ifdef __win32__ |
3657 | 2341 |
ioctlsocket(sock, FIONBIO, &on); |
2342 |
#elif defined(O_NONBLOCK) |
|
1935 | 2343 |
/* |
2344 |
* set to non-blocking and wait later |
|
2345 |
*/ |
|
2346 |
oldFlags = fcntl(sock, F_GETFL, 0); |
|
2347 |
/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */ |
|
2348 |
fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK); |
|
2349 |
# endif |
|
2350 |
||
2351 |
/* |
|
2352 |
* connect |
|
2353 |
*/ |
|
3123 | 2354 |
|
4039 | 2355 |
// we do not use wrap calls any longer, because they have problems with aborting. |
3657 | 2356 |
// we use nonblocking accept() instead. |
2357 |
# if 0 && defined(DO_WRAP_CALLS) |
|
3217 | 2358 |
// __setWrapCallDebugging(1,1); |
2414 | 2359 |
|
3123 | 2360 |
|
1935 | 2361 |
do { |
5001 | 2362 |
DBGFPRINTF((stderr, "SOCKET: (sock=%d) connect...\n", sock)); |
2363 |
ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, (INT)sockaddr_size); |
|
2364 |
DBGFPRINTF((stderr, "SOCKET: connect(%d) -> %"_ld_" (%d)\n", sock, (INT)ret, __threadErrno)); |
|
1935 | 2365 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3123 | 2366 |
|
3077 | 2367 |
if (ret < 0) { |
5001 | 2368 |
int optLen = sizeof(errno); |
2369 |
errno = __threadErrno; |
|
3123 | 2370 |
#if 0 |
5001 | 2371 |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &errno, &optLen) == SOCKET_ERROR) { |
2372 |
DBGFPRINTF((stderr, "SOCKET: getsockopt(SO_ERROR) failed: %d\n", WSAGetLastError())); |
|
2373 |
} |
|
3657 | 2374 |
#endif // 0 |
3077 | 2375 |
} |
2376 |
||
2377 |
// __setWrapCallDebugging(1,0); |
|
3657 | 2378 |
# else // !DO_WRAP_CALLS |
2379 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2380 |
# if !defined(__win32__) && !defined(O_NONBLOCK) |
1935 | 2381 |
__BEGIN_INTERRUPTABLE__ |
3657 | 2382 |
# endif |
1935 | 2383 |
do { |
5001 | 2384 |
ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size); |
1935 | 2385 |
} while ((ret < 0) |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2386 |
# ifdef __win32__ |
5001 | 2387 |
&& (errno = WSAGetLastError()) |
3657 | 2388 |
# endif |
5001 | 2389 |
&& ((errno == EINTR) |
3657 | 2390 |
# ifdef EAGAIN |
5001 | 2391 |
|| (errno == EAGAIN) |
3657 | 2392 |
# endif |
5001 | 2393 |
)); |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2394 |
# if !defined(__win32__) && !defined(O_NONBLOCK) |
1935 | 2395 |
__END_INTERRUPTABLE__ |
3657 | 2396 |
# endif |
2397 |
#endif |
|
2398 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2399 |
#if defined(__win32__) && !defined(EINPROGRESS) |
3657 | 2400 |
# define EINPROGRESSS WSAEINPROGRESSS |
2401 |
# define EALREADY WSAEALREADY |
|
1935 | 2402 |
#endif |
2403 |
||
2404 |
if (ret < 0) { |
|
2405 |
# if defined(EINPROGRESS) || defined(EALREADY) |
|
5001 | 2406 |
if (0 |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2407 |
# ifdef __win32__ |
5001 | 2408 |
|| (errno == WSAEWOULDBLOCK) |
3657 | 2409 |
# endif |
1935 | 2410 |
# ifdef EINPROGRESS |
5001 | 2411 |
|| (errno == EINPROGRESS) |
1935 | 2412 |
# endif |
2413 |
# ifdef EALREADY |
|
5001 | 2414 |
|| (errno == EALREADY) |
1935 | 2415 |
# endif |
5001 | 2416 |
) { |
2417 |
/* |
|
2418 |
* This was a nonblocking operation that will take some time. |
|
2419 |
* Do a select on read to get informed when the operation is ready. |
|
2420 |
*/ |
|
2421 |
DBGFPRINTF((stderr, "SOCKET: isAsync is true\n")); |
|
2422 |
isAsync = true; |
|
2423 |
} else |
|
1935 | 2424 |
# endif /* EINPROGRESS or EALREADY */ |
5001 | 2425 |
{ |
2426 |
DBGFPRINTF((stderr, "SOCKET: connect failed ret=%"_ld_" errno=%d __threadErrno=%d\n", |
|
2427 |
(INT)ret, errno, __threadErrno )); |
|
1935 | 2428 |
# ifdef DUMP_ADDRESS |
5001 | 2429 |
{ |
2430 |
unsigned char *cp = (unsigned char *)(&sa); |
|
2431 |
int i; |
|
2432 |
||
2433 |
console_printf("address data:\n"); |
|
2434 |
for (i=0; i<sockaddr_size; i++) { |
|
2435 |
console_printf(" %02x\n", *cp++); |
|
2436 |
} |
|
2437 |
} |
|
1935 | 2438 |
# endif |
5001 | 2439 |
err = __MKSMALLINT(errno); |
2440 |
} |
|
1935 | 2441 |
} |
2442 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
2443 |
# ifdef __win32__ |
3657 | 2444 |
{ |
5001 | 2445 |
int off = 0; |
2446 |
ioctlsocket(sock, FIONBIO, &off); |
|
3657 | 2447 |
} |
2448 |
# elif defined(O_NONBLOCK) // Linux / Unix |
|
1935 | 2449 |
fcntl(sock, F_SETFL, oldFlags); |
2450 |
# endif |
|
2451 |
||
2452 |
# else /* NO_SOCKET */ |
|
3077 | 2453 |
err = @symbol(notSupported); |
1935 | 2454 |
# endif /* NO_SOCKET */ |
3077 | 2455 |
out:; |
1935 | 2456 |
%}. |
3217 | 2457 |
|
3077 | 2458 |
err notNil ifTrue:[ |
5001 | 2459 |
err isSymbol ifTrue:[ |
2460 |
self primitiveFailed:err. |
|
2461 |
]. |
|
2462 |
^ self reportError:err. |
|
3077 | 2463 |
]. |
4234 | 2464 |
isAsync ifTrue:[ |
5001 | 2465 |
milliSeconds := milliSecondsOrTimeDuration. |
2466 |
milliSecondsOrTimeDuration isTimeDuration ifTrue:[ |
|
2467 |
milliSeconds := milliSecondsOrTimeDuration asMilliseconds. |
|
2468 |
]. |
|
2469 |
(self writeExceptionWaitWithTimeoutMs:milliSeconds) ifTrue:[ |
|
2470 |
"/ a timeout occurred |
|
2471 |
"/ should I cancel the connect? |
|
2472 |
^ self reportError:(OperatingSystem errorNumberFor:#ETIMEDOUT). |
|
2473 |
]. |
|
2474 |
err := self getSocketError. |
|
2475 |
err ~~ 0 ifTrue:[ |
|
2476 |
^ self reportError:err. |
|
2477 |
]. |
|
1935 | 2478 |
]. |
2479 |
||
1940
2ea7d2c1a2e6
changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents:
1939
diff
changeset
|
2480 |
|
3059 | 2481 |
peer := aSocketAddress. |
1935 | 2482 |
port isNil ifTrue:[ |
5001 | 2483 |
"socket has not been explicitly bound, |
2484 |
after connect it has been bound implicitly - fetch the port" |
|
2485 |
port := self getFullSocketAddress port. |
|
1935 | 2486 |
]. |
2487 |
^ true |
|
2488 |
||
2489 |
" |
|
2490 |
|sock| |
|
2491 |
sock := Socket newTCP. |
|
3059 | 2492 |
sock connectTo:(IPSocketAddress localHost port:21) withTimeout:1000. |
1935 | 2493 |
sock |
2494 |
||
4568 | 2495 |
[ |
5001 | 2496 |
|sock| |
2497 |
sock := Socket newTCP. |
|
2498 |
sock connectTo:(IPSocketAddress localHost port:21) withTimeout:1000. |
|
2499 |
sock |
|
4568 | 2500 |
] on:SocketErrorNotification do:[:ex| |
5001 | 2501 |
ex halt. |
4568 | 2502 |
]. |
2503 |
||
1935 | 2504 |
|sock| |
2505 |
sock := Socket newTCP. |
|
3059 | 2506 |
sock connectTo:(IPSocketAddress localHost port:9876) withTimeout:2000. |
1935 | 2507 |
sock |
2508 |
" |
|
4568 | 2509 |
|
4570 | 2510 |
"Modified: / 19-01-2018 / 17:57:36 / stefan" |
1935 | 2511 |
! ! |
2512 |
||
1885 | 2513 |
!Socket methodsFor:'datagram transmission'! |
2514 |
||
2515 |
receiveBuffer:aDataBuffer start:startIndex for:nBytes |
|
2516 |
"receive data |
|
4626 | 2517 |
Return the number of bytes received. |
1885 | 2518 |
The thread blocks until data arrives - you may want to wait before |
2519 |
receiving, using #readWait or #readWaitWithTimeout:." |
|
2520 |
||
3126 | 2521 |
|nReceived error| |
1885 | 2522 |
|
2523 |
%{ |
|
2524 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2525 |
OBJ fp = __INST(handle); |
1885 | 2526 |
|
2527 |
if (fp != nil) { |
|
5001 | 2528 |
SOCKET sock; |
2529 |
INT objSize, offs; |
|
2530 |
INT n; |
|
2531 |
char *extPtr; |
|
2532 |
unsigned char *buffer; |
|
2533 |
unsigned char *allocatedBuffer = NULL; |
|
2534 |
INT flags = 0; |
|
2535 |
||
2536 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2537 |
||
2538 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
|
2539 |
if (__isSmallInteger(nBytes)) { |
|
2540 |
if (__intVal(nBytes) < objSize) { |
|
2541 |
objSize = __intVal(nBytes); |
|
2542 |
} |
|
2543 |
} |
|
1885 | 2544 |
|
2545 |
# ifdef DO_WRAP_CALLS |
|
5001 | 2546 |
if (extPtr) { |
2547 |
buffer = extPtr + offs; |
|
2548 |
} else { |
|
2549 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
|
2550 |
} |
|
2551 |
||
2552 |
do { |
|
2553 |
__threadErrno = 0; |
|
2554 |
n = (INT)STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags); |
|
2555 |
} while ((n < 0) && (__threadErrno == EINTR)); |
|
2556 |
if (n < 0) { |
|
2557 |
errno = __threadErrno; |
|
2558 |
} |
|
2559 |
||
2560 |
if (allocatedBuffer) { |
|
2561 |
if (n > 0) { |
|
2562 |
memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, n); |
|
2563 |
} |
|
2564 |
free(allocatedBuffer); |
|
2565 |
} |
|
1885 | 2566 |
# else |
5001 | 2567 |
__BEGIN_INTERRUPTABLE__ |
2568 |
do { |
|
2569 |
if (extPtr) { |
|
2570 |
n = recv(sock, extPtr + offs, objSize, flags); |
|
2571 |
} else { |
|
2572 |
n = recv(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags); |
|
2573 |
} |
|
2574 |
} while ((n < 0) && (errno == EINTR)); |
|
2575 |
__END_INTERRUPTABLE__ |
|
1885 | 2576 |
# endif |
2577 |
||
5001 | 2578 |
if (n < 0) { |
2579 |
error = __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2580 |
} else { |
|
2581 |
RETURN(__MKSMALLINT(n)); |
|
2582 |
} |
|
1885 | 2583 |
} |
2584 |
#endif |
|
2585 |
bad: ; |
|
2586 |
%}. |
|
3126 | 2587 |
error notNil ifTrue:[ |
5001 | 2588 |
^ self readError:error. |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2589 |
]. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2590 |
" |
1282 | 2591 |
arrive here if you try to receive into an invalid buffer (i.e. not ByteArray-like) |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2592 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2593 |
self primitiveFailed |
4626 | 2594 |
|
2595 |
"Modified: / 21-03-2018 / 19:35:09 / stefan" |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2596 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2597 |
|
4626 | 2598 |
receiveFrom:aSocketAddress buffer:aDataBuffer |
2599 |
"receive datagramm data - put address of originating host into |
|
2600 |
aSocketAddress, data into aDataBuffer. |
|
2601 |
aDataBuffer must be ByteArray-like. |
|
2602 |
For backward compatibility, aSocketAddress may be a non-SocketAddress; |
|
2603 |
then, it must be a byteArray with appropriate size for the addressBytes. |
|
2604 |
||
2605 |
Return the number of bytes received. |
|
2606 |
The thread blocks until data arrives - you may want to wait before |
|
2607 |
receiving, using #readWait or #readWaitWithTimeout:." |
|
2608 |
||
2609 |
^ self receiveFrom:aSocketAddress buffer:aDataBuffer start:1 for:(aDataBuffer size) flags:0 |
|
2610 |
||
2611 |
"Modified (comment): / 21-03-2018 / 19:33:59 / stefan" |
|
3615 | 2612 |
! |
2613 |
||
4626 | 2614 |
receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes |
2615 |
^ self receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:0 |
|
2616 |
||
2617 |
"Modified (format): / 21-03-2018 / 19:32:27 / stefan" |
|
2618 |
! |
|
2619 |
||
2620 |
receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:flags |
|
1885 | 2621 |
"receive datagramm data |
4626 | 2622 |
- put address of originating host into aSocketAddress, data into aDataBuffer. |
2623 |
aDataBuffer must be ByteArray-like. |
|
2624 |
For backward compatibility, aSocketAddress may be a non-SocketAddress; |
|
1885 | 2625 |
then, it must be a byteArray with appropriate size for the addressBytes. |
2626 |
||
4626 | 2627 |
Return the number of bytes received. |
1885 | 2628 |
The thread blocks until data arrives - you may want to wait before |
2629 |
receiving, using #readWait or #readWaitWithTimeout:." |
|
2630 |
||
3126 | 2631 |
|domainClass addr addrLen nReceived error| |
1885 | 2632 |
|
2633 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2634 |
domainClass isNil ifTrue:[ |
|
5001 | 2635 |
^ self error:'invalid (unsupported) domain'. |
1885 | 2636 |
]. |
4626 | 2637 |
aSocketAddress isSocketAddress ifTrue:[ |
5001 | 2638 |
aSocketAddress class == domainClass ifFalse:[ |
2639 |
^ self error:'addressBuffer class mismatch (domain)'. |
|
2640 |
]. |
|
2641 |
addr := aSocketAddress. |
|
1885 | 2642 |
] ifFalse:[ |
5001 | 2643 |
aSocketAddress notNil ifTrue:[ |
2644 |
addr := domainClass new. |
|
2645 |
]. |
|
1885 | 2646 |
]. |
2647 |
||
2648 |
%{ |
|
2649 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2650 |
OBJ fp = __INST(handle); |
1885 | 2651 |
|
2652 |
if (fp != nil) { |
|
5001 | 2653 |
SOCKET sock; |
2654 |
size_t objSize; |
|
2655 |
union sockaddr_u sa; |
|
2656 |
socklen_t alen = 0; |
|
2657 |
INT n, offs; |
|
2658 |
int _flags = __longIntVal(flags); |
|
2659 |
char *extPtr; |
|
2660 |
unsigned char *allocatedBuffer = NULL, *buffer = NULL; |
|
2661 |
||
2662 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2663 |
||
2664 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
|
2665 |
if (__isSmallInteger(nBytes)) { |
|
2666 |
if (__intVal(nBytes) < objSize) { |
|
2667 |
objSize = __intVal(nBytes); |
|
2668 |
} |
|
2669 |
} |
|
1885 | 2670 |
# ifdef DO_WRAP_CALLS |
5001 | 2671 |
if (extPtr) { |
2672 |
buffer = extPtr + offs; |
|
2673 |
} else { |
|
2674 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
|
2675 |
} |
|
2676 |
||
2677 |
do { |
|
2678 |
__threadErrno = 0; |
|
2679 |
alen = sizeof(sa); |
|
2680 |
n = (INT)STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, _flags, (struct sockaddr *)&sa, &alen); |
|
2681 |
} while ((n < 0) && (__threadErrno == EINTR)); |
|
2682 |
if (n < 0) { |
|
2683 |
errno = __threadErrno; |
|
2684 |
} |
|
2685 |
||
2686 |
if (allocatedBuffer) { |
|
2687 |
if (n > 0) { |
|
2688 |
memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, n); |
|
2689 |
} |
|
2690 |
free(allocatedBuffer); |
|
2691 |
} |
|
1885 | 2692 |
# else |
5001 | 2693 |
__BEGIN_INTERRUPTABLE__ |
2694 |
do { |
|
2695 |
alen = sizeof(sa); |
|
2696 |
if (extPtr) { |
|
2697 |
n = recvfrom(sock, extPtr + offs, objSize, _flags, (struct sockaddr *) &sa, &alen); |
|
2698 |
} else { |
|
2699 |
n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, (struct sockaddr *) &sa, &alen); |
|
2700 |
} |
|
2701 |
} while ((n < 0) && (errno == EINTR)); |
|
2702 |
__END_INTERRUPTABLE__ |
|
1885 | 2703 |
# endif |
2704 |
||
5001 | 2705 |
if (n >= 0) { |
2706 |
if (__isNonNilObject(addr)) { |
|
2707 |
char *addrPtr; |
|
2708 |
OBJ oClass; |
|
2709 |
int nInstVars, nInstBytes, objSize; |
|
2710 |
||
2711 |
oClass = __qClass(addr); |
|
2712 |
if (! __isBytes(addr) ) |
|
2713 |
goto bad; |
|
2714 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2715 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
|
2716 |
objSize = __qSize(addr) - nInstBytes; |
|
2717 |
addrPtr = (char *)__InstPtr(addr) + nInstBytes; |
|
2718 |
if (objSize < alen) |
|
2719 |
goto bad; |
|
2720 |
||
2721 |
/* |
|
2722 |
* extract the datagrams address |
|
2723 |
*/ |
|
2724 |
memcpy(addrPtr, (char *)&sa, alen); |
|
2725 |
addrLen = __MKSMALLINT(alen); |
|
2726 |
} |
|
2727 |
} |
|
2728 |
if (n < 0) { |
|
2729 |
error = __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2730 |
} |
|
2731 |
nReceived = __MKSMALLINT(n); |
|
1885 | 2732 |
} |
2733 |
#endif |
|
2734 |
bad: ; |
|
2735 |
%}. |
|
3126 | 2736 |
error notNil ifTrue:[ |
5001 | 2737 |
^ self readError:error. |
3126 | 2738 |
]. |
2739 |
||
1885 | 2740 |
nReceived notNil ifTrue:[ |
5001 | 2741 |
addrLen notNil ifTrue:[ |
2742 |
(addr == aSocketAddress) ifFalse:[ |
|
2743 |
self obsoleteFeatureWarning:'please use a socketAddress argument'. |
|
2744 |
||
2745 |
"can be a ByteArray for backward compatibility" |
|
2746 |
aSocketAddress replaceFrom:1 to:addrLen with:(addr hostAddress). |
|
2747 |
]. |
|
2748 |
]. |
|
2749 |
^ nReceived |
|
1885 | 2750 |
]. |
2751 |
" |
|
2752 |
arrive here if you try to receive into an invalid buffer |
|
2753 |
(i.e. not ByteArray-like), |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2754 |
or if the addressBuffer is nonNil AND not a SocketAddress/ByteArray |
126 | 2755 |
or if the addressBuffer is nonNil AND too small. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2756 |
" |
126 | 2757 |
self primitiveFailed |
4626 | 2758 |
|
2759 |
"Modified (comment): / 21-03-2018 / 19:33:49 / stefan" |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2760 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2761 |
|
1885 | 2762 |
sendBuffer:aDataBuffer start:startIndex for:nBytes flags:flags |
4626 | 2763 |
"send data. aDataBuffer be ByteArray-like. |
2764 |
Return the number of bytes transmitted, or a negative number on error." |
|
1885 | 2765 |
|
3126 | 2766 |
|error| |
1885 | 2767 |
|
2768 |
%{ |
|
2769 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2770 |
OBJ fp = __INST(handle); |
1885 | 2771 |
|
2772 |
if ((fp != nil) |
|
2773 |
&& __isSmallInteger(startIndex) |
|
2774 |
&& __isSmallInteger(nBytes)) { |
|
5001 | 2775 |
SOCKET sock; |
2776 |
INT objSize, n, offs; |
|
2777 |
char *extPtr; |
|
2778 |
int _flags = __longIntVal(flags); |
|
2779 |
unsigned long norder; |
|
2780 |
unsigned char *buffer, *allocatedBuffer = NULL; |
|
2781 |
||
2782 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2783 |
||
2784 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
|
2785 |
if (__isSmallInteger(nBytes)) { |
|
2786 |
if (__intVal(nBytes) < objSize) { |
|
2787 |
objSize = __intVal(nBytes); |
|
2788 |
} |
|
2789 |
} |
|
1885 | 2790 |
|
2791 |
# ifdef DGRAM_DEBUG |
|
5001 | 2792 |
console_printf("sending %d bytes ...\n", nBytes); |
1885 | 2793 |
# endif |
2794 |
||
2795 |
#ifdef DO_WRAP_CALLS |
|
5001 | 2796 |
if (extPtr) { |
2797 |
buffer = extPtr + offs; |
|
2798 |
} else { |
|
2799 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
|
2800 |
memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize); |
|
2801 |
} |
|
2802 |
||
2803 |
do { |
|
2804 |
__threadErrno = 0; |
|
2805 |
n = (INT)STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags); |
|
2806 |
} while ((n < 0) && (__threadErrno == EINTR)); |
|
2807 |
if (n < 0) { |
|
2808 |
errno = __threadErrno; |
|
2809 |
} |
|
2810 |
||
2811 |
if (allocatedBuffer) { |
|
2812 |
free(allocatedBuffer); |
|
2813 |
} |
|
1885 | 2814 |
#else |
5001 | 2815 |
__BEGIN_INTERRUPTABLE__ |
2816 |
do { |
|
2817 |
if (extPtr) { |
|
2818 |
n = send(sock, extPtr + offs, objSize, _flags); |
|
2819 |
} else { |
|
2820 |
n = send(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags); |
|
2821 |
} |
|
2822 |
} while ((n < 0) && (errno == EINTR)); |
|
2823 |
__END_INTERRUPTABLE__ |
|
1885 | 2824 |
#endif |
2825 |
||
5001 | 2826 |
if (n < 0) { |
2827 |
error = __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2828 |
} else { |
|
2829 |
RETURN (__MKSMALLINT(n)); |
|
2830 |
} |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2831 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2832 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2833 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2834 |
%}. |
3126 | 2835 |
error notNil ifTrue:[ |
5001 | 2836 |
self writeError:error. |
3126 | 2837 |
]. |
2838 |
||
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2839 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2840 |
arrive here if you try to send from an invalid buffer (i.e. not ByteArray-like), |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2841 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2842 |
self primitiveFailed |
4626 | 2843 |
|
2844 |
"Modified: / 21-03-2018 / 19:22:52 / stefan" |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2845 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2846 |
|
4626 | 2847 |
sendTo:aSocketAddress buffer:buffer |
1885 | 2848 |
"send datagramm data - fetch address of destination host from |
4626 | 2849 |
aSocketAddress, data from aDataBuffer. |
5001 | 2850 |
aDataBuffer must be ByteArray-like. |
2851 |
aSocketAddress must be a valid SocketAddress for my domain |
|
4626 | 2852 |
(i.e. for IPv4, an IPSocketAddress). |
2853 |
For backward compatibility, a ByteArray is still supported in aSocketAddress |
|
2854 |
(i.e. for IPv4, a 4-byte byteArray). |
|
2855 |
Return the number of bytes transmitted." |
|
2856 |
||
2857 |
^ self sendTo:aSocketAddress buffer:buffer start:1 for:buffer size flags:0 |
|
2858 |
||
2859 |
"Modified (comment): / 21-03-2018 / 19:30:20 / stefan" |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2860 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2861 |
|
4626 | 2862 |
sendTo:aSocketAddress buffer:buffer start:startIndex for:count |
1885 | 2863 |
"send datagramm data - fetch address of destination host from |
4626 | 2864 |
aSocketAddress, data from aDataBuffer. |
5001 | 2865 |
aDataBuffer must be ByteArray-like. |
2866 |
aSocketAddress must be a valid SocketAddress for my domain |
|
4626 | 2867 |
(i.e. for IPv4, an IPSocketAddress). |
2868 |
For backward compatibility, a ByteArray is still supported in aSocketAddress |
|
2869 |
(i.e. for IPv4, a 4-byte byteArray). |
|
2870 |
Return the number of bytes transmitted." |
|
2871 |
||
2872 |
^ self sendTo:aSocketAddress buffer:buffer start:startIndex for:count flags:0 |
|
2873 |
||
2874 |
"Modified (comment): / 21-03-2018 / 19:29:07 / stefan" |
|
1885 | 2875 |
! |
2876 |
||
4626 | 2877 |
sendTo:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:flags |
1885 | 2878 |
"send datagramm data - fetch address of destination host from |
4626 | 2879 |
aSocketAddress, data from aDataBuffer starting at startIndex, |
1885 | 2880 |
sending count bytes. |
5001 | 2881 |
aDataBuffer must be ByteArray-like. |
2882 |
aSocketAddress must be a valid SocketAddress for my domain |
|
4626 | 2883 |
(i.e. for IPv4, an IPSocketAddress). |
2884 |
For backward compatibility, a ByteArray is still supported in aSocketAddress |
|
2885 |
(i.e. for IPv4, a 4-byte byteArray). |
|
2886 |
Return the number of bytes transmitted." |
|
1885 | 2887 |
|
3126 | 2888 |
|domainClass addr error| |
1885 | 2889 |
|
4626 | 2890 |
aSocketAddress isSocketAddress ifTrue:[ |
5001 | 2891 |
addr := aSocketAddress. |
1885 | 2892 |
] ifFalse:[ |
5001 | 2893 |
aSocketAddress isByteArray ifFalse:[ |
2894 |
^ self error:'bad socketAddress argument' |
|
2895 |
]. |
|
2896 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2897 |
domainClass isNil ifTrue:[ |
|
2898 |
^ self error:'invalid (unsupported) domain'. |
|
2899 |
]. |
|
2900 |
addr := domainClass hostAddress:aSocketAddress. |
|
1885 | 2901 |
]. |
2902 |
%{ |
|
2903 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
2904 |
OBJ fp = __INST(handle); |
1885 | 2905 |
|
2906 |
if ((fp != nil) |
|
2907 |
&& __isSmallInteger(startIndex) |
|
2908 |
&& __isSmallInteger(nBytes)) { |
|
5001 | 2909 |
SOCKET sock; |
2910 |
INT objSize; |
|
2911 |
struct sockaddr *sockaddr_ptr; |
|
2912 |
union sockaddr_u sa; |
|
2913 |
socklen_t sockaddr_size, alen = 0; |
|
2914 |
INT sockAddrOffs; |
|
2915 |
INT n, offs; |
|
2916 |
char *extPtr; |
|
2917 |
int _flags = __longIntVal(flags); |
|
2918 |
unsigned long norder; |
|
2919 |
unsigned char *buffer; |
|
2920 |
unsigned char *allocatedBuffer = NULL; |
|
2921 |
||
2922 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
2923 |
||
2924 |
if (! __isBytes(addr)) { |
|
2925 |
sockaddr_size = 0; |
|
2926 |
sockaddr_ptr = (struct sockaddr *)0; |
|
2927 |
} else { |
|
2928 |
int nIndex; |
|
2929 |
OBJ cls; |
|
2930 |
||
2931 |
sockAddrOffs = 0; |
|
2932 |
if ((cls = __qClass(addr)) != @global(ByteArray)) |
|
2933 |
sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2934 |
nIndex = __qSize(addr) - OHDR_SIZE; |
|
2935 |
sockaddr_size = nIndex - sockAddrOffs; |
|
2936 |
if (sockaddr_size > sizeof(sa)) { |
|
2937 |
console_fprintf(stderr, "Socket [warning]: bad socketAddr\n"); |
|
2938 |
goto bad; |
|
2939 |
} |
|
2940 |
memcpy(&sa, (__byteArrayVal(addr) + sockAddrOffs), sockaddr_size); |
|
2941 |
sockaddr_ptr = (struct sockaddr *)(&sa); |
|
2942 |
} |
|
2943 |
||
2944 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
|
2945 |
if (__isSmallInteger(nBytes)) { |
|
2946 |
if (__intVal(nBytes) < objSize) { |
|
2947 |
objSize = __intVal(nBytes); |
|
2948 |
} |
|
2949 |
} |
|
1885 | 2950 |
|
2951 |
#ifdef DO_WRAP_CALLS |
|
5001 | 2952 |
if (extPtr) { |
2953 |
buffer = extPtr + offs; |
|
2954 |
} else { |
|
2955 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
|
2956 |
memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize); |
|
2957 |
} |
|
2958 |
||
2959 |
do { |
|
2960 |
__threadErrno = 0; |
|
2961 |
n = (INT)STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size); |
|
2962 |
} while ((n < 0) && (__threadErrno == EINTR)); |
|
2963 |
if (n < 0) { |
|
2964 |
errno = __threadErrno; |
|
2965 |
} |
|
2966 |
||
2967 |
if (allocatedBuffer) { |
|
2968 |
free(allocatedBuffer); |
|
2969 |
} |
|
1885 | 2970 |
#else |
5001 | 2971 |
__BEGIN_INTERRUPTABLE__ |
2972 |
do { |
|
2973 |
if (extPtr) { |
|
2974 |
n = sendto(sock, extPtr + offs, objSize, _flags, sockaddr_ptr, sockaddr_size); |
|
2975 |
} else { |
|
2976 |
n = sendto(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, sockaddr_ptr, sockaddr_size); |
|
2977 |
} |
|
2978 |
} while ((n < 0) && (errno == EINTR)); |
|
2979 |
__END_INTERRUPTABLE__ |
|
1885 | 2980 |
#endif |
2981 |
||
5001 | 2982 |
if (n < 0) { |
2983 |
error = __INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2984 |
} else { |
|
2985 |
RETURN (__MKSMALLINT(n)); |
|
2986 |
} |
|
1885 | 2987 |
} |
2988 |
#endif |
|
2989 |
bad: ; |
|
2990 |
%}. |
|
3126 | 2991 |
error notNil ifTrue:[ |
5001 | 2992 |
self writeError:error. |
3126 | 2993 |
]. |
2994 |
||
1885 | 2995 |
" |
2996 |
arrive here if you try to send from an invalid buffer |
|
2997 |
(i.e. not ByteArray-like), |
|
2998 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2999 |
or if the addressBuffer is nonNil AND too small. |
|
3000 |
" |
|
3001 |
self primitiveFailed |
|
4626 | 3002 |
|
3003 |
"Modified: / 21-03-2018 / 19:27:51 / stefan" |
|
0 | 3004 |
! ! |
3005 |
||
4568 | 3006 |
!Socket methodsFor:'error reporting'! |
3007 |
||
3008 |
reportError:osErrorNumber |
|
3009 |
"report an error to the initiator of a Socket operation. |
|
3010 |
We raise a notification for newer code, and also |
|
3011 |
return false for old code not catching the notification." |
|
3012 |
||
3013 |
|errorHolder| |
|
3014 |
||
3015 |
lastErrorNumber := osErrorNumber. |
|
3016 |
||
3017 |
errorHolder := OperatingSystem errorHolderForNumber:osErrorNumber. |
|
3018 |
SocketErrorNotification raiseRequestWith:errorHolder. |
|
3019 |
||
3020 |
^ false. |
|
3021 |
||
3022 |
"Created: / 19-01-2018 / 12:50:00 / stefan" |
|
3023 |
! ! |
|
3024 |
||
4172 | 3025 |
!Socket methodsFor:'finalization'! |
3026 |
||
3027 |
finalize |
|
3028 |
self linger:0. "/ do an abortive release - discard buffered data |
|
3029 |
self closeFile. "/ does not wait due to abortive release. |
|
3030 |
! ! |
|
3031 |
||
3484 | 3032 |
!Socket methodsFor:'initialization'! |
3033 |
||
3034 |
initialize |
|
3035 |
super initialize. |
|
3036 |
"/ transparent |
|
3037 |
eolMode := nil. |
|
3038 |
! ! |
|
3039 |
||
3123 | 3040 |
!Socket methodsFor:'low level'! |
1885 | 3041 |
|
1935 | 3042 |
getSocketAdress |
3043 |
"BAD SPELLING, of #getSocketAddress, kept for compatibility with swazoo" |
|
3044 |
||
3045 |
<resource: #obsolete> |
|
3046 |
||
3047 |
^ self getSocketAddress |
|
3048 |
! |
|
3049 |
||
1885 | 3050 |
getSocketError |
3051 |
"get the SO_ERROR form the socket, which indicates the |
|
3052 |
result of an asynchronous operation" |
|
3053 |
||
3054 |
%{ |
|
3055 |
#ifndef NO_SOCKET |
|
3056 |
OBJ fp; |
|
3057 |
int err; |
|
3058 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3059 |
fp = __INST(handle); |
1885 | 3060 |
if (fp == nil) { |
3061 |
err = EBADF; |
|
3062 |
} else { |
|
3063 |
unsigned int sz; |
|
3064 |
SOCKET sock; |
|
3065 |
||
3066 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
3067 |
sz = sizeof(err); |
|
2909 | 3068 |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)(&err), &sz) < 0) { |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3069 |
# ifdef __win32__ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3070 |
errno = WSAGetLastError(); |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3071 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3072 |
err = errno; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3073 |
} |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3074 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3075 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3076 |
RETURN(__MKSMALLINT(err)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3077 |
#endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3078 |
%} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3079 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3080 |
|
1935 | 3081 |
listenWithBacklog:aNumber |
3082 |
<resource: #obsolete> |
|
3083 |
"same as listenFor: - backward compatibility with old ST/X" |
|
3059 | 3084 |
self obsoleteMethodWarning. |
1935 | 3085 |
^ self listenFor:aNumber |
1885 | 3086 |
! |
3087 |
||
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3088 |
primAcceptOn:aServerSocket blocking:blocking |
3059 | 3089 |
"accept a connection on a server port (created with:'Socket>>newTCP:') |
3090 |
usage is: (Socket basicNew acceptOn:(Socket newTCP:9999)). |
|
1935 | 3091 |
Return the true if ok; false if not. |
4568 | 3092 |
Notify with a SocketErrorNotification on error. |
3093 |
||
1935 | 3094 |
If blocking is true, the accept() syscall (and the whole smalltalk image) |
3095 |
will block, until a connection is accepted. |
|
3096 |
If blocking is false, this call will return immediately, if there is no connection pending." |
|
3097 |
||
4568 | 3098 |
|serverSocketHandle addr domainClass newHandle err| |
1935 | 3099 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3100 |
handle notNil ifTrue:[ |
5001 | 3101 |
^ self errorAlreadyOpen. |
4180 | 3102 |
]. |
3103 |
serverSocketHandle := aServerSocket fileHandle. |
|
3104 |
serverSocketHandle isNil ifTrue:[ |
|
5001 | 3105 |
"socket is not open" |
3106 |
^ self errorNotOpen |
|
1935 | 3107 |
]. |
3108 |
||
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3109 |
domain := aServerSocket domain. |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3110 |
socketType := aServerSocket type. |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3111 |
handleType := aServerSocket handleType. |
3059 | 3112 |
"unix domain sockets do not return a valid peer name on accept" |
1935 | 3113 |
domainClass := self class socketAddressClassForDomain:domain. |
3114 |
domainClass isNil ifTrue:[ |
|
5001 | 3115 |
^ self error:'invalid (unsupported) domain'. |
1935 | 3116 |
]. |
3117 |
addr := domainClass new. |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3118 |
newHandle := OperatingSystem socketAccessor new. |
1935 | 3119 |
|
3120 |
%{ /* STACK: 100000 */ |
|
1885 | 3121 |
#ifndef NO_SOCKET |
1935 | 3122 |
FILE *fp; |
3123 |
int flags; |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3124 |
SOCKET serverSocket, newSock; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3125 |
int _fd; |
1935 | 3126 |
union sockaddr_u sa; |
3059 | 3127 |
unsigned int alen; |
3128 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3129 |
# ifdef __win32__ |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3130 |
serverSocket = SOCKET_FROM_FILE_OBJECT(serverSocketHandle); |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3131 |
# else |
3247 | 3132 |
serverSocket = __intVal(serverSocketHandle); |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3133 |
# endif |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3134 |
|
1935 | 3135 |
# if defined(O_NONBLOCK) && defined(SET_NDELAY) |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3136 |
if (blocking == false) { |
5001 | 3137 |
flags = fcntl(serverSocket, F_GETFL); |
3138 |
fcntl(serverSocket, F_SETFL, flags | O_NONBLOCK); |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3139 |
} |
1935 | 3140 |
# endif |
3141 |
||
1885 | 3142 |
# ifdef DO_WRAP_CALLS |
3143 |
do { |
|
5001 | 3144 |
__threadErrno = 0; |
3145 |
alen = sizeof(sa); |
|
3146 |
newSock = (SOCKET)STX_WSA_CALL3("accept", accept, serverSocket, &sa, &alen); |
|
1935 | 3147 |
} while ((newSock < 0) && (__threadErrno == EINTR)); |
4568 | 3148 |
if (newSock == -1) { |
5001 | 3149 |
err = __MKSMALLINT(__threadErrno); |
3126 | 3150 |
} |
1885 | 3151 |
# else |
3152 |
__BEGIN_INTERRUPTABLE__ |
|
3153 |
do { |
|
5001 | 3154 |
alen = sizeof(sa); |
3155 |
newSock = accept(serverSocket, (struct sockaddr *) &sa, &alen); |
|
1935 | 3156 |
} while ((newSock < 0) && (errno == EINTR)); |
1885 | 3157 |
__END_INTERRUPTABLE__ |
4568 | 3158 |
if (newSock == -1) { |
5001 | 3159 |
err = __MKSMALLINT(errno); |
4568 | 3160 |
} |
1885 | 3161 |
# endif |
1935 | 3162 |
DBGFPRINTF((stderr, "SOCKET: accept newSock=%d\n", newSock)); |
3163 |
||
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3164 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
1935 | 3165 |
if (blocking == false) { |
5001 | 3166 |
fcntl(serverSocket, F_SETFL, flags); |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3167 |
} |
1935 | 3168 |
# endif |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3169 |
if (newSock == -1) { |
5001 | 3170 |
DBGPRINTF(("SOCKET: accept call failed errno=%d\n", (int)(__intVal(err)))); |
3171 |
goto out; |
|
1935 | 3172 |
} |
3173 |
||
3174 |
if (__isNonNilObject(addr)) { |
|
5001 | 3175 |
OBJ oClass = __qClass(addr); |
3176 |
int nInstVars, nInstBytes, objSize; |
|
3177 |
char *addrP; |
|
3178 |
||
3179 |
if (! __isBytes(addr)) { |
|
3180 |
DBGPRINTF(("SOCKET: bad addr\n")); |
|
3181 |
closesocket(newSock); |
|
3182 |
err = @symbol(badAddressArg); |
|
3183 |
goto out; |
|
3184 |
} |
|
3185 |
||
3186 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3187 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
|
3188 |
objSize = __qSize(addr) - nInstBytes; |
|
3189 |
addrP = (char *)__InstPtr(addr) + nInstBytes; |
|
3190 |
if (objSize < alen) { |
|
3191 |
DBGPRINTF(("SOCKET: bad addr\n")); |
|
3192 |
closesocket(newSock); |
|
3193 |
err = @symbol(badAddressArgLen); |
|
3194 |
goto out; |
|
3195 |
} |
|
3196 |
||
3197 |
/* |
|
3198 |
* extract the partners address |
|
3199 |
*/ |
|
3200 |
memcpy(addrP, (char *)&sa, alen); |
|
1935 | 3201 |
} |
3202 |
||
3203 |
/* |
|
3204 |
* make it a FILE * |
|
3205 |
*/ |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3206 |
# ifdef __win32__ |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3207 |
# if 0 && (defined( __BORLANDC__ ) || defined( __MINGW__ )) |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3208 |
__stxWrapApiEnterCritical(); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3209 |
_fd = _open_osfhandle((long)newSock, 0); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3210 |
__stxWrapApiLeaveCritical(); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3211 |
DBGPRINTF(("SOCKET: sock=%d fd=%d\n", newSock, _fd)); |
2773 | 3212 |
# else |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3213 |
_fd = (int)newSock; |
2773 | 3214 |
# endif |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3215 |
# else // ! __win32__ |
1935 | 3216 |
fp = fdopen(newSock, "r+"); |
3217 |
if (! fp) { |
|
5001 | 3218 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
3219 |
err = __MKSMALLINT(errno); |
|
3220 |
closesocket(newSock); |
|
3221 |
DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock)); |
|
3222 |
goto out; |
|
1935 | 3223 |
} |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3224 |
# endif // ! __win32__ |
1935 | 3225 |
|
3226 |
if ((@global(FileOpenTrace) == true) || __debugging__) { |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3227 |
# ifdef __win32__ |
5001 | 3228 |
console_fprintf(stderr, "fdopen [Socket accept] -> fd: %d (H: %"_lx_")\n", _fd, (INT)newSock); |
1935 | 3229 |
# else |
5001 | 3230 |
console_fprintf(stderr, "fdopen [Socket accept] -> %"_lx_" (fd: %d)\n", (INT)fp, newSock); |
1935 | 3231 |
# endif |
3232 |
} |
|
3233 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3234 |
# ifdef __win32__ |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3235 |
__externalAddressVal(newHandle) = _fd; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3236 |
__INST(handleType) = @symbol(socketHandle); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3237 |
# else |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3238 |
__externalAddressVal(newHandle) = fp; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3239 |
__INST(handleType) = @symbol(socketFilePointer); |
1935 | 3240 |
# endif |
3241 |
#endif /* not NO_SOCKET */ |
|
4568 | 3242 |
out:; |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3243 |
%}. |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3244 |
|
4568 | 3245 |
err notNil ifTrue:[ |
5001 | 3246 |
err isSymbol ifTrue:[ |
3247 |
self error:err. |
|
3248 |
]. |
|
3249 |
^ self reportError:err. |
|
4568 | 3250 |
]. |
3251 |
||
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3252 |
handle := newHandle. |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3253 |
buffered := false. |
1935 | 3254 |
mode := #readwrite. |
3255 |
binary := false. |
|
3620 | 3256 |
self registerForFinalization. |
3059 | 3257 |
peer := addr. |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3258 |
port := aServerSocket port. |
1935 | 3259 |
|
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3260 |
^ true |
4568 | 3261 |
|
3262 |
"Modified (comment): / 19-01-2018 / 13:35:57 / stefan" |
|
2551 | 3263 |
! |
1885 | 3264 |
|
3265 |
setSocketOption:option argument:arg1 argument:arg2 |
|
3513 | 3266 |
|ok error| |
1885 | 3267 |
|
2551 | 3268 |
handle isNil ifTrue:[ |
5001 | 3269 |
^ self errorNotOpen |
2551 | 3270 |
]. |
3271 |
||
1885 | 3272 |
%{ /* STACK: 32000 */ |
2818 | 3273 |
#ifndef NO_SOCKET |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3274 |
OBJ fp = __INST(handle); |
1885 | 3275 |
|
3276 |
if (fp != nil) { |
|
5001 | 3277 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(fp); |
3278 |
int opt = -1; |
|
3279 |
int level = -1; |
|
3280 |
int usize = -1; |
|
3281 |
int ret; |
|
3282 |
union u { |
|
3283 |
BOOL u_bool; |
|
3284 |
int u_int; |
|
3285 |
struct linger u_linger; |
|
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3286 |
# ifdef IP_ADD_MEMBERSHIP |
5001 | 3287 |
struct ip_mreq u_ip_mreq; |
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3288 |
# endif |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3289 |
# if defined(SO_RCVTIMEO) || defined(SO_SNDTIMEO) |
5001 | 3290 |
struct timeval u_tv; |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3291 |
# endif |
5001 | 3292 |
} u; |
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3293 |
|
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3294 |
# ifdef IP_ADD_MEMBERSHIP |
5001 | 3295 |
if (option == @symbol(IP_DROP_MEMBERSHIP)) { |
3296 |
opt = IP_DROP_MEMBERSHIP; |
|
3297 |
goto dropOrAdd; |
|
3298 |
} |
|
3299 |
if (option == @symbol(IP_ADD_MEMBERSHIP)) { |
|
3300 |
/* add membership to a multicast group */ |
|
3301 |
opt = IP_ADD_MEMBERSHIP; |
|
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3302 |
dropOrAdd: |
5001 | 3303 |
level = IPPROTO_IP; |
3304 |
usize = sizeof(u.u_ip_mreq); |
|
3305 |
if (__isByteArrayLike(arg1) && __isByteArrayLike(arg2)) { |
|
3306 |
memcpy(&u.u_ip_mreq.imr_multiaddr, __byteArrayVal(arg1), sizeof(u.u_ip_mreq.imr_multiaddr)); |
|
3307 |
memcpy(&u.u_ip_mreq.imr_interface, __byteArrayVal(arg2), sizeof(u.u_ip_mreq.imr_interface)); |
|
3308 |
// once we use the struct ip_mreqn: |
|
3309 |
// u.u_ip_mreqn.imr_ifindex = 0; |
|
3310 |
} |
|
3311 |
else |
|
3312 |
goto argError; |
|
3313 |
} |
|
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3314 |
# endif /* IP_ADD_MEMBERSHIP */ |
1885 | 3315 |
|
4738 | 3316 |
# ifdef IP_TTL |
5001 | 3317 |
if (option == @symbol(IP_TTL)) { |
3318 |
opt = IP_TTL; |
|
3319 |
level = IPPROTO_IP; |
|
3320 |
usize = sizeof(u.u_int); |
|
3321 |
if (__isSmallInteger(arg1))u.u_int = __intVal(arg1); |
|
3322 |
else goto argError; |
|
3323 |
} |
|
4738 | 3324 |
# endif /* IP_TTL */ |
3325 |
||
3326 |
# ifdef IP_MULTICAST_TTL |
|
5001 | 3327 |
if (option == @symbol(IP_MULTICAST_TTL)) { |
3328 |
opt = IP_MULTICAST_TTL; |
|
3329 |
level = IPPROTO_IP; |
|
3330 |
usize = sizeof(u.u_int); |
|
3331 |
if (__isSmallInteger(arg1))u.u_int = __intVal(arg1); |
|
3332 |
else goto argError; |
|
3333 |
} |
|
4738 | 3334 |
# endif /* IP_TTL */ |
3335 |
||
3336 |
||
1885 | 3337 |
# ifdef SO_BROADCAST |
5001 | 3338 |
if (option == @symbol(SO_BROADCAST)) { |
3339 |
/* Enables transmission and receipt of broadcast messages on the socket. */ |
|
3340 |
opt = SO_BROADCAST; |
|
3341 |
level = SOL_SOCKET; |
|
3342 |
usize = sizeof(u.u_bool); |
|
3343 |
if (arg1 == true) u.u_bool = TRUE; |
|
3344 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3345 |
else goto argError; |
|
3346 |
} |
|
1885 | 3347 |
# endif /* SO_BROADCAST */ |
3348 |
||
3349 |
# ifdef SO_CONDITIONAL |
|
3350 |
# if 0 |
|
5001 | 3351 |
if (option == @symbol(SO_CONDITIONAL)) { |
3352 |
/* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */ |
|
3353 |
opt = SO_CONDITIONAL; |
|
3354 |
level = SOL_SOCKET; |
|
3355 |
usize = sizeof(u.u_bool); |
|
3356 |
if (arg1 == true) u.u_bool = TRUE; |
|
3357 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3358 |
else goto argError; |
|
3359 |
} |
|
1885 | 3360 |
# endif |
3361 |
# endif /* SO_CONDITIONAL */ |
|
3362 |
||
3363 |
# ifdef SO_DEBUG |
|
5001 | 3364 |
if (option == @symbol(SO_DEBUG)) { |
3365 |
/* Records debugging information. */ |
|
3366 |
opt = SO_DEBUG; |
|
3367 |
level = SOL_SOCKET; |
|
3368 |
usize = sizeof(u.u_bool); |
|
3369 |
if (arg1 == true) u.u_bool = TRUE; |
|
3370 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3371 |
else goto argError; |
|
3372 |
} |
|
1885 | 3373 |
# endif /* SO_DEBUG */ |
3374 |
||
3375 |
# ifdef SO_DONTLINGER |
|
5001 | 3376 |
if (option == @symbol(SO_DONTLINGER)) { |
3377 |
/* Does not block close waiting for unsent data to be sent. |
|
3378 |
Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */ |
|
3379 |
opt = SO_DONTLINGER; |
|
3380 |
level = SOL_SOCKET; |
|
3381 |
usize = sizeof(u.u_bool); |
|
3382 |
if (arg1 == true) u.u_bool = TRUE; |
|
3383 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3384 |
else goto argError; |
|
3385 |
} |
|
1885 | 3386 |
# endif /* SO_DONTLINGER */ |
3387 |
||
3388 |
# ifdef SO_DONTROUTE |
|
5001 | 3389 |
if (option == @symbol(SO_DONTROUTE)) { |
3390 |
/* Does not route: sends directly to interface. |
|
3391 |
Succeeds but is ignored on AF_INET sockets; |
|
3392 |
fails on AF_INET6 sockets with WSAENOPROTOOPT. |
|
3393 |
Not supported on ATM sockets (results in an error). */ |
|
3394 |
opt = SO_DONTROUTE; |
|
3395 |
level = SOL_SOCKET; |
|
3396 |
usize = sizeof(u.u_bool); |
|
3397 |
if (arg1 == true) u.u_bool = TRUE; |
|
3398 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3399 |
else goto argError; |
|
3400 |
} |
|
1885 | 3401 |
# endif /* SO_DONTROUTE */ |
3402 |
||
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3403 |
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY) |
5001 | 3404 |
if (option == @symbol(TCP_NODELAY)) { |
3405 |
/* enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) */ |
|
3406 |
opt = TCP_NODELAY; |
|
3407 |
level = IPPROTO_TCP; |
|
3408 |
usize = sizeof(u.u_bool); |
|
3409 |
if (arg1 == true) u.u_bool = TRUE; |
|
3410 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3411 |
else goto argError; |
|
3412 |
} |
|
2516
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3413 |
# endif /* TCP_NODELAY */ |
592619f82885
Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents:
2465
diff
changeset
|
3414 |
|
1885 | 3415 |
# ifdef SO_KEEPALIVE |
5001 | 3416 |
if (option == @symbol(SO_KEEPALIVE)) { |
3417 |
/* Sends keep-alives. Not supported on ATM sockets (results in an error). */ |
|
3418 |
opt = SO_KEEPALIVE; |
|
3419 |
level = SOL_SOCKET; |
|
3420 |
usize = sizeof(u.u_bool); |
|
3421 |
if (arg1 == true) u.u_bool = TRUE; |
|
3422 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3423 |
else goto argError; |
|
3424 |
} |
|
1885 | 3425 |
# endif /* SO_KEEPALIVE */ |
3426 |
||
3427 |
# ifdef SO_LINGER |
|
5001 | 3428 |
if (option == @symbol(SO_LINGER)) { |
3429 |
/* Lingers on close if unsent data is present. */ |
|
3430 |
opt = SO_LINGER; |
|
3431 |
level = SOL_SOCKET; |
|
3432 |
usize = sizeof(u.u_linger); |
|
3433 |
if (arg1 == true) u.u_linger.l_onoff = TRUE; |
|
3434 |
else if (arg1 == false) u.u_linger.l_onoff = FALSE; |
|
3435 |
else goto argError; |
|
3436 |
if (arg2 == nil) u.u_linger.l_linger = 0; |
|
3437 |
else if (__isSmallInteger(arg2))u.u_linger.l_linger = __intVal(arg2); |
|
3438 |
else goto argError; |
|
3439 |
DBGPRINTF(("SOCKET: SO_LINGER %d %d\n", u.u_linger.l_onoff, u.u_linger.l_linger)); |
|
3440 |
} |
|
1885 | 3441 |
# endif /* SO_LINGER */ |
3442 |
||
3443 |
# ifdef SO_OOBINLINE |
|
5001 | 3444 |
if (option == @symbol(SO_OOBINLINE)) { |
3445 |
/* Receives OOB data in the normal data stream. */ |
|
3446 |
opt = SO_OOBINLINE; |
|
3447 |
level = SOL_SOCKET; |
|
3448 |
usize = sizeof(u.u_bool); |
|
3449 |
if (arg1 == true) u.u_bool = TRUE; |
|
3450 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3451 |
else goto argError; |
|
3452 |
} |
|
1885 | 3453 |
# endif /* SO_OOBINLINE */ |
3454 |
||
3455 |
# ifdef SO_RCVBUF |
|
5001 | 3456 |
if (option == @symbol(SO_RCVBUF)) { |
3457 |
/* Specifies the total per-socket buffer space reserved for receives. |
|
3458 |
This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */ |
|
3459 |
opt = SO_RCVBUF; |
|
3460 |
level = SOL_SOCKET; |
|
3461 |
usize = sizeof(u.u_int); |
|
3462 |
if (__isSmallInteger(arg1))u.u_int = __intVal(arg1); |
|
3463 |
else goto argError; |
|
3464 |
} |
|
1885 | 3465 |
# endif /* SO_RCVBUF */ |
3466 |
||
3467 |
# ifdef SO_SNDBUF |
|
5001 | 3468 |
if (option == @symbol(SO_SNDBUF)) { |
3469 |
/* Specifies the total per-socket buffer space reserved for sends. |
|
3470 |
This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */ |
|
3471 |
opt = SO_SNDBUF; |
|
3472 |
level = SOL_SOCKET; |
|
3473 |
usize = sizeof(u.u_int); |
|
3474 |
if (__isSmallInteger(arg1))u.u_int = __intVal(arg1); |
|
3475 |
else goto argError; |
|
3476 |
} |
|
1885 | 3477 |
# endif /* SO_SNDBUF */ |
3478 |
||
3479 |
# ifdef SO_REUSEADDR |
|
5001 | 3480 |
if (option == @symbol(SO_REUSEADDR)) { |
3481 |
/* Allows the socket to be bound to an address that is already in use. */ |
|
3482 |
opt = SO_REUSEADDR; |
|
3483 |
level = SOL_SOCKET; |
|
3484 |
usize = sizeof(u.u_bool); |
|
3485 |
if (arg1 == true) u.u_bool = TRUE; |
|
3486 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3487 |
else goto argError; |
|
3488 |
} |
|
1885 | 3489 |
# endif /* SO_OOBINLINE */ |
3490 |
||
3491 |
# ifdef SO_EXCLUSIVEADDRUSE |
|
5001 | 3492 |
if (option == @symbol(SO_EXCLUSIVEADDRUSE)) { |
3493 |
/* Enables a socket to be bound for exclusive access. |
|
3494 |
Does not require administrative privilege. */ |
|
3495 |
opt = SO_EXCLUSIVEADDRUSE; |
|
3496 |
level = SOL_SOCKET; |
|
3497 |
usize = sizeof(u.u_bool); |
|
3498 |
if (arg1 == true) u.u_bool = TRUE; |
|
3499 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3500 |
else goto argError; |
|
3501 |
} |
|
1885 | 3502 |
# endif /* SO_OOBINLINE */ |
3503 |
||
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3504 |
# ifdef SO_RCVTIMEO |
5001 | 3505 |
if ((option == @symbol(SO_RCVTIMEO)) |
3506 |
&& __isSmallInteger(arg1) |
|
3507 |
&& __isSmallInteger(arg2)) { |
|
3508 |
opt = SO_RCVTIMEO; |
|
3509 |
level = SOL_SOCKET; |
|
3510 |
u.u_tv.tv_sec = __intVal(arg1); |
|
3511 |
u.u_tv.tv_usec = __intVal(arg2); |
|
3512 |
usize = sizeof(u.u_tv); |
|
3513 |
} |
|
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3514 |
# endif /* SO_RCVTIMEO */ |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3515 |
|
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3516 |
# ifdef SO_SNDTIMEO |
5001 | 3517 |
if ((option == @symbol(SO_SNDTIMEO)) |
3518 |
&& __isSmallInteger(arg1) |
|
3519 |
&& __isSmallInteger(arg2)) { |
|
3520 |
opt = SO_SNDTIMEO; |
|
3521 |
level = SOL_SOCKET; |
|
3522 |
u.u_tv.tv_sec = __intVal(arg1); |
|
3523 |
u.u_tv.tv_usec = __intVal(arg2); |
|
3524 |
usize = sizeof(u.u_tv); |
|
3525 |
} |
|
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3526 |
# endif /* SO_SNDTIMEO */ |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3527 |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3528 |
# if !defined(IPV6_V6ONLY) && defined(__win32__) |
3513 | 3529 |
# define IPPROTO_IPV6 41 |
3530 |
# define IPV6_V6ONLY 27 |
|
3531 |
# endif |
|
3532 |
||
3533 |
# if defined(IPV6_V6ONLY) |
|
5001 | 3534 |
if (option == @symbol(IPV6_V6ONLY)) { |
3535 |
opt = IPV6_V6ONLY; |
|
3536 |
level = IPPROTO_IPV6; |
|
3537 |
usize = sizeof(u.u_bool); |
|
3538 |
if (arg1 == true) u.u_bool = TRUE; |
|
3539 |
else if (arg1 == false) u.u_bool = FALSE; |
|
3540 |
else goto argError; |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3541 |
# ifdef __win32__ |
5001 | 3542 |
console_fprintf(stderr, "%d %d %d %d\n", level, opt, usize, u.u_int); |
3514
2d81c5ffa475
win32_printf is only avail in: guess what
Claus Gittinger <cg@exept.de>
parents:
3513
diff
changeset
|
3543 |
# endif |
5001 | 3544 |
} |
3513 | 3545 |
# endif /* IPV6_V6ONLY */ |
3546 |
||
5001 | 3547 |
if (usize == -1) goto argError; |
3548 |
||
3549 |
ok = (setsockopt(sock, level, opt, (char *)&u, usize) >= 0) ? true : false; |
|
3550 |
if (ok == false) { |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3551 |
# ifdef __win32__ |
5001 | 3552 |
error = __mkSmallInteger(WSAGetLastError()); |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3553 |
# else |
5001 | 3554 |
error = __mkSmallInteger(errno); |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3555 |
# endif |
5001 | 3556 |
} |
3513 | 3557 |
|
1885 | 3558 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3559 |
argError: ; |
2818 | 3560 |
#endif /* NO_SOCKET */ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3561 |
%}. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3562 |
ok isNil ifTrue:[ |
5001 | 3563 |
self primitiveFailed |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3564 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3565 |
ok ifFalse:[ |
5001 | 3566 |
'++++ Info: Socket>>#setSocketOption:... failed. error: ' infoPrint. error infoPrintCR. |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3567 |
]. |
2551 | 3568 |
! |
1885 | 3569 |
|
2823
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
3570 |
shutdown:howNum |
1885 | 3571 |
"shutDown the socket - inform it that no more I/O will be performed. |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3572 |
0 - read side (no further reads) |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3573 |
the tcp receive window is closed, so the peer cannot send more data. |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3574 |
1 - write side (no further writes) |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3575 |
first, all queued data will be delivered to the peer. |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3576 |
Then, an orderly release (TCP FIN) is sent to signal the peer, |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3577 |
that we will not send more data. |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3578 |
2 - both read side and write side." |
1885 | 3579 |
|
3580 |
%{ |
|
3581 |
#ifndef NO_SOCKET |
|
2823
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
3582 |
OBJ __handle = __INST(handle); |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3583 |
|
2823
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
3584 |
if ((__handle != nil) && __isSmallInteger(howNum)) { |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3585 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(__handle); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3586 |
INT how = __intVal(howNum); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3587 |
INT ret; |
2823
10179ccfae5d
Default for close - linger in background instead 30s in foreground
Stefan Vogel <sv@exept.de>
parents:
2818
diff
changeset
|
3588 |
|
1885 | 3589 |
# ifdef DO_WRAP_CALLS |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3590 |
do { |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3591 |
__threadErrno = 0; |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3592 |
DBGFPRINTF((stderr, "SOCKET: shutDown...\n")); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3593 |
ret = (INT)STX_WSA_NOINT_CALL2("shutdown", shutdown, sock, how); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3594 |
DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno)); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3595 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3596 |
# else |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3597 |
__BEGIN_INTERRUPTABLE__ |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3598 |
shutdown(sock, how); |
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
3599 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3600 |
# endif |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3601 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3602 |
#endif |
1339 | 3603 |
%}. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3604 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3605 |
|
1885 | 3606 |
!Socket methodsFor:'printing & storing'! |
3607 |
||
3608 |
printOn:aStream |
|
3530 | 3609 |
aStream nextPutAll:self className; nextPutAll:'('. |
3610 |
domain printOn:aStream. |
|
3611 |
aStream nextPutAll:' protocol='. |
|
1885 | 3612 |
protocol printOn:aStream. |
4736 | 3613 |
aStream nextPutAll:' type='. |
3614 |
socketType printOn:aStream. |
|
1885 | 3615 |
aStream nextPutAll:' port='. |
1935 | 3616 |
self port printOn:aStream. |
4636 | 3617 |
peer notNil ifTrue:[ |
5001 | 3618 |
aStream nextPutAll:' peer='. |
3619 |
peer printOn:aStream. |
|
4636 | 3620 |
]. |
3621 |
listening notNil ifTrue:[ |
|
5001 | 3622 |
aStream nextPutAll:' *listening('. |
3623 |
listening printOn:aStream. |
|
3624 |
aStream nextPutAll:')*'. |
|
4636 | 3625 |
]. |
1842 | 3626 |
aStream nextPut:$). |
4636 | 3627 |
|
3628 |
"Modified: / 23-04-2018 / 19:44:24 / stefan" |
|
4736 | 3629 |
"Modified: / 19-09-2018 / 18:30:20 / Claus Gittinger" |
1885 | 3630 |
! ! |
3631 |
||
3632 |
!Socket methodsFor:'queries'! |
|
3633 |
||
3634 |
domain |
|
3059 | 3635 |
"return the sockets addressing domain (i.e. #AF_INET, #AF_INET6, #AF_UNIX, ...)" |
1885 | 3636 |
|
3637 |
^ domain |
|
126 | 3638 |
! |
3639 |
||
3059 | 3640 |
getFullPeerAddress |
1935 | 3641 |
"implemented for swazoo project (primitive code can't be loaded as extension) |
1885 | 3642 |
Answer my own address (I am bound to this address). |
3643 |
Note that this address may change after a connect or accept." |
|
3644 |
||
3059 | 3645 |
|error domainClass addr| |
1885 | 3646 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3647 |
handle isNil ifTrue:[ |
3217 | 3648 |
^ self errorNotOpen |
1885 | 3649 |
]. |
3650 |
||
3651 |
domainClass := self class socketAddressClassForDomain:domain. |
|
3652 |
domainClass isNil ifTrue:[ |
|
3217 | 3653 |
^ self error:'invalid (unsupported) domain'. |
1885 | 3654 |
]. |
3655 |
addr := domainClass new. |
|
3656 |
||
3657 |
%{ |
|
3658 |
#ifndef NO_SOCKET |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3659 |
OBJ fp = __INST(handle); |
1885 | 3660 |
SOCKET sock; |
3661 |
int ret; |
|
3662 |
union sockaddr_u sa; |
|
3059 | 3663 |
unsigned int alen = sizeof(sa); |
1885 | 3664 |
char *addrP; |
3665 |
int addrObjSize, nAddrInstBytes; |
|
3059 | 3666 |
OBJ addrClass; |
3667 |
int nAddrInstVars; |
|
1885 | 3668 |
|
3669 |
if (!__isNonNilObject(addr) || !__isBytes(addr)) { |
|
3217 | 3670 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3671 |
error = @symbol(badArgument); |
|
3672 |
goto err; |
|
3059 | 3673 |
} |
3674 |
||
3675 |
addrClass = __qClass(addr); |
|
3676 |
nAddrInstVars = __intVal(__ClassInstPtr(addrClass)->c_ninstvars); |
|
3677 |
nAddrInstBytes = OHDR_SIZE + (nAddrInstVars * sizeof(OBJ)); |
|
3678 |
addrObjSize = __qSize(addr) - nAddrInstBytes; |
|
3679 |
||
3680 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
3681 |
ret = getpeername(sock, (struct sockaddr *)&sa, &alen); |
|
3682 |
if (ret < 0) { |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3683 |
# ifdef __win32__ |
3217 | 3684 |
errno = WSAGetLastError(); |
3059 | 3685 |
# endif |
3217 | 3686 |
DBGPRINTF(("SOCKET: getsocketname failed ret=%d errno=%d\n", ret, errno)); |
3687 |
error = __MKSMALLINT(errno); |
|
3688 |
goto err; |
|
3059 | 3689 |
} |
3690 |
||
3691 |
if (addrObjSize < alen) { |
|
3217 | 3692 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3693 |
error = @symbol(badArgument); |
|
3694 |
goto err; |
|
3059 | 3695 |
} |
3696 |
||
3697 |
addrP = (char *)__InstPtr(addr) + nAddrInstBytes; |
|
3698 |
memcpy(addrP, (char *)&sa, alen); |
|
3699 |
||
3700 |
err:; |
|
3701 |
#else /* NO_SOCKET */ |
|
3702 |
error = @symbol(notImplemented); |
|
3703 |
#endif /* NO_SOCKET */ |
|
3704 |
%}. |
|
3705 |
error notNil ifTrue:[ |
|
3217 | 3706 |
^ self errorReporter reportOn:error |
3059 | 3707 |
]. |
3708 |
^ addr |
|
3709 |
! |
|
3710 |
||
3711 |
getFullSocketAddress |
|
3712 |
"implemented for swazoo project (primitive code can't be loaded as extension) |
|
3713 |
Answer my own address (I am bound to this address). |
|
3714 |
Note that this address may change after a connect or accept." |
|
3715 |
||
3716 |
|error domainClass addr| |
|
3717 |
||
3718 |
handle isNil ifTrue:[ |
|
3217 | 3719 |
^ self errorNotOpen |
3059 | 3720 |
]. |
3721 |
||
3722 |
domainClass := self class socketAddressClassForDomain:domain. |
|
3723 |
domainClass isNil ifTrue:[ |
|
3217 | 3724 |
^ self error:'invalid (unsupported) domain'. |
3059 | 3725 |
]. |
3726 |
addr := domainClass new. |
|
3727 |
||
3728 |
%{ |
|
3729 |
#ifndef NO_SOCKET |
|
3730 |
OBJ fp = __INST(handle); |
|
3731 |
SOCKET sock; |
|
3732 |
int ret; |
|
3733 |
union sockaddr_u sa; |
|
3734 |
unsigned int alen = sizeof(sa); |
|
3735 |
char *addrP; |
|
3736 |
int addrObjSize, nAddrInstBytes; |
|
3737 |
||
3738 |
if (!__isNonNilObject(addr) || !__isBytes(addr)) { |
|
3217 | 3739 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3740 |
error = @symbol(badArgument); |
|
3741 |
goto err; |
|
1885 | 3742 |
} |
3743 |
||
3744 |
{ |
|
3217 | 3745 |
OBJ addrClass; |
3746 |
int nAddrInstVars; |
|
3747 |
||
3748 |
addrClass = __qClass(addr); |
|
3749 |
nAddrInstVars = __intVal(__ClassInstPtr(addrClass)->c_ninstvars); |
|
3750 |
nAddrInstBytes = OHDR_SIZE + (nAddrInstVars * sizeof(OBJ)); |
|
3751 |
addrObjSize = __qSize(addr) - nAddrInstBytes; |
|
1885 | 3752 |
} |
3753 |
||
3754 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
3755 |
ret = getsockname(sock, (struct sockaddr *)&sa, &alen); |
|
3756 |
if (ret < 0) { |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3757 |
# ifdef __win32__ |
3217 | 3758 |
errno = WSAGetLastError(); |
1885 | 3759 |
# endif |
3217 | 3760 |
DBGPRINTF(("SOCKET: getsocketname failed ret=%d errno=%d\n", ret, errno)); |
3761 |
error = __MKSMALLINT(errno); |
|
3762 |
goto err; |
|
1885 | 3763 |
} |
3764 |
||
3765 |
if (addrObjSize < alen) { |
|
3217 | 3766 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3767 |
error = @symbol(badArgument); |
|
3768 |
goto err; |
|
1885 | 3769 |
} |
3770 |
||
3771 |
addrP = (char *)__InstPtr(addr) + nAddrInstBytes; |
|
3059 | 3772 |
memcpy(addrP, (char *)&sa, alen); |
1535 | 3773 |
|
3774 |
err:; |
|
3775 |
#else /* NO_SOCKET */ |
|
3776 |
error = @symbol(notImplemented); |
|
3777 |
#endif /* NO_SOCKET */ |
|
3778 |
%}. |
|
3779 |
error notNil ifTrue:[ |
|
3217 | 3780 |
^ self errorReporter reportOn:error |
1535 | 3781 |
]. |
3782 |
^ addr |
|
3783 |
! |
|
3784 |
||
1885 | 3785 |
getName |
3786 |
"return the name; here, we return the ports name" |
|
3787 |
||
1935 | 3788 |
^ self port printString |
126 | 3789 |
! |
3790 |
||
1885 | 3791 |
getPeer |
3792 |
"ST-80 compatibility: return an IPSocketAddress instance representing |
|
3793 |
my hostname/port combination. |
|
3794 |
If you are interested in the hostname, use getPeerName directly." |
|
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3795 |
|
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3796 |
^ peer |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3797 |
! |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3798 |
|
1885 | 3799 |
getPeerName |
4091 | 3800 |
"return the peer name; that's the hostname (or dotted name) of the |
25 | 3801 |
partners host after an accept." |
3802 |
||
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3803 |
peerName isNil ifTrue:[ |
4414 | 3804 |
peerName := self class peerNameFromDomain:domain peer:peer. |
1187
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3805 |
]. |
25 | 3806 |
^ peerName |
28 | 3807 |
! |
3808 |
||
1885 | 3809 |
getSocketAddress |
3810 |
"implemented for swazoo project primitive code cant load as extension |
|
3811 |
answer my own address (I am bound to this address). |
|
1146 | 3812 |
Note that this address may change after connect or accept." |
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
3813 |
|
1535 | 3814 |
^ self getFullSocketAddress hostAddress |
1146 | 3815 |
! |
3816 |
||
1885 | 3817 |
isActive |
4795 | 3818 |
"return true, if the receiver has a connection or is bound or listening" |
1885 | 3819 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3820 |
^ handle notNil |
4795 | 3821 |
|
3822 |
"Modified (comment): / 05-02-2019 / 17:19:35 / Stefan Vogel" |
|
1885 | 3823 |
! |
3824 |
||
3825 |
isConnected |
|
3826 |
"return true, if the receiver has a connection" |
|
3827 |
||
3828 |
^ self isActive |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3829 |
and:[peer notNil] |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3830 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3831 |
|
1885 | 3832 |
port |
1935 | 3833 |
"return the port number (or name for unix-sockets) to which the socket is bound |
3834 |
- so this is the local port." |
|
3835 |
||
3836 |
"/ port isNil ifTrue:[ |
|
3837 |
"/ port := self getFullSocketAddress port. |
|
1505 | 3838 |
"/ ]. |
1935 | 3839 |
|
71 | 3840 |
^ port |
1885 | 3841 |
! |
3842 |
||
3059 | 3843 |
socketAddressClass |
4288 | 3844 |
"get the matching SocketAddress class for this socket" |
3059 | 3845 |
|
3846 |
|domainClass| |
|
3847 |
||
3848 |
domainClass := self class socketAddressClassForDomain:domain. |
|
3849 |
domainClass isNil ifTrue:[ |
|
4414 | 3850 |
^ self error:'invalid (unsupported) domain'. |
3059 | 3851 |
]. |
3852 |
^ domainClass. |
|
3853 |
! |
|
3854 |
||
1885 | 3855 |
type |
3856 |
"return the sockets connection type (i.e. #datagram, #stream etc)" |
|
3857 |
||
3858 |
^ socketType |
|
81 | 3859 |
! ! |
3860 |
||
126 | 3861 |
!Socket methodsFor:'socket setup'! |
3862 |
||
1885 | 3863 |
domain:domainArg type:typeArg |
3864 |
"set up socket with domain and type. |
|
3865 |
This is a low level entry; no binding, listening or connect |
|
3866 |
is done. Both arguments must be symbols from one of |
|
3059 | 3867 |
#AF_INET, #AF_INET6, #AF_UNIX ... and #stream, #datagram, #raw resp." |
126 | 3868 |
|
3137 | 3869 |
^ self domain:domainArg type:typeArg protocol:nil |
126 | 3870 |
! |
3871 |
||
1885 | 3872 |
domain:domainArg type:typeArg protocol:protocolNumber |
3873 |
"set up socket with domain, type and protocol number. |
|
3874 |
This is a low level entry; no binding, listening or connect |
|
3875 |
is done. Both arguments must be symbols from one of |
|
3059 | 3876 |
#AF_INET, #AF_INET6, #AF_UNIX ... and #stream, #datagram, #raw resp." |
1885 | 3877 |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3878 |
|domainName domainCode typeCode error newHandle| |
1885 | 3879 |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
3880 |
handle notNil ifTrue:[ |
4414 | 3881 |
^ self errorAlreadyOpen |
1885 | 3882 |
]. |
3883 |
domainName := SocketAddress domainCodeFromName:domainArg. |
|
3884 |
domainCode := OperatingSystem domainCodeOf:domainName. |
|
3885 |
typeCode := OperatingSystem socketTypeCodeOf:typeArg. |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3886 |
newHandle := OperatingSystem socketAccessor new. |
1885 | 3887 |
%{ |
3888 |
#ifndef NO_SOCKET |
|
3889 |
FILE *fp; |
|
3137 | 3890 |
int dom, typ, proto = 0; |
1885 | 3891 |
int on = 1; |
3892 |
SOCKET sock; |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3893 |
int _fd; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3894 |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3895 |
# ifdef __win32__ |
3123 | 3896 |
# ifndef WSA_FLAG_NO_HANDLE_INHERIT |
3897 |
# define WSA_FLAG_NO_HANDLE_INHERIT 0x80 |
|
3898 |
# endif |
|
3899 |
static int noInheritFlag = WSA_FLAG_NO_HANDLE_INHERIT; |
|
3900 |
# endif |
|
1885 | 3901 |
|
3902 |
if (! __isSmallInteger(domainCode)) { |
|
4414 | 3903 |
error = @symbol(badArgument1); |
3904 |
goto out; |
|
1885 | 3905 |
} |
3906 |
if (! __isSmallInteger(typeCode)) { |
|
4414 | 3907 |
error = @symbol(badArgument2); |
3908 |
goto out; |
|
1885 | 3909 |
} |
3910 |
if (protocolNumber != nil) { |
|
4414 | 3911 |
if (!__isSmallInteger(protocolNumber)) { |
3912 |
error = @symbol(badArgument3); |
|
3913 |
goto out; |
|
3914 |
} |
|
3915 |
proto = __intVal(protocolNumber); |
|
1885 | 3916 |
} |
3917 |
||
3918 |
/* |
|
3919 |
* get address and protocol-family |
|
3920 |
*/ |
|
3921 |
dom = __intVal(domainCode); |
|
3922 |
typ = __intVal(typeCode); |
|
3923 |
||
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3924 |
# ifdef __win32__ |
3123 | 3925 |
sock = WSASocket(dom, typ, proto, 0, 0, noInheritFlag); |
3926 |
if (sock == INVALID_SOCKET && noInheritFlag) { |
|
4414 | 3927 |
// tried to open socket with WSA_FLAG_NO_HANDLE_INHERIT |
3928 |
// This fails on older windows versions, e.g. Windows XP |
|
3929 |
sock = WSASocket(dom, typ, proto, 0, 0, 0); |
|
3930 |
if (sock != INVALID_SOCKET) { |
|
3931 |
// no error without WSA_FLAG_NO_HANDLE_INHERIT, |
|
3932 |
// never use this flag again! |
|
3933 |
noInheritFlag = 0; |
|
3934 |
} |
|
3123 | 3935 |
} |
3936 |
if (sock == INVALID_SOCKET) { |
|
4414 | 3937 |
errno = WSAGetLastError(); |
3123 | 3938 |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3939 |
# else // !__win32__ |
3123 | 3940 |
|
1885 | 3941 |
sock = socket(dom, typ, proto); |
3123 | 3942 |
# if defined(EPROTONOSUPPORT) /* for SGI */ |
3943 |
if ((sock < 0) && (proto != 0) && (errno == EPROTONOSUPPORT)) { |
|
4414 | 3944 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
3945 |
proto = 0; |
|
3946 |
sock = socket(dom, typ, 0); |
|
1885 | 3947 |
} |
3948 |
# endif |
|
3123 | 3949 |
if (sock < 0) { |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3950 |
# endif // !__win32__ |
3123 | 3951 |
|
4414 | 3952 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno)); |
3953 |
error = __MKSMALLINT(errno); |
|
1885 | 3954 |
} else { |
3123 | 3955 |
# if defined(SET_LINGER_WHEN_CREATING_SOCKET) && defined(SO_LINGER) |
4414 | 3956 |
{ |
3957 |
struct linger l; |
|
3958 |
||
3959 |
l.l_onoff = 1; |
|
3960 |
l.l_linger = 30; |
|
3961 |
setsockopt(sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l)); |
|
3962 |
} |
|
1885 | 3963 |
# endif |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3964 |
# ifdef __win32__ |
4414 | 3965 |
/* |
3966 |
* make it blocking |
|
3967 |
*/ |
|
3968 |
{ |
|
3969 |
unsigned long zero = 0; |
|
3970 |
ioctlsocket(sock, FIONBIO, &zero); |
|
3971 |
} |
|
3972 |
{ |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3973 |
# if 0 && (defined( __BORLANDC__ ) || defined( __MINGW__ )) |
4414 | 3974 |
/* |
3975 |
* make it a FILE * |
|
3976 |
*/ |
|
3977 |
__stxWrapApiEnterCritical(); |
|
3978 |
_fd = _open_osfhandle((long)sock, 0); |
|
3979 |
__stxWrapApiLeaveCritical(); |
|
2773 | 3980 |
# else |
4414 | 3981 |
_fd = (int)sock; |
2773 | 3982 |
# endif |
4414 | 3983 |
DBGPRINTF(("SOCKET: sock=%d fd=%d\n", sock, _fd)); |
3984 |
} |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3985 |
# else // !__win32__ |
4414 | 3986 |
fp = fdopen(sock, "r+"); |
3987 |
if (! fp) { |
|
3988 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
3989 |
error = __MKSMALLINT(errno); |
|
3990 |
__BEGIN_INTERRUPTABLE__ |
|
3991 |
closesocket(sock); |
|
3992 |
DBGFPRINTF((stderr, "SOCKET: fdopen failed (%d)\n", sock)); |
|
3993 |
__END_INTERRUPTABLE__ |
|
3994 |
goto out; |
|
3995 |
} |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3996 |
# endif // !__win32__ |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
3997 |
|
4414 | 3998 |
if (@global(FileOpenTrace) == true) { |
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
3999 |
# ifdef __win32__ |
4414 | 4000 |
console_fprintf(stderr, "fdopen [Socket create] -> fd: %d (H: %"_lx_")\n", (INT)_fd, (INT)sock); |
3223 | 4001 |
# else |
4414 | 4002 |
console_fprintf(stderr, "fdopen [Socket] -> %"_lx_" (fd: %d)\n", (INT)fp, sock); |
3223 | 4003 |
# endif |
4414 | 4004 |
} |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4005 |
|
3843
fbced69597a7
oops - error check was disabled
Claus Gittinger <cg@exept.de>
parents:
3742
diff
changeset
|
4006 |
# ifdef __win32__ |
4414 | 4007 |
__externalAddressVal(newHandle) = _fd; |
4008 |
__INST(handleType) = @symbol(socketHandle); |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4009 |
# else |
4414 | 4010 |
__externalAddressVal(newHandle) = fp; |
4011 |
__INST(handleType) = @symbol(socketFilePointer); |
|
1885 | 4012 |
# endif |
4013 |
} |
|
4014 |
#endif |
|
4015 |
out:; |
|
4016 |
%}. |
|
4017 |
||
4018 |
"all ok?" |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4019 |
handleType notNil ifTrue:[ |
4414 | 4020 |
handle := newHandle. |
4021 |
domain := domainArg. |
|
4022 |
socketType := typeArg. |
|
4023 |
self registerForFinalization. |
|
4024 |
^ self. |
|
1885 | 4025 |
]. |
3217 | 4026 |
error isInteger ifTrue:[ |
4414 | 4027 |
lastErrorNumber := error. |
4028 |
^ self openError:error. |
|
3217 | 4029 |
]. |
4030 |
^ self primitiveFailed:error. |
|
126 | 4031 |
|
4032 |
" |
|
3059 | 4033 |
Socket new domain:#AF_INET type:#stream |
4034 |
Socket new domain:#AF_UNIX type:#stream |
|
126 | 4035 |
" |
28 | 4036 |
! ! |
4037 |
||
4736 | 4038 |
|
28 | 4039 |
!Socket methodsFor:'specials'! |
4040 |
||
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
4041 |
linger:anIntegerOrNil |
3224 | 4042 |
"set the linger behavior on close: |
4043 |
anIntegerOrNil == nil: close returns immediately, socket tries |
|
5001 | 4044 |
to send buffered data in background. |
3224 | 4045 |
anIntegerOrNil == 0: close returns immediately, bufferd data is discarded. |
4046 |
anIntegerOrNil > 0: close waits this many seconds for buffered data |
|
5001 | 4047 |
to be delivered, after this time buffered data is |
4048 |
discarded and close returns with an error. |
|
4796 | 4049 |
(returns false, if unsupported)" |
3467
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
4050 |
|
24d35ef42e17
socket options rcvtimeout and sndtimeout added
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
4051 |
^ self |
5001 | 4052 |
setSocketOption:#'SO_LINGER' |
4053 |
argument:anIntegerOrNil notNil |
|
4054 |
argument:anIntegerOrNil. |
|
4796 | 4055 |
|
4056 |
"Modified (comment): / 08-02-2019 / 22:33:14 / Claus Gittinger" |
|
3224 | 4057 |
! |
4058 |
||
1885 | 4059 |
receiveBufferSize |
4060 |
"get the send buffer size - for special applications only. |
|
4061 |
Not all operatingSystems offer this functionality |
|
4062 |
(returns nil, if unsupported)" |
|
4063 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4064 |
handle isNil ifTrue:[ |
1885 | 4065 |
^ self errorNotOpen |
1335 | 4066 |
]. |
1885 | 4067 |
%{ |
4068 |
#if defined(SO_RCVBUF) && defined(SOL_SOCKET) |
|
4069 |
{ |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4070 |
OBJ fp = __INST(handle); |
1885 | 4071 |
SOCKET sock; |
4072 |
int opt; |
|
4073 |
unsigned int size; |
|
4074 |
||
4075 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4076 |
if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &size) >= 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4077 |
RETURN( __MKSMALLINT(opt) ); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4078 |
} |
1335 | 4079 |
} |
4080 |
#endif |
|
4081 |
%}. |
|
4082 |
^ nil |
|
4083 |
! |
|
4084 |
||
1885 | 4085 |
receiveBufferSize:size |
4086 |
"set the receive buffer size - for special applications only. |
|
4087 |
Not all operatingSystems offer this functionality |
|
4088 |
(returns false, if unsupported)" |
|
4089 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4090 |
handle isNil ifTrue:[ |
1885 | 4091 |
^ self errorNotOpen |
4092 |
]. |
|
4093 |
%{ |
|
4094 |
#if defined(SO_RCVBUF) && defined(SOL_SOCKET) |
|
4095 |
if (__isSmallInteger(size)) { |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4096 |
OBJ fp = __INST(handle); |
1885 | 4097 |
SOCKET sock; |
4098 |
int opt; |
|
4099 |
||
4100 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
1343 | 4101 |
opt = __intVal(size); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4102 |
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, sizeof(int)) >= 0 ) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4103 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4104 |
} |
1335 | 4105 |
} |
4106 |
#endif |
|
4107 |
%}. |
|
4108 |
^ false |
|
4109 |
! |
|
4110 |
||
1885 | 4111 |
receiveTimeout |
4112 |
"get the receive timeout in millis - for special applications only. |
|
4113 |
Not all operatingSystems offer this functionality |
|
4114 |
(returns nil, if unsupported)" |
|
4115 |
||
4116 |
|millis| |
|
4117 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4118 |
handle isNil ifTrue:[ |
5001 | 4119 |
^ self errorNotOpen |
1885 | 4120 |
]. |
4121 |
%{ |
|
4122 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4123 |
OBJ fp = __INST(handle); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4124 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(fp); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4125 |
int len; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4126 |
int __millis; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4127 |
struct timeval tv = {0, 0}; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4128 |
|
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4129 |
len = sizeof(struct timeval); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4130 |
if (getsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, &len) == 0) { |
5001 | 4131 |
__millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); |
4132 |
millis = __mkSmallInteger(__millis); |
|
1885 | 4133 |
# if 0 |
5001 | 4134 |
console_fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis); |
1885 | 4135 |
# endif |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4136 |
} else { |
5001 | 4137 |
console_fprintf(stderr, "Socket [warning]: getsockopt %d failed; errno=%d\n", sock, errno); |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4138 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4139 |
#endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4140 |
%}. |
4570 | 4141 |
^ millis |
4142 |
||
4143 |
" |
|
5001 | 4144 |
Socket newTCP receiveTimeout |
4570 | 4145 |
" |
4146 |
||
4147 |
"Modified: / 19-01-2018 / 19:15:17 / stefan" |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4148 |
! |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4149 |
|
4570 | 4150 |
receiveTimeout:secondsOrTimeDuration |
1885 | 4151 |
"set the receive timeout - for special applications only. |
4152 |
Not all operatingSystems offer this functionality |
|
4570 | 4153 |
(returns false, if unsupported). |
4154 |
||
4155 |
From linux manpage: |
|
5001 | 4156 |
SO_RCVTIMEO and SO_SNDTIMEO |
4157 |
Specify the receiving or sending timeouts until reporting an error. The argument is a |
|
4158 |
struct timeval. If an input or output function blocks for this period of time, and data has |
|
4159 |
been sent or received, the return value of that function will be the amount of data trans- |
|
4160 |
ferred; if no data has been transferred and the timeout has been reached, then -1 is |
|
4161 |
returned with errno set to EAGAIN or EWOULDBLOCK, or EINPROGRESS (for connect(2)) just as if |
|
4162 |
the socket was specified to be nonblocking. If the timeout is set to zero (the default), |
|
4163 |
then the operation will never timeout. Timeouts only have effect for system calls that per- |
|
4164 |
form socket I/O (e.g., read(2), recvmsg(2), send(2), sendmsg(2)); timeouts have no effect |
|
4165 |
for select(2), poll(2), epoll_wait(2), and so on." |
|
1885 | 4166 |
|
4167 |
|millis| |
|
4168 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4169 |
handle isNil ifTrue:[ |
5001 | 4170 |
^ self errorNotOpen |
1885 | 4171 |
]. |
4570 | 4172 |
secondsOrTimeDuration isTimeDuration ifTrue:[ |
5001 | 4173 |
millis := secondsOrTimeDuration getMilliseconds. |
4570 | 4174 |
] ifFalse:[ |
5001 | 4175 |
millis := (secondsOrTimeDuration * 1000) rounded. |
4570 | 4176 |
]. |
4177 |
||
1885 | 4178 |
%{ |
4179 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) |
|
4180 |
if (__isSmallInteger(millis)) { |
|
5001 | 4181 |
OBJ fp = __INST(handle); |
4182 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
4183 |
int __millis = __intVal(millis); |
|
4184 |
struct timeval tv = {0, 0}; |
|
4185 |
||
4186 |
tv.tv_sec = __millis / 1000; |
|
4187 |
tv.tv_usec = (__millis % 1000) * 1000; |
|
1885 | 4188 |
# if 0 |
5001 | 4189 |
console_fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec); |
1885 | 4190 |
# endif |
5001 | 4191 |
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) { |
4192 |
RETURN(true); |
|
4193 |
} |
|
4194 |
console_fprintf(stderr, "Socket [warning]: setsockopt %d failed; errno=%d\n", sock, errno); |
|
28 | 4195 |
} |
4196 |
#endif |
|
71 | 4197 |
%}. |
28 | 4198 |
^ false |
4570 | 4199 |
|
4200 |
" |
|
5001 | 4201 |
Socket newTCP |
4202 |
receiveTimeout:5s; |
|
4203 |
receiveTimeout |
|
4570 | 4204 |
" |
4205 |
||
4206 |
"Modified (comment): / 19-01-2018 / 19:14:49 / stefan" |
|
81 | 4207 |
! |
4208 |
||
1885 | 4209 |
sendBufferSize |
4210 |
"get the send buffer size - for special applications only. |
|
4211 |
Not all operatingSystems offer this functionality |
|
4212 |
(returns nil, if unsupported)" |
|
4213 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4214 |
handle isNil ifTrue:[ |
1885 | 4215 |
^ self errorNotOpen |
4216 |
]. |
|
4217 |
%{ |
|
4218 |
#if defined(SO_SNDBUF) && defined(SOL_SOCKET) |
|
4219 |
{ |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4220 |
OBJ fp = __INST(handle); |
1885 | 4221 |
SOCKET sock; |
4222 |
int opt; |
|
4223 |
unsigned int size; |
|
4224 |
||
4225 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4226 |
if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, &size) >= 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4227 |
RETURN( __MKSMALLINT(opt) ); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4228 |
} |
1335 | 4229 |
} |
4230 |
#endif |
|
4231 |
%}. |
|
4232 |
^ nil |
|
4233 |
! |
|
4234 |
||
1885 | 4235 |
sendBufferSize:size |
4236 |
"set the send buffer size - for special applications only. |
|
4237 |
Not all operatingSystems offer this functionality |
|
4238 |
(returns false, if unsupported)" |
|
4239 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4240 |
handle isNil ifTrue:[ |
1885 | 4241 |
^ self errorNotOpen |
4242 |
]. |
|
4243 |
%{ |
|
4244 |
#if defined(SO_SNDBUF) && defined(SOL_SOCKET) |
|
4245 |
if (__isSmallInteger(size)) { |
|
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4246 |
OBJ fp = __INST(handle); |
1885 | 4247 |
SOCKET sock; |
4248 |
int opt; |
|
4249 |
||
4250 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
1343 | 4251 |
opt = __intVal(size); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4252 |
if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, sizeof(int)) >= 0) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4253 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4254 |
} |
1335 | 4255 |
} |
4256 |
#endif |
|
4257 |
%}. |
|
4258 |
^ false |
|
4259 |
! |
|
4260 |
||
1885 | 4261 |
sendTimeout |
4262 |
"get the send timeout in millis - for special applications only. |
|
4263 |
Not all operatingSystems offer this functionality |
|
4264 |
(returns nil, if unsupported)" |
|
4265 |
||
4266 |
|millis| |
|
4267 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4268 |
handle isNil ifTrue:[ |
5001 | 4269 |
^ self errorNotOpen |
1885 | 4270 |
]. |
4271 |
%{ |
|
4272 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) |
|
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4273 |
OBJ fp = __INST(handle); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4274 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(fp); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4275 |
int len; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4276 |
int __millis; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4277 |
struct timeval tv = {0, 0}; |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4278 |
|
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4279 |
len = sizeof(struct timeval); |
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4280 |
if (getsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, &len) == 0) { |
5001 | 4281 |
__millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); |
4282 |
millis = __mkSmallInteger(__millis); |
|
1885 | 4283 |
# if 0 |
5001 | 4284 |
console_fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis); |
1885 | 4285 |
# endif |
3246
c75a006f9a7a
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
3224
diff
changeset
|
4286 |
} else { |
5001 | 4287 |
console_fprintf(stderr, "Socket [warning]: getsockopt %d failed; errno=%d\n", sock, errno); |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4288 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4289 |
#endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4290 |
%}. |
4570 | 4291 |
^ millis |
4292 |
||
4293 |
" |
|
5001 | 4294 |
Socket newTCP sendTimeout |
4570 | 4295 |
" |
4296 |
||
4297 |
"Modified (comment): / 19-01-2018 / 19:16:23 / stefan" |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4298 |
! |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4299 |
|
4570 | 4300 |
sendTimeout:secondsOrTimeDuration |
1885 | 4301 |
"set the send timeout - for special applications only. |
4302 |
Not all operatingSystems offer this functionality |
|
4570 | 4303 |
(returns false, if unsupported). |
4304 |
From linux manpage: |
|
5001 | 4305 |
SO_RCVTIMEO and SO_SNDTIMEO |
4306 |
Specify the receiving or sending timeouts until reporting an error. The argument is a |
|
4307 |
struct timeval. If an input or output function blocks for this period of time, and data has |
|
4308 |
been sent or received, the return value of that function will be the amount of data trans- |
|
4309 |
ferred; if no data has been transferred and the timeout has been reached, then -1 is |
|
4310 |
returned with errno set to EAGAIN or EWOULDBLOCK, or EINPROGRESS (for connect(2)) just as if |
|
4311 |
the socket was specified to be nonblocking. If the timeout is set to zero (the default), |
|
4312 |
then the operation will never timeout. Timeouts only have effect for system calls that per- |
|
4313 |
form socket I/O (e.g., read(2), recvmsg(2), send(2), sendmsg(2)); timeouts have no effect |
|
4314 |
for select(2), poll(2), epoll_wait(2), and so on." |
|
1885 | 4315 |
|
4316 |
|millis| |
|
4317 |
||
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
2308
diff
changeset
|
4318 |
handle isNil ifTrue:[ |
5001 | 4319 |
^ self errorNotOpen |
1885 | 4320 |
]. |
4570 | 4321 |
secondsOrTimeDuration isTimeDuration ifTrue:[ |
5001 | 4322 |
millis := secondsOrTimeDuration getMilliseconds. |
4570 | 4323 |
] ifFalse:[ |
5001 | 4324 |
millis := (secondsOrTimeDuration * 1000) rounded. |
4570 | 4325 |
]. |
1885 | 4326 |
%{ |
4327 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) |
|
4328 |
if (__isSmallInteger(millis)) { |
|
5001 | 4329 |
OBJ fp = __INST(handle); |
4330 |
SOCKET sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
4331 |
int __millis = __intVal(millis); |
|
4332 |
struct timeval tv = {0, 0}; |
|
4333 |
||
4334 |
tv.tv_sec = __millis / 1000; |
|
4335 |
tv.tv_usec = (__millis % 1000) * 1000; |
|
1885 | 4336 |
# if 0 |
5001 | 4337 |
console_fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec); |
1885 | 4338 |
# endif |
5001 | 4339 |
if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) { |
4340 |
RETURN(true); |
|
4341 |
} |
|
4342 |
console_fprintf(stderr, "Socket [warning]: setsockopt %d failed; errno=%d\n", sock, errno); |
|
126 | 4343 |
} |
4344 |
#endif |
|
4345 |
%}. |
|
4346 |
^ false |
|
4570 | 4347 |
|
4348 |
" |
|
5001 | 4349 |
Socket newTCP |
4350 |
sendTimeout:5s; |
|
4351 |
sendTimeout |
|
4570 | 4352 |
" |
4353 |
||
4354 |
"Modified (comment): / 19-01-2018 / 19:12:51 / stefan" |
|
1340 | 4355 |
! |
4356 |
||
1885 | 4357 |
setTCPCork:aBoolean |
4358 |
"enable/disable TCP_CORK (do-not-send-partial-frames) |
|
4359 |
For special applications only. |
|
4360 |
Not all OperatingSystems offer this functionality |
|
4361 |
(returns false, if unsupported)" |
|
4362 |
||
2551 | 4363 |
^ self setSocketOption:#'TCP_CORK' argument:aBoolean argument:nil. |
1885 | 4364 |
! |
4365 |
||
4366 |
setTCPNoDelay:aBoolean |
|
4367 |
"enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) |
|
4368 |
For special applications only. |
|
4369 |
Not all OperatingSystems offer this functionality |
|
4370 |
(returns false, if unsupported)" |
|
4371 |
||
2551 | 4372 |
^ self setSocketOption:#'TCP_NODELAY' argument:aBoolean argument:nil. |
126 | 4373 |
! ! |
82 | 4374 |
|
4626 | 4375 |
|
1935 | 4376 |
!Socket methodsFor:'waiting'! |
4377 |
||
4570 | 4378 |
waitForNewConnectionOrDataOnAny:otherConnections timeout:secondsOrTimeDurationOrNil |
1935 | 4379 |
"suspend the current process, until either a new connection comes |
4380 |
in at the receiver, or data arrives on any of the otherConnections. |
|
4381 |
For a new connection, an accept is performed and the new socket is returned. |
|
4382 |
For an old connection, that socket is returned. |
|
4383 |
In any case, the caller gets a socket to operate on as return value, |
|
4032 | 4384 |
or nil, if a timeout occurred. |
1935 | 4385 |
This method implements the inner wait-primitive of a multi-connection |
4386 |
server application." |
|
4387 |
||
4388 |
||
4570 | 4389 |
|wasBlocked sema timeoutMs| |
1935 | 4390 |
|
4391 |
"first, a quick check if data is already available" |
|
4392 |
self canReadWithoutBlocking ifTrue:[ |
|
5001 | 4393 |
^ self accept. |
1935 | 4394 |
]. |
4395 |
otherConnections do:[:aConnection | |
|
5001 | 4396 |
aConnection canReadWithoutBlocking ifTrue:[ |
4397 |
^ aConnection |
|
4398 |
] |
|
1935 | 4399 |
]. |
4400 |
||
3281 | 4401 |
"check again - prevent incoming interrupts from disturbing our setup" |
4570 | 4402 |
|
4403 |
secondsOrTimeDurationOrNil notNil ifTrue:[ |
|
5001 | 4404 |
secondsOrTimeDurationOrNil isTimeDuration ifTrue:[ |
4405 |
timeoutMs := secondsOrTimeDurationOrNil getMilliseconds. |
|
4406 |
] ifFalse:[ |
|
4407 |
timeoutMs := secondsOrTimeDurationOrNil * 1000. |
|
4408 |
] |
|
4570 | 4409 |
]. |
4410 |
||
3281 | 4411 |
wasBlocked := OperatingSystem blockInterrupts. |
1935 | 4412 |
[ |
5001 | 4413 |
sema := Semaphore name:'multiReadWait'. |
4414 |
otherConnections do:[:aConnection | |
|
4415 |
Processor signal:sema onInput:(aConnection fileDescriptor). |
|
4416 |
]. |
|
4417 |
Processor signal:sema onInput:(self fileDescriptor). |
|
4418 |
timeoutMs notNil ifTrue:[ |
|
4419 |
Processor signal:sema afterMilliseconds:timeoutMs |
|
4420 |
]. |
|
4421 |
Processor activeProcess state:#ioWait. |
|
4422 |
sema wait. |
|
3281 | 4423 |
] ifCurtailed:[ |
5001 | 4424 |
sema notNil ifTrue:[Processor disableSemaphore:sema]. |
4425 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1935 | 4426 |
]. |
3281 | 4427 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1935 | 4428 |
|
4429 |
"see who it was ..." |
|
4430 |
self canReadWithoutBlocking ifTrue:[ |
|
5001 | 4431 |
^ self accept. |
1935 | 4432 |
]. |
4433 |
otherConnections do:[:aConnection | |
|
5001 | 4434 |
aConnection canReadWithoutBlocking ifTrue:[ |
4435 |
^ aConnection |
|
4436 |
] |
|
1935 | 4437 |
]. |
4438 |
||
4439 |
"none - a timeout" |
|
4440 |
^ nil |
|
4497 | 4441 |
|
4442 |
"Modified: / 09-08-2017 / 11:59:50 / cg" |
|
4570 | 4443 |
"Modified: / 19-01-2018 / 18:59:17 / stefan" |
1935 | 4444 |
! |
4445 |
||
4570 | 4446 |
waitForNewConnectionWithTimeout:secondsOrTimeDurationOrNil |
1935 | 4447 |
"suspend the current process, until a new connection comes |
4448 |
in at the receiver or a timeout occurs. |
|
4449 |
For a new connection, an accept is performed and the new socket is returned. |
|
4032 | 4450 |
Returns nil, if a timeout occurred. |
1935 | 4451 |
This method implements the inner wait-primitive of a single-connection |
4452 |
server application." |
|
4453 |
||
3633 | 4454 |
|newSock| |
4455 |
||
4570 | 4456 |
(self readWaitWithTimeout:secondsOrTimeDurationOrNil) ifTrue:[ |
5001 | 4457 |
"a timeout occurred - no connection within timeout" |
4458 |
self reportError:(OperatingSystem errorNumberFor:#ETIMEDOUT). |
|
4459 |
^ nil. |
|
1935 | 4460 |
]. |
4180 | 4461 |
self isOpen ifFalse:[ |
5001 | 4462 |
"I have been closed while waiting" |
4463 |
^ self errorNotOpen. |
|
4180 | 4464 |
]. |
4568 | 4465 |
|
4466 |
"ok, a connection is present - accept it" |
|
3633 | 4467 |
newSock := self class new. |
4468 |
(newSock primAcceptOn:self blocking:false) ifFalse:[ |
|
5001 | 4469 |
"should raise an error here - primitive code raises a notification" |
4470 |
^ nil |
|
3633 | 4471 |
]. |
4472 |
^ newSock |
|
4568 | 4473 |
|
4570 | 4474 |
"Modified (format): / 19-01-2018 / 18:53:15 / stefan" |
1935 | 4475 |
! ! |
4476 |
||
464 | 4477 |
!Socket class methodsFor:'documentation'! |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4478 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4479 |
version |
3590 | 4480 |
^ '$Header$' |
2292 | 4481 |
! |
4482 |
||
4483 |
version_CVS |
|
3590 | 4484 |
^ '$Header$' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4485 |
! ! |