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