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