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