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