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