author | Claus Gittinger <cg@exept.de> |
Wed, 09 Jul 2003 16:26:57 +0200 | |
changeset 1260 | 9a8fb2391174 |
parent 1235 | 9b35e58bf392 |
child 1263 | 23161346a162 |
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 |
" |
|
12 |
||
888 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
63 | 15 |
NonPositionableExternalStream subclass:#Socket |
1186 | 16 |
instanceVariableNames:'domain socketType protocol port serviceName peer peerName' |
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 |
||
444 | 27 |
#ifdef LINUX |
28 |
# define BUGGY_STDIO_LIB |
|
822 | 29 |
# include <linux/version.h> |
30 |
||
31 |
# ifndef KERNEL_VERSION |
|
32 |
# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
|
33 |
# endif |
|
34 |
#endif /* LINUX */ |
|
126 | 35 |
|
36 |
#include <stdio.h> |
|
37 |
#include <errno.h> |
|
38 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
39 |
#define UNIX_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
40 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
41 |
#if defined(transputer) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
42 |
# undef UNIX_LIKE |
418 | 43 |
# define NO_SOCKET |
44 |
#endif |
|
45 |
||
525 | 46 |
/* |
47 |
* which protocols can we support ? |
|
48 |
*/ |
|
49 |
#ifndef NO_SOCKET |
|
50 |
# define WANT__AF_INET |
|
51 |
#endif |
|
52 |
||
53 |
#ifdef UNIX_LIKE |
|
54 |
# define WANT__AF_UNIX |
|
55 |
#endif |
|
56 |
||
563 | 57 |
#ifdef __VMS__ |
58 |
# undef WANT__AF_UNIX |
|
571 | 59 |
# define WANT_AF_DECnet |
563 | 60 |
#endif |
61 |
||
527 | 62 |
#ifdef LINUX |
822 | 63 |
# ifndef LINUX_VERSION_CODE |
64 |
/* PRE 2.0 Linux kernel. */ |
|
65 |
# else |
|
66 |
# if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0) |
|
67 |
/* PRE 2.0 Linux kernel. */ |
|
68 |
# else |
|
69 |
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0) |
|
70 |
# define WANT__AF_APPLETALK |
|
71 |
# define xxWANT__AF_X25 |
|
72 |
# define xxWANT__AF_AX25 |
|
73 |
# define xxWANT__AF_IPX |
|
74 |
# define WANT__AF_INET6 */ |
|
869 | 75 |
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) |
875 | 76 |
# define xxWANT__AF_IRDA */ |
869 | 77 |
# endif /* >= 2.2.0 */ |
822 | 78 |
# endif /* >= 2.1.0 */ |
79 |
# endif /* pre 2.0.0 */ |
|
80 |
# endif /* pre 2.0.0 */ |
|
81 |
#endif /* LINIX */ |
|
525 | 82 |
|
819 | 83 |
#ifdef solaris2_0 |
84 |
# define xxxWANT__AF_DECNET |
|
85 |
#endif |
|
86 |
||
126 | 87 |
#ifdef LINUX |
88 |
/* kludge to avoid some redefines ... */ |
|
89 |
# define _ARPA_NAMESER_H |
|
90 |
# define _NETINET_TCP_H |
|
91 |
#endif |
|
92 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
93 |
#if !defined(NO_SOCKET) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
94 |
# include <fcntl.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
95 |
# include <sys/types.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
96 |
# define _SYS_TYPES_H_INCLUDED_ |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
97 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
98 |
# if defined(IRIS) && !defined(IRIX5) |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
99 |
/* no socket.h on 4.0.5h ?!?!? */ |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
100 |
# ifndef AF_UNIX |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
101 |
# define AF_UNIX 1 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
102 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
103 |
# ifndef AF_INET |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
104 |
# define AF_INET 2 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
105 |
# endif |
789 | 106 |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
107 |
# ifndef SOCK_STREAM |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
108 |
# define SOCK_STREAM 1 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
109 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
110 |
# ifndef SOCK_DGRAM |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
111 |
# define SOCK_DGRAM 2 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
112 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
113 |
# ifndef SOCK_RAW |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
114 |
# define SOCK_RAW 3 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
115 |
# endif |
656 | 116 |
# else |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
117 |
# include <sys/socket.h> |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
118 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
119 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
120 |
# ifdef NEXT3 |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
121 |
# include <netinet/in_systm.h> |
126 | 122 |
# endif |
123 |
#endif |
|
124 |
||
525 | 125 |
|
126 | 126 |
/* |
528 | 127 |
* see what we want ... |
126 | 128 |
*/ |
525 | 129 |
#ifdef WANT__AF_UNIX |
130 |
# ifdef AF_UNIX |
|
131 |
# ifndef PF_UNIX |
|
132 |
# define PF_UNIX AF_UNIX |
|
133 |
# endif |
|
126 | 134 |
# endif |
525 | 135 |
#else |
136 |
# undef AF_UNIX |
|
137 |
#endif |
|
138 |
||
139 |
#ifdef WANT__AF_INET |
|
140 |
# ifdef AF_INET |
|
141 |
# ifndef PF_INET |
|
142 |
# define PF_INET AF_INET |
|
143 |
# endif |
|
144 |
# endif |
|
145 |
#else |
|
146 |
# undef AF_INET |
|
126 | 147 |
#endif |
525 | 148 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
149 |
#ifdef WANT__AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
150 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
151 |
# ifndef PF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
152 |
# define PF_INET6 AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
153 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
154 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
155 |
#else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
156 |
# undef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
157 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
158 |
|
525 | 159 |
#ifdef WANT__AF_DECnet |
160 |
# ifdef AF_DECnet |
|
161 |
# ifndef PF_DECnet |
|
162 |
# define PF_DECnet AF_DECnet |
|
163 |
# endif |
|
164 |
# endif |
|
165 |
#else |
|
166 |
# undef AF_DECnet |
|
167 |
#endif |
|
168 |
||
169 |
#ifdef WANT__AF_APPLETALK |
|
170 |
# ifdef AF_APPLETALK |
|
171 |
# ifndef PF_APPLETALK |
|
172 |
# define PF_APPLETALK AF_APPLETALK |
|
173 |
# endif |
|
126 | 174 |
# endif |
525 | 175 |
#else |
176 |
# undef AF_APPLETALK |
|
126 | 177 |
#endif |
525 | 178 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
179 |
#ifdef WANT__AF_X25 /* X.25 */ |
525 | 180 |
# ifdef AF_X25 |
181 |
# ifndef PF_X25 |
|
182 |
# define PF_X25 AF_X25 |
|
183 |
# endif |
|
184 |
# endif |
|
185 |
#else |
|
186 |
# undef AF_X25 |
|
187 |
#endif |
|
188 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
189 |
#ifdef WANT__AF_NS /* Xerox XNS */ |
525 | 190 |
# ifdef AF_NS |
191 |
# ifndef PF_NS |
|
192 |
# define PF_NS AF_NS |
|
193 |
# endif |
|
126 | 194 |
# endif |
525 | 195 |
#else |
196 |
# undef AF_NS |
|
126 | 197 |
#endif |
525 | 198 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
199 |
#ifdef WANT__AF_SNA /* IBM SNA */ |
525 | 200 |
# ifdef AF_SNA |
201 |
# ifndef PF_SNA |
|
202 |
# define PF_SNA AF_SNA |
|
203 |
# endif |
|
126 | 204 |
# endif |
525 | 205 |
#else |
206 |
# undef AF_SNA |
|
207 |
#endif |
|
208 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
209 |
#ifdef WANT__AF_RAW /* RAW packets */ |
525 | 210 |
# ifdef AF_RAW |
211 |
# ifndef PF_RAW |
|
212 |
# define PF_RAW AF_RAW |
|
213 |
# endif |
|
214 |
# endif |
|
215 |
#else |
|
216 |
# undef AF_RAW |
|
126 | 217 |
#endif |
525 | 218 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
219 |
#ifdef WANT__AF_ISO /* ? */ |
525 | 220 |
# ifdef AF_ISO |
221 |
# ifndef PF_ISO |
|
222 |
# define PF_ISO AF_ISO |
|
223 |
# endif |
|
224 |
# endif |
|
225 |
#else |
|
226 |
# undef AF_ISO |
|
227 |
#endif |
|
228 |
||
823 | 229 |
#ifdef WANT__AF_NETBIOS /* NETBIOS */ |
525 | 230 |
# ifdef AF_NETBIOS |
231 |
# ifndef PF_NETBIOS |
|
232 |
# define PF_NETBIOS AF_NETBIOS |
|
233 |
# endif |
|
126 | 234 |
# endif |
525 | 235 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
236 |
# undef AF_NETBIOS |
126 | 237 |
#endif |
525 | 238 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
239 |
#ifdef WANT__AF_CCITT /* ? */ |
525 | 240 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
241 |
# ifndef PF_CCITT |
|
242 |
# define PF_CCITT AF_CCITT |
|
243 |
# endif |
|
244 |
# endif |
|
245 |
#else |
|
246 |
# undef AF_CCITT |
|
247 |
#endif |
|
248 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
249 |
#ifdef WANT__AF_IPX /* Novell IPX */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
250 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
251 |
# ifndef PF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
252 |
# define PF_IPX AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
253 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
254 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
255 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
256 |
# undef AF_IPX |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
257 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
258 |
|
812 | 259 |
#ifdef WANT__AF_AX25 /* Amateur Radio AX.25 */ |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
260 |
# ifdef AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
261 |
# ifndef PF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
262 |
# define PF_AX25 AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
263 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
264 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
265 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
266 |
# undef AF_AX25 |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
267 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
268 |
|
812 | 269 |
#ifdef WANT__AF_NETROM /* Amateur Radio NET/ROM */ |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
270 |
# ifdef AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
271 |
# ifndef PF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
272 |
# define PF_NETROM AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
273 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
274 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
275 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
276 |
# undef AF_NETROM |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
277 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
278 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
279 |
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
280 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
281 |
# ifndef PF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
282 |
# define PF_BRIDGE AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
283 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
284 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
285 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
286 |
# undef AF_BRIDGE |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
287 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
288 |
|
571 | 289 |
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */ |
290 |
# ifdef AF_BSC |
|
291 |
# ifndef PF_BSC |
|
292 |
# define PF_BSC AF_BSC |
|
293 |
# endif |
|
294 |
# endif |
|
295 |
#else |
|
296 |
# undef AF_BSC |
|
297 |
#endif |
|
298 |
||
812 | 299 |
#ifdef WANT__AF_ROSE /* Amateur Radio X.25 PLP */ |
814 | 300 |
# ifdef AF_ROSE |
301 |
# ifndef PF_ROSE |
|
302 |
# define PF_ROSE AF_ROSE |
|
812 | 303 |
# endif |
304 |
# endif |
|
305 |
#else |
|
814 | 306 |
# undef AF_ROSE |
812 | 307 |
#endif |
308 |
||
823 | 309 |
#ifdef WANT__AF_ATM /* ATM Services */ |
310 |
# ifdef AF_ATM |
|
311 |
# ifndef PF_ATM |
|
312 |
# define PF_ATM AF_ATM |
|
313 |
# endif |
|
314 |
# endif |
|
315 |
#else |
|
316 |
# undef AF_ATM |
|
317 |
#endif |
|
318 |
||
319 |
#ifdef WANT__AF_BAN /* BAN / VINES IP Services */ |
|
320 |
# ifdef AF_BAN |
|
321 |
# ifndef PF_BAN |
|
322 |
# define PF_BAN AF_BAN |
|
323 |
# endif |
|
324 |
# endif |
|
325 |
#else |
|
326 |
# undef AF_BAN |
|
327 |
#endif |
|
328 |
||
329 |
#ifdef WANT__AF_VOICEVIEW /* VoiceView Services W95 only */ |
|
330 |
# ifdef AF_VOICEVIEW |
|
331 |
# ifndef PF_VOICEVIEW |
|
332 |
# define PF_VOICEVIEW AF_VOICEVIEW |
|
333 |
# endif |
|
334 |
# endif |
|
335 |
#else |
|
336 |
# undef AF_VOICEVIEW |
|
337 |
#endif |
|
338 |
||
869 | 339 |
#ifdef WANT__AF_IRDA /* infrared */ |
340 |
# ifdef AF_IRDA |
|
341 |
# ifndef PF_IRDA |
|
342 |
# define PF_IRDA AF_IRDA |
|
343 |
# endif |
|
344 |
# endif |
|
345 |
#else |
|
346 |
# undef AF_IRDA |
|
347 |
#endif |
|
348 |
||
571 | 349 |
|
528 | 350 |
/* |
351 |
* now, include what we have to ... |
|
819 | 352 |
* undef support, if no include file is present |
353 |
* (or I dont know yet, where to find it) |
|
528 | 354 |
*/ |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
355 |
|
823 | 356 |
#ifdef AF_UNIX |
357 |
# ifdef UNIX |
|
358 |
# include <sys/un.h> |
|
359 |
# else |
|
360 |
# undef AF_UNIX |
|
361 |
# endif |
|
362 |
#endif |
|
363 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
364 |
#ifdef AF_INET |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
365 |
# include <netdb.h> |
969 | 366 |
# if defined(PRE_SUSE_7_2) |
367 |
# if defined(LINUX) && defined(AF_INET6) |
|
368 |
# include <linux/in.h> |
|
369 |
# else |
|
370 |
# include <netinet/in.h> |
|
371 |
# endif |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
372 |
# else |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
373 |
# include <netinet/in.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
374 |
# endif |
969 | 375 |
# if !defined(LINUX) |
376 |
# if ! (defined(SYSV3) && defined(mc88k)) |
|
377 |
# include <netinet/tcp.h> |
|
378 |
# endif |
|
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
379 |
# endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
380 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
381 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
382 |
#ifdef AF_INET6 |
819 | 383 |
# if defined(LINUX) && defined(__GLIBC__) |
969 | 384 |
# if defined(PRE_SUSE_7_2) |
385 |
# include <linux/in6.h> |
|
386 |
# endif |
|
819 | 387 |
# else |
388 |
# undef AF_INET6 |
|
126 | 389 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
390 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
391 |
|
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
392 |
#ifdef AF_APPLETALK |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
393 |
# ifdef LINUX |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
394 |
# include <asm/types.h> |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
395 |
# include <linux/atalk.h> |
819 | 396 |
# else |
397 |
# undef AF_APPLETALK |
|
398 |
# endif |
|
399 |
#endif |
|
400 |
||
401 |
#ifdef AF_DECNET |
|
402 |
# ifdef solaris2_0 |
|
403 |
# include <X11/dni8.h> |
|
404 |
# else |
|
405 |
# undef AF_DECNET |
|
465 | 406 |
# endif |
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
407 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
408 |
|
812 | 409 |
#ifdef AF_X25 |
410 |
# ifdef LINUX |
|
411 |
# include <linux/x25.h> |
|
819 | 412 |
# else |
413 |
# undef AF_X25 |
|
414 |
# endif |
|
415 |
#endif |
|
416 |
||
417 |
#ifdef AF_AX25 |
|
418 |
# ifdef LINUX |
|
419 |
# include <linux/ax25.h> |
|
420 |
# else |
|
421 |
# undef AF_AX25 |
|
422 |
# endif |
|
423 |
#endif |
|
424 |
||
425 |
#ifdef AF_IPX |
|
426 |
# ifdef LINUX |
|
427 |
# include <linux/ipx.h> |
|
428 |
# else |
|
823 | 429 |
# ifdef WIN32 |
430 |
# include <wsipx.h> |
|
431 |
# else |
|
432 |
# undef AF_IPX |
|
433 |
# endif |
|
434 |
# endif |
|
435 |
#endif |
|
436 |
||
437 |
#ifdef AF_NETBIOS |
|
438 |
# ifdef WIN32 |
|
439 |
# include <wsnetbs.h> |
|
440 |
# else |
|
441 |
# undef AF_NETBIOS |
|
442 |
# endif |
|
443 |
#endif |
|
444 |
||
445 |
#ifdef AF_ATM |
|
446 |
# ifdef WIN32 |
|
447 |
# include <ws2atm.h> |
|
448 |
# else |
|
449 |
# undef AF_ATM |
|
812 | 450 |
# endif |
451 |
#endif |
|
452 |
||
823 | 453 |
#ifdef AF_BAN |
454 |
# ifdef WIN32 |
|
455 |
# include <wsvns.h> |
|
456 |
# else |
|
457 |
# undef AF_BAN |
|
458 |
# endif |
|
459 |
#endif |
|
460 |
||
461 |
#ifdef AF_VOICEVIEW |
|
462 |
# ifdef WIN32 |
|
463 |
# include <wsvv.h> |
|
464 |
# else |
|
465 |
# undef AF_VOICEVIEW |
|
466 |
# endif |
|
467 |
#endif |
|
468 |
||
869 | 469 |
#ifdef AF_IRDA |
470 |
# ifdef LINUX |
|
471 |
# include <linux/irda.h> |
|
472 |
# else |
|
473 |
# undef AF_IRDA |
|
474 |
# endif |
|
475 |
#endif |
|
476 |
||
823 | 477 |
#undef AF_SNA /* not yet implemented */ |
478 |
#undef AF_RAW /* not yet implemented */ |
|
479 |
#undef AF_NETROM /* not yet implemented */ |
|
480 |
#undef AF_BRIDGE /* not yet implemented */ |
|
481 |
#undef AF_BSC /* not yet implemented */ |
|
482 |
||
819 | 483 |
|
484 |
/* |
|
485 |
* see what is leftOver |
|
486 |
*/ |
|
487 |
union sockaddr_u { |
|
488 |
#ifdef AF_UNIX |
|
489 |
struct sockaddr_un un; |
|
490 |
#endif |
|
491 |
#ifdef AF_INET |
|
492 |
struct sockaddr_in in; |
|
493 |
#endif |
|
494 |
#ifdef AF_INET6 |
|
495 |
struct sockaddr_in6 in6; |
|
496 |
#endif |
|
497 |
#ifdef AF_APPLETALK |
|
498 |
struct sockaddr_at at; |
|
499 |
#endif |
|
500 |
#ifdef AF_DECNET |
|
501 |
struct sockaddr_dn dn; |
|
502 |
#endif |
|
503 |
#ifdef AF_X25 |
|
504 |
struct sockaddr_x25 x25; |
|
505 |
#endif |
|
506 |
#ifdef AF_AX25 |
|
507 |
struct sockaddr_ax25 ax25; |
|
508 |
#endif |
|
509 |
#ifdef AF_IPX |
|
510 |
struct sockaddr_ipx ipx; |
|
511 |
#endif |
|
823 | 512 |
#ifdef AF_NETBIOS |
513 |
struct sockaddr_nb nb; |
|
514 |
#endif |
|
515 |
#ifdef AF_ATM |
|
516 |
struct sockaddr_atm atm; |
|
517 |
#endif |
|
518 |
#ifdef AF_BAN |
|
519 |
struct sockaddr_vns vns; |
|
520 |
#endif |
|
521 |
#ifdef AF_VOICEVIEW |
|
522 |
struct sockaddr_vv vv; |
|
523 |
#endif |
|
869 | 524 |
#ifdef AF_IRDA |
525 |
struct sockaddr_irda irda; |
|
526 |
#endif |
|
819 | 527 |
}; |
528 |
||
529 |
||
739
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
530 |
#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
|
531 |
# define USE_H_ERRNO |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
532 |
#endif |
eb3878300c3b
removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
533 |
|
126 | 534 |
|
819 | 535 |
|
126 | 536 |
/* |
537 |
* on some systems errno is a macro ... check for it here |
|
538 |
*/ |
|
539 |
#ifndef errno |
|
540 |
extern errno; |
|
541 |
#endif |
|
542 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
543 |
#ifdef USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
544 |
# ifndef h_errno |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
545 |
extern h_errno; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
546 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
547 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
548 |
|
720 | 549 |
#ifdef xxLINUX |
550 |
/* use inline string macros ... */ |
|
551 |
# define __STRINGDEFS__ |
|
552 |
# include <linuxIntern.h> |
|
553 |
#endif |
|
554 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
555 |
/* |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
556 |
* gethostbyname seems to have trouble |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
557 |
* sometimes, if interrupted while a request |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
558 |
* is on its way the name server. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
559 |
* (although specified in the man-page, |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
560 |
* a check on TRY_AGAIN fails on iris) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
561 |
*/ |
692
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
562 |
#ifdef LINUX |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
563 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
564 |
# define GETHOSTBYNAME(hp, name) \ |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
565 |
hp = gethostbyname((char *) name); |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
566 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
567 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
568 |
hp = gethostbyaddr(addr, alen, af); |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
569 |
|
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
570 |
#else |
85d64f84be0c
oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents:
672
diff
changeset
|
571 |
|
693 | 572 |
# ifdef IRIX5_3 |
573 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
574 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
575 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
576 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
577 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
578 |
} while ((hp == NULL) && \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
579 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
580 |
|
693 | 581 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
789 | 582 |
do { \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
583 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
584 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
585 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
586 |
} while ((hp == NULL) && \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
587 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
693 | 588 |
# else |
589 |
# ifdef USE_H_ERRNO |
|
590 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
591 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
592 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
593 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
594 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
595 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
596 |
|
693 | 597 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
598 |
do { \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
599 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
600 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
601 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
602 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
693 | 603 |
# else |
604 |
# define GETHOSTBYNAME(hp, name) \ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
605 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
606 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
607 |
__END_INTERRUPTABLE__ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
608 |
|
693 | 609 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
610 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
611 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
612 |
__END_INTERRUPTABLE__ |
693 | 613 |
# endif |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
614 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
615 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
616 |
|
126 | 617 |
#ifdef DEBUG |
618 |
# define DBGPRINTF(x) { if (__debugging__) printf x; } |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
619 |
# define DBGFPRINTF(x) { if (__debugging__) fprintf x; } |
126 | 620 |
#else |
621 |
# define DBGPRINTF(x) /* as nothing */ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
622 |
# define DBGFPRINTF(x) /* as nothing */ |
126 | 623 |
#endif |
624 |
||
625 |
%} |
|
626 |
! ! |
|
627 |
||
511 | 628 |
!Socket primitiveVariables! |
629 |
%{ |
|
630 |
static int __debugging__ = 0; |
|
631 |
%} |
|
632 |
! ! |
|
633 |
||
464 | 634 |
!Socket class methodsFor:'documentation'! |
25 | 635 |
|
31 | 636 |
copyright |
637 |
" |
|
638 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
42 | 639 |
All Rights Reserved |
31 | 640 |
|
641 |
This software is furnished under a license and may be used |
|
642 |
only in accordance with the terms of that license and with the |
|
643 |
inclusion of the above copyright notice. This software may not |
|
644 |
be provided or otherwise made available to, or used by, any |
|
645 |
other person. No title to or ownership of the software is |
|
646 |
hereby transferred. |
|
647 |
" |
|
648 |
! |
|
649 |
||
25 | 650 |
documentation |
651 |
" |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
652 |
This class provides access to sockets for interprocess communication. |
25 | 653 |
The message protocol is preliminary, until someone tells me how |
31 | 654 |
other smalltalk's socket interfaces look like. |
25 | 655 |
|
525 | 656 |
Currently, only IP and UNIX domain sockets are supported. |
657 |
Code for appletalk is included, but was never tested ... |
|
658 |
More may be added in the future. |
|
659 |
(the code is prepared for things like SNA or decNet; |
|
660 |
however, right now, this code is empty and needs a little work. |
|
661 |
Implementing those is pretty straight forward, once the address |
|
662 |
data structures are known.) |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
663 |
|
28 | 664 |
Due to historic reasons (I started this class, before I got hold of some |
665 |
code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface |
|
71 | 666 |
still provided. |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
667 |
This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces, |
71 | 668 |
together with the bind/listen and accept calls, |
669 |
which are meant to be compatible to ST-80's UnixSocketAccessor interface. |
|
670 |
||
869 | 671 |
ST/X does not yet use IPSocketAddress, UDSocketAddress etc; all addressing |
71 | 672 |
is done by passing appropriate string- or byteArray objects containing |
673 |
the addresses. This may change, too. |
|
674 |
||
675 |
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
|
676 |
(mhmh - how can I test those ?) |
532 | 677 |
change to raise more signals on errors. |
529 | 678 |
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
|
679 |
net please test this (and send bug fixes ...) |
259 | 680 |
|
681 |
[author:] |
|
425 | 682 |
Claus Gittinger |
48 | 683 |
" |
684 |
! |
|
28 | 685 |
|
48 | 686 |
examples |
687 |
" |
|
28 | 688 |
example (get help info from an nntp server): |
1009 | 689 |
[exBegin] |
690 |
|sock host| |
|
691 |
||
692 |
host := OperatingSystem getEnvironment:'NNTPSERVER'. |
|
693 |
||
694 |
sock := Socket newTCPclientToHost:host port:'nntp'. |
|
695 |
Transcript showCR:sock nextLine. |
|
696 |
sock buffered:false. |
|
697 |
||
698 |
sock nextPutAll:'HELP'; cr. |
|
699 |
[:exit | |
|
700 |
|line| |
|
701 |
||
702 |
line := sock nextLine. |
|
703 |
line = '.' ifTrue:[exit value:nil]. |
|
704 |
Transcript showCR:line. |
|
705 |
] loopWithExit. |
|
706 |
sock close |
|
707 |
[exEnd] |
|
209 | 708 |
|
28 | 709 |
|
209 | 710 |
example (connect to finger daemon, get users entry): |
1009 | 711 |
[exBegin] |
712 |
|sock host entry| |
|
713 |
||
714 |
host := OperatingSystem getHostName. |
|
715 |
||
716 |
sock := Socket newTCPclientToHost:host port:'finger'. |
|
717 |
sock isNil ifTrue:[ |
|
718 |
self warn:'no finger daemon is running'. |
|
719 |
^ self |
|
720 |
]. |
|
721 |
sock useCRLF:true. |
|
722 |
sock buffered:false. |
|
723 |
sock isNil ifTrue:[ |
|
724 |
Transcript showCR:'cannot connect to local finger daemon' |
|
725 |
] ifFalse:[ |
|
726 |
sock nextPutAll:(OperatingSystem getLoginName). |
|
727 |
sock cr. |
|
728 |
||
729 |
entry := sock nextLine. |
|
730 |
Transcript showCR:entry. |
|
731 |
||
732 |
sock close |
|
733 |
] |
|
734 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
735 |
|
28 | 736 |
example (connect to an ftp server): |
1009 | 737 |
[exBegin] |
738 |
|sock host| |
|
739 |
||
740 |
host := OperatingSystem getHostName. |
|
741 |
sock := Socket newTCPclientToHost:host port:'ftp'. |
|
742 |
||
743 |
sock buffered:false. |
|
744 |
Transcript showCR:sock nextLine. |
|
745 |
sock nextPutAll:('USER ' , 'anonymous'); cr. |
|
746 |
Transcript showCR:sock nextLine. |
|
747 |
sock nextPutAll:('PASS ' , 'fooBar'); cr. |
|
748 |
Transcript showCR:sock nextLine. |
|
749 |
sock nextPutAll:'LIST'; cr. |
|
750 |
Transcript showCR:sock nextLine. |
|
751 |
sock close. |
|
752 |
||
753 |
'dont know enough of the ftp protocol to continue here ...' |
|
754 |
[exEnd] |
|
28 | 755 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
756 |
|
93 | 757 |
example (connect to an snmp server [UDP]): |
1009 | 758 |
[exBegin] |
759 |
|sock port| |
|
760 |
||
761 |
sock := Socket newUDP. |
|
762 |
port := Socket portOfService:'snmp'. |
|
763 |
sock connectTo:(OperatingSystem getHostName) port:port. |
|
764 |
sock buffered:false. |
|
765 |
Transcript showCR:'got it'. |
|
766 |
sock close. |
|
767 |
[exEnd] |
|
42 | 768 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
769 |
|
42 | 770 |
example (await connection from a client and read some data): |
1009 | 771 |
[exBegin] |
772 |
|connectSock sock| |
|
773 |
||
774 |
connectSock := Socket newTCPserverAtPort:9998. |
|
775 |
connectSock isNil ifTrue:[ |
|
776 |
Transcript showCR:'socket setup failed.'. |
|
777 |
] ifFalse:[ |
|
778 |
Transcript showCR:'listen ..'. |
|
779 |
(connectSock listenFor:5) ifFalse:[ |
|
780 |
Transcript showCR:'listen failed.'. |
|
781 |
] ifTrue:[ |
|
782 |
Transcript showCR:'wait'. |
|
783 |
connectSock readWait. |
|
784 |
Transcript showCR:'accept'. |
|
785 |
sock := connectSock accept. |
|
786 |
sock isNil ifTrue:[ |
|
787 |
Transcript showCR:'accept failed.'. |
|
788 |
] ifFalse:[ |
|
789 |
sock buffered:false. |
|
790 |
Transcript showCR:'server: got it'. |
|
791 |
'can now do transfer via sock'. |
|
792 |
Transcript showCR:'read'. |
|
793 |
Transcript showCR:('got: ' , sock nextLine). |
|
794 |
||
795 |
Transcript showCR:'close'. |
|
796 |
sock close |
|
797 |
]. |
|
798 |
connectSock close. |
|
799 |
] |
|
800 |
] |
|
801 |
[exEnd] |
|
42 | 802 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
803 |
|
42 | 804 |
example (connect to above server and send some data): |
1009 | 805 |
[exBegin] |
806 |
|sock| |
|
807 |
||
808 |
sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998. |
|
809 |
sock isNil ifTrue:[ |
|
810 |
Transcript showCR:'nope' |
|
811 |
] ifFalse:[ |
|
812 |
sock buffered:false. |
|
813 |
Transcript showCR:'client: got it'. |
|
814 |
'can now do transfer via sock'. |
|
815 |
Transcript showCR:'sending <hello>'. |
|
816 |
sock nextPutLine:'hello'. |
|
817 |
sock close |
|
818 |
] |
|
819 |
[exEnd] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
820 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
821 |
example: UNIX domain socket (await connection from a client and read some data): |
1009 | 822 |
|
823 |
|connectSock sock| |
|
824 |
||
825 |
'/tmp/ud_socket' asFilename remove. |
|
826 |
connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'. |
|
827 |
connectSock isNil ifTrue:[ |
|
828 |
Transcript showCR:'socket setup failed.'. |
|
829 |
] ifFalse:[ |
|
830 |
Transcript showCR:'listen ..'. |
|
831 |
(connectSock listenFor:5) ifFalse:[ |
|
832 |
Transcript showCR:'listen failed.'. |
|
833 |
] ifTrue:[ |
|
834 |
Transcript showCR:'wait'. |
|
835 |
connectSock buffered:false. |
|
836 |
connectSock readWait. |
|
837 |
Transcript showCR:'accept'. |
|
838 |
sock := connectSock accept. |
|
839 |
sock isNil ifTrue:[ |
|
840 |
Transcript showCR:'accept failed.'. |
|
841 |
] ifFalse:[ |
|
842 |
sock buffered:false. |
|
843 |
Transcript showCR:'server: got it'. |
|
844 |
'can now do transfer via sock'. |
|
845 |
Transcript showCR:'read'. |
|
846 |
Transcript showCR:('got: ' , sock nextLine). |
|
847 |
||
848 |
Transcript showCR:'close'. |
|
849 |
sock close |
|
850 |
]. |
|
851 |
connectSock close. |
|
852 |
] |
|
853 |
] |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
854 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
855 |
|
118 | 856 |
example (connect to above server and send some data; |
1009 | 857 |
Notice, this fails, if above server code is executed in the same ST/X image |
858 |
(at least on LINUX), since the OS does not correctly handle |
|
859 |
a connect from within an interrupted accept system call |
|
860 |
On SGI's SVR4, this works ok |
|
861 |
[exBegin] |
|
862 |
|sock| |
|
863 |
||
864 |
sock := Socket newUNIXclientTo:'/tmp/ud_socket'. |
|
865 |
sock isNil ifTrue:[ |
|
866 |
Transcript showCR:'nope' |
|
867 |
] ifFalse:[ |
|
868 |
sock buffered:false. |
|
869 |
Transcript showCR:'client: got it'. |
|
870 |
'can now do transfer via sock'. |
|
871 |
Transcript showCR:'sending <hello>'. |
|
872 |
sock nextPutLine:'hello'. |
|
873 |
sock close |
|
874 |
] |
|
875 |
[exEnd] |
|
1007 | 876 |
|
877 |
||
878 |
example (UDP await packet from a client and read some data): |
|
1009 | 879 |
[exBegin] |
880 |
|udpSock sock addr n dataBuffer| |
|
881 |
||
882 |
udpSock := Socket newUDPserverAtPort:9999. |
|
883 |
udpSock isNil ifTrue:[ |
|
884 |
Transcript showCR:'socket setup failed.'. |
|
885 |
] ifFalse:[ |
|
886 |
Transcript showCR:'wait'. |
|
887 |
udpSock readWait. |
|
888 |
||
889 |
addr := IPSocketAddress new. |
|
890 |
dataBuffer := ByteArray new:1000. |
|
891 |
n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size. |
|
892 |
n > 0 ifTrue:[ |
|
893 |
Transcript showCR:('got: ' , n printString , 'bytes from ' , addr printString). |
|
894 |
Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString). |
|
895 |
] ifFalse:[ |
|
896 |
Transcript showCR:'read failed'. |
|
897 |
]. |
|
898 |
||
899 |
Transcript showCR:'close'. |
|
900 |
udpSock close |
|
901 |
] |
|
902 |
[exEnd] |
|
1007 | 903 |
example (connect to above UDP server and send some data; |
1009 | 904 |
[exBegin] |
905 |
|sock| |
|
906 |
||
907 |
sock := Socket newUDP. |
|
908 |
sock isNil ifTrue:[ |
|
909 |
Transcript showCR:'nope' |
|
910 |
] ifFalse:[ |
|
911 |
sock sendTo:(IPSocketAddress new hostName:'localhost' port:9999) buffer:'hello world'. |
|
912 |
sock close |
|
913 |
] |
|
914 |
[exEnd] |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
915 |
|
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
916 |
example: pingWalk (try to ping hosts on the local network) |
1009 | 917 |
[exBegin] |
918 |
|myName myAddress list top hosts walkProcess port| |
|
919 |
||
920 |
myName := OperatingSystem getHostName. |
|
921 |
myAddress := Socket ipAddressOfHost:myName. |
|
922 |
||
923 |
port := Socket portOfService:'echo'. |
|
924 |
port isNil ifTrue:[ |
|
925 |
self error:'dont know echo port'. |
|
926 |
^ self |
|
927 |
]. |
|
928 |
||
929 |
top := StandardSystemView new. |
|
930 |
top label:'PING net walk'. |
|
931 |
||
932 |
list := ScrollableView for:ListView in:top. |
|
933 |
list origin:0.0@0.0 corner:1.0@1.0. |
|
934 |
||
935 |
top openAndWait. |
|
936 |
||
937 |
walkProcess := [ |
|
938 |
|l low hi direction tryHostID dottedName hostName conn addr| |
|
939 |
||
940 |
l := SortedCollection new. |
|
941 |
||
942 |
' only works with type C-net |
|
943 |
the code below could simply do 1 to:254 do:[:hostID } |
|
944 |
but, to probe likely hosts earlier, the probing is done |
|
945 |
ping-pong like around my ip-address (assuming, that other machines |
|
946 |
have numbers around my own)'. |
|
947 |
||
948 |
low := hi := (myAddress at:4). |
|
949 |
direction := 1. |
|
950 |
||
951 |
[low > 0 or:[hi < 255]] whileTrue:[ |
|
952 |
direction > 0 ifTrue:[ |
|
953 |
hi := hi + 1. |
|
954 |
tryHostID := hi. |
|
955 |
direction := -1. |
|
956 |
] ifFalse:[ |
|
957 |
low := low - 1. |
|
958 |
tryHostID := low. |
|
959 |
direction := 1. |
|
960 |
]. |
|
961 |
(tryHostID between:1 and:254) ifTrue:[ |
|
962 |
dottedName := (myAddress at:1) printString |
|
963 |
, '.' , (myAddress at:2) printString |
|
964 |
, '.' , (myAddress at:3) printString |
|
965 |
, '.' , tryHostID printString. |
|
966 |
||
967 |
top label:'PING net walk - trying ' , dottedName. |
|
968 |
||
969 |
top windowGroup withCursor:Cursor wait do:[ |
|
970 |
conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000. |
|
971 |
conn notNil ifTrue:[ |
|
972 |
addr := Socket ipAddressOfHost:dottedName. |
|
973 |
hostName := Socket hostWithIpAddress:addr. |
|
974 |
hostName isNil ifTrue:[ |
|
975 |
hostName :='?' |
|
976 |
]. |
|
977 |
l add:(dottedName paddedTo:15 with:Character space) |
|
978 |
, ' ' |
|
979 |
, (hostName paddedTo:15 with:Character space) |
|
980 |
, ' up & reachable'. |
|
981 |
list list:l. |
|
982 |
conn close. |
|
983 |
] |
|
984 |
]. |
|
985 |
]. |
|
986 |
]. |
|
987 |
top label:'PING reachable hosts'. |
|
988 |
] forkAt:(Processor userBackgroundPriority). |
|
989 |
walkProcess name:'ping net walker'. |
|
990 |
[exEnd] |
|
991 |
||
992 |
||
993 |
This example creates a simple UDP server that accepts |
|
994 |
single packets from anybody and broadcasts them to all |
|
995 |
clients that have connected so far. |
|
996 |
||
997 |
[exBegin] |
|
998 |
| socket address buffer msgSize clients | |
|
999 |
clients := Set new. |
|
1000 |
address := IPSocketAddress new. |
|
1001 |
buffer := String new: 1024. |
|
1002 |
||
1003 |
socket := self newUDPserverAtPort: 6666. |
|
1004 |
||
1005 |
Transcript showCR: 'server starting'. |
|
1006 |
||
1007 |
[ |
|
1008 |
[true] whileTrue: [ |
|
1009 |
(socket readWaitWithTimeoutMs: 200) ifFalse: [ |
|
1010 |
msgSize := socket |
|
1011 |
receiveFrom: address |
|
1012 |
buffer: buffer |
|
1013 |
start: 1 |
|
1014 |
for: buffer size. |
|
1015 |
||
1016 |
clients add: address copy. |
|
1017 |
clients do: [ :clientAddress | |
|
1018 |
socket |
|
1019 |
sendTo: clientAddress |
|
1020 |
buffer: buffer |
|
1021 |
start: 1 |
|
1022 |
for: msgSize]] |
|
1023 |
] |
|
1024 |
] valueNowOrOnUnwindDo:[ |
|
1025 |
Transcript showCR: 'server shutting down'. |
|
1026 |
socket close |
|
1027 |
] |
|
1028 |
[exEnd] |
|
817 | 1029 |
|
1030 |
send a datagram to above server: |
|
1009 | 1031 |
[exBegin] |
1032 |
||
1033 |
| socket address buffer host msg | |
|
1034 |
||
1035 |
host := Dialog |
|
1036 |
request: 'What is the name of the server''s host?' |
|
1037 |
initialAnswer: 'localhost'. |
|
1038 |
||
1039 |
socket := self newUDP. |
|
1040 |
||
1041 |
address := IPSocketAddress hostName: host port: 6666. |
|
1042 |
||
1043 |
buffer := ByteArray new: 1000. |
|
1044 |
[ |
|
1045 |
[(msg := Dialog request: 'Say something') isEmpty] whileFalse:[ |
|
1046 |
| replySize stream | |
|
1047 |
||
1048 |
socket writeWait. |
|
1049 |
stream := buffer writeStream. |
|
1050 |
stream nextPutAll: msg. |
|
1051 |
socket sendTo:address buffer:buffer start:1 for:stream position. |
|
1052 |
socket readWait. |
|
1053 |
||
1054 |
replySize := socket receiveFrom:address buffer:buffer. |
|
1055 |
replySize > 0 ifTrue: [ |
|
1056 |
Transcript cr; nextPutAll: 'Server acknowledged: '. |
|
1057 |
Transcript show: ((buffer copyFrom: 1 to: replySize) asString) |
|
1058 |
] |
|
1059 |
] |
|
1060 |
] valueNowOrOnUnwindDo: [socket close]. |
|
1061 |
Transcript cr |
|
1062 |
[exEnd] |
|
25 | 1063 |
" |
1064 |
! ! |
|
1065 |
||
1221 | 1066 |
!Socket class methodsFor:'Compatibility-ST80'! |
91 | 1067 |
|
126 | 1068 |
family:domainSymbol type:typeSymbol |
1069 |
"create a socket for domain and type - ST80 simply uses a different name. |
|
1070 |
Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns; |
|
1071 |
Type must be #stream, #datagram or #raw |
|
91 | 1072 |
|
811 | 1073 |
XXX: currently only the #inet and #unix domains is supported" |
91 | 1074 |
|
126 | 1075 |
^ self domain:domainSymbol type:typeSymbol |
51 | 1076 |
|
126 | 1077 |
" |
1078 |
Socket family:#inet type:#stream |
|
1079 |
Socket family:#inet type:#datagram |
|
1080 |
Socket family:#unix type:#stream |
|
1081 |
" |
|
867 | 1082 |
! |
115 | 1083 |
|
617
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1084 |
getHostname |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1085 |
"return the computers hostname string" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1086 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1087 |
^ OperatingSystem getHostName |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1088 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1089 |
"Created: / 27.2.1998 / 02:32:17 / cg" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1090 |
! |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
1091 |
|
126 | 1092 |
sockStream |
1093 |
"return the type code for stream sockets" |
|
51 | 1094 |
|
126 | 1095 |
^ #stream |
44 | 1096 |
! ! |
1097 |
||
464 | 1098 |
!Socket class methodsFor:'Signal constants'! |
21 | 1099 |
|
1100 |
brokenConnectionSignal |
|
1101 |
"return the signal used to tell broken connections. |
|
1102 |
Since in unix, this is the same as the broken pipe signal, |
|
1103 |
return that one. |
|
1104 |
(for other Operatingsystems, this may change ..)" |
|
1105 |
||
1106 |
^ PipeStream brokenPipeSignal |
|
887 | 1107 |
! |
1108 |
||
1109 |
invalidArgumentsSignal |
|
1110 |
"dummy for compatibility" |
|
1111 |
||
1112 |
^ self errorSignal |
|
21 | 1113 |
! ! |
1114 |
||
464 | 1115 |
!Socket class methodsFor:'debugging'! |
71 | 1116 |
|
1117 |
debug:aBoolean |
|
1118 |
"turn on/off internal debugprints. |
|
1119 |
This method is for ST/X debugging only and |
|
1120 |
may be removed in later versions" |
|
1121 |
||
1122 |
%{ /* NOCONTEXT */ |
|
1123 |
||
1124 |
__debugging__ = (aBoolean == true); |
|
1125 |
%} |
|
93 | 1126 |
" |
1127 |
Socket debug:true |
|
1128 |
Socket debug:false |
|
1129 |
" |
|
71 | 1130 |
! ! |
1131 |
||
464 | 1132 |
!Socket class methodsFor:'general instance creation'! |
126 | 1133 |
|
1134 |
domain:domainSymbol type:type |
|
1135 |
"create a socket for domain and type - |
|
1136 |
neither any connect nor binding is done. |
|
819 | 1137 |
Domain must be one of the symbols: |
1138 |
#inet, #unix, #appletalk, #decnet, #xns, ...; |
|
1139 |
Type must be: |
|
1140 |
#stream, #datagram or #raw |
|
126 | 1141 |
|
1142 |
XXX: currently only the #inet domain is supported" |
|
1143 |
||
1144 |
^ self new domain:domainSymbol type:type |
|
1145 |
||
1146 |
" |
|
1147 |
Socket domain:#inet type:#stream |
|
1148 |
Socket domain:#inet type:#datagram |
|
1149 |
Socket domain:#unix type:#stream |
|
1150 |
Socket domain:#appletalk type:#stream |
|
819 | 1151 |
Socket domain:#decnet type:#stream |
869 | 1152 |
Socket domain:#irda type:#stream |
126 | 1153 |
" |
1154 |
! |
|
1155 |
||
576 | 1156 |
new |
1157 |
"create a TCP socket" |
|
1158 |
||
1159 |
^ super new buffered:false |
|
1160 |
! |
|
1161 |
||
126 | 1162 |
newTCP |
1163 |
"create a TCP socket - no binding or other setup is done, |
|
1164 |
neither connect nor connect-wait is done." |
|
1165 |
||
1166 |
^ self new domain:#inet type:#stream |
|
1167 |
||
1168 |
"Socket newUDP" |
|
1169 |
! |
|
1170 |
||
1171 |
newTCP:aServiceOrNil |
|
1172 |
"create a TCP socket for a service - |
|
1173 |
neither connect nor connect-wait is done." |
|
1174 |
||
1175 |
|newSock| |
|
1176 |
||
1177 |
newSock := self newTCP. |
|
1178 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
819 | 1179 |
(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[ |
1180 |
^ nil |
|
1181 |
] |
|
126 | 1182 |
]. |
1183 |
^ newSock |
|
1184 |
||
1185 |
||
1186 |
"Socket newTCP:'nntp'" |
|
1187 |
"Socket newTCP:9995" |
|
1188 |
! |
|
1189 |
||
576 | 1190 |
newTCPclientToAddress:aHostAddress port:aService |
1191 |
"create a new TCP client socket connecting to a service. |
|
1192 |
Return a socket instance if ok, nil on failure. |
|
1193 |
Block until a connection is established (but only the current thread; |
|
1194 |
not the whole smalltalk). |
|
1195 |
See also: #newTCPclientToAddress:port:withTimeout:" |
|
1196 |
||
1197 |
^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil |
|
1198 |
! |
|
1199 |
||
1200 |
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis |
|
1201 |
"create a new TCP client socket connecting to a service. |
|
1202 |
Return a socket instance if ok, nil on failure. |
|
1203 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 1204 |
and return nil." |
576 | 1205 |
|
1206 |
^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis |
|
1207 |
! |
|
1208 |
||
126 | 1209 |
newTCPclientToHost:hostname port:aService |
1210 |
"create a new TCP client socket connecting to a service. |
|
1211 |
Return a socket instance if ok, nil on failure. |
|
1212 |
Block until a connection is established (but only the current thread; |
|
1213 |
not the whole smalltalk). |
|
1214 |
See also: #newTCPclientToHost:port:withTimeout:" |
|
1215 |
||
1216 |
^ self newTCPclientToHost:hostname port:aService withTimeout:nil |
|
1217 |
||
1218 |
" |
|
1219 |
Socket newTCPclientToHost:'localhost' port:'nntp' |
|
1220 |
" |
|
1221 |
||
1222 |
"Created: 31.10.1995 / 18:54:11 / cg" |
|
1223 |
! |
|
1224 |
||
1225 |
newTCPclientToHost:hostname port:aService withTimeout:millis |
|
1226 |
"create a new TCP client socket connecting to a service. |
|
1227 |
Return a socket instance if ok, nil on failure. |
|
1228 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
1229 |
and return nil.." |
|
1230 |
||
1231 |
|newSock| |
|
1232 |
||
1233 |
newSock := self newTCP. |
|
1234 |
newSock notNil ifTrue:[ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1235 |
(newSock connectTo:hostname |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1236 |
port:(self portOfService:aService protocol:'tcp') |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1237 |
withTimeout:millis |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1238 |
) ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1239 |
newSock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1240 |
^ nil |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1241 |
] |
126 | 1242 |
]. |
1243 |
^ newSock |
|
1244 |
" |
|
1245 |
same as: |
|
1246 |
^ (self new) for:hostname port:(self portOfService:aPort). |
|
1247 |
" |
|
1248 |
" |
|
1249 |
Socket newTCPclientToHost:'slsv6bt' port:'nntp' |
|
1250 |
Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000 |
|
1251 |
" |
|
604 | 1252 |
|
1253 |
"Modified: / 16.1.1998 / 09:47:06 / stefan" |
|
126 | 1254 |
! |
1255 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1256 |
newTCPserverAtAnonymousPort |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1257 |
"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
|
1258 |
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
|
1259 |
|
811 | 1260 |
^ self newTCPserverAtPort:0 |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1261 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1262 |
! |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
1263 |
|
126 | 1264 |
newTCPserverAtPort:aService |
1265 |
"create a new TCP server socket providing service." |
|
1266 |
||
1267 |
|newSock| |
|
1268 |
||
1269 |
newSock := self newTCP. |
|
1270 |
newSock notNil ifTrue:[ |
|
1271 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1272 |
^ nil |
|
1273 |
] |
|
1274 |
]. |
|
1275 |
^ newSock |
|
1276 |
" |
|
1277 |
same as: |
|
1278 |
^ (self new) for:nil port:aPort |
|
1279 |
" |
|
1280 |
! |
|
1281 |
||
1282 |
newUDP |
|
1283 |
"create a UDP socket - no binding or other setup is done, |
|
1284 |
neither connect nor connect-wait is done." |
|
1285 |
||
1286 |
^ self new domain:#inet type:#datagram |
|
1287 |
||
1288 |
"Socket newUDP" |
|
1289 |
! |
|
1290 |
||
1291 |
newUDP:aServiceOrNil |
|
1292 |
"create a UDP socket for a service - |
|
1293 |
neither connect nor connect-wait is done." |
|
1294 |
||
1295 |
|newSock| |
|
1296 |
||
1297 |
newSock := self newUDP. |
|
1298 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
819 | 1299 |
(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[ |
1300 |
^ nil |
|
1301 |
] |
|
126 | 1302 |
]. |
1303 |
^ newSock |
|
1304 |
||
1305 |
"Socket newUDP:nil" |
|
1306 |
! |
|
1307 |
||
1308 |
newUDPserverAtPort:aService |
|
1309 |
"create a new UDP server socket providing service." |
|
1310 |
||
1311 |
|newSock| |
|
1312 |
||
1313 |
newSock := self newUDP. |
|
1314 |
newSock notNil ifTrue:[ |
|
1315 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1316 |
^ nil |
|
1317 |
] |
|
1318 |
]. |
|
1319 |
^ newSock |
|
1320 |
" |
|
1321 |
same as: |
|
1322 |
^ (self new) for:nil udpPort:aPort |
|
1323 |
" |
|
1324 |
! |
|
1325 |
||
1326 |
newUNIX |
|
1327 |
"create a UNIX domain socket - no binding or other setup is done, |
|
811 | 1328 |
neither connect nor connect-wait is done. |
1329 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1330 |
return nil." |
|
126 | 1331 |
|
1332 |
^ self new domain:#unix type:#stream |
|
1333 |
||
1334 |
" |
|
1335 |
Socket newUNIX |
|
1336 |
" |
|
1337 |
! |
|
1338 |
||
1339 |
newUNIXclientTo:pathName |
|
1340 |
"create a new UNIX client socket connecting to a pathname. |
|
1341 |
Return a socket instance if ok, nil on failure. |
|
1342 |
Block until a connection is established (but only the current thread; |
|
1343 |
not the whole smalltalk). |
|
811 | 1344 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
1345 |
return nil. |
|
126 | 1346 |
See also: #newUNIXclientTo:withTimeout:" |
1347 |
||
1348 |
^ self newUNIXclientTo:pathName withTimeout:nil |
|
1349 |
||
1350 |
! |
|
1351 |
||
1352 |
newUNIXclientTo:pathName withTimeout:millis |
|
1353 |
"create a new UNIX client socket connecting to a pathname. |
|
1354 |
Return a socket instance if ok, nil on failure. |
|
1355 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
811 | 1356 |
and return nil. |
1357 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1358 |
return nil." |
|
126 | 1359 |
|
1360 |
|newSock| |
|
1361 |
||
1362 |
newSock := self newUNIX. |
|
1363 |
newSock notNil ifTrue:[ |
|
812 | 1364 |
(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[ |
1365 |
newSock close. |
|
1366 |
^ nil |
|
1367 |
] |
|
126 | 1368 |
]. |
1369 |
^ newSock |
|
1370 |
||
1371 |
" |
|
1372 |
|s| |
|
1373 |
||
1374 |
s := Socket newUNIXclientTo:'/tmp/foo' |
|
1375 |
" |
|
1376 |
! |
|
1377 |
||
1378 |
newUNIXserverAt:pathName |
|
811 | 1379 |
"create a new UNIX server socket providing service at a pathname. |
1380 |
If the system does not support unix domain sockets (i.e. VMS or MSDOS), |
|
1381 |
return nil." |
|
126 | 1382 |
|
1383 |
|newSock| |
|
1384 |
||
1385 |
newSock := self newUNIX. |
|
1386 |
newSock notNil ifTrue:[ |
|
812 | 1387 |
(newSock bindTo:pathName address:nil) ifFalse:[ |
1388 |
^ nil |
|
1389 |
] |
|
126 | 1390 |
]. |
1391 |
^ newSock |
|
1392 |
||
1393 |
" |
|
1394 |
|s s2| |
|
1395 |
||
1396 |
s := Socket newUNIXserverAt:'/tmp/foo'. |
|
1397 |
s listenFor:5. |
|
1398 |
s2 := s accept. |
|
1399 |
" |
|
1400 |
! ! |
|
1401 |
||
525 | 1402 |
!Socket class methodsFor:'host queries'! |
1403 |
||
1404 |
appletalkAddressOfHost:aHostName |
|
1405 |
"return the APPLETALK address for a hostname as a byteArray, |
|
819 | 1406 |
where the network bytes come first (no matter what the local byteorder is) |
1407 |
followed by the node byte. |
|
525 | 1408 |
If the host is unknown, return nil. |
812 | 1409 |
This is the reverse operation to #hostWithAppletalkAddress:. |
1410 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1411 |
|
1120 | 1412 |
%{ /* STACK: 100000 */ |
526 | 1413 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
819 | 1414 |
struct sockaddr_at sa; |
525 | 1415 |
struct hostent *hp ; |
1416 |
long addr; |
|
653 | 1417 |
OBJ rslt; |
525 | 1418 |
|
529 | 1419 |
sa.sat_family = -1; |
525 | 1420 |
|
1421 |
if (__isString(aHostName)) { |
|
789 | 1422 |
bzero(&sa, sizeof(sa)) ; |
1423 |
||
1424 |
/* do we know the host's address? */ |
|
1425 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1426 |
if (hp == NULL) { |
|
819 | 1427 |
DBGPRINTF(("SOCKET: unknown appletalk host: %s\n", __stringVal(aHostName))); |
789 | 1428 |
RETURN ( nil ); |
1429 |
} |
|
1430 |
bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ; |
|
1431 |
sa.sat_family = hp->h_addrtype; |
|
525 | 1432 |
} |
1433 |
||
752 | 1434 |
/* if the addressing family is not AF_APPLETALK, Return nil */ |
812 | 1435 |
if (sa.sat_family != AF_APPLETALK) { |
789 | 1436 |
DBGPRINTF(("SOCKET: not an appletalk host\n")); |
1437 |
RETURN ( nil ); |
|
525 | 1438 |
} |
1439 |
||
1440 |
sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net); |
|
653 | 1441 |
rslt = __BYTEARRAY_NEW_INT(3); |
1442 |
if (rslt != nil) { |
|
789 | 1443 |
__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sat_addr.s_net >> 8) & 0xFF; |
1444 |
__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF; |
|
1445 |
__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sat_addr.s_node) & 0xFF; |
|
653 | 1446 |
RETURN (rslt); |
1447 |
} |
|
525 | 1448 |
#endif |
1449 |
%}. |
|
653 | 1450 |
^ nil |
525 | 1451 |
|
1452 |
! |
|
1453 |
||
1454 |
hostWithAppletalkAddress:anAddress |
|
1455 |
"return the hostname for an APPLETALK address. |
|
1456 |
The address is supposed to be a byteArray consisting of 3 bytes, |
|
1457 |
the network bytes come first (no matter what the local byteorder is). |
|
1458 |
The last byte is the node number. |
|
1459 |
Nil is returned for an unknown host or if its not an appletalk host. |
|
812 | 1460 |
This is is the reverse operation to #appletalkAddressOfHost:. |
1461 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1462 |
|
1463 |
|b1 b2 b3 b4| |
|
1464 |
||
812 | 1465 |
b1 := anAddress at:1. "/ net-hi |
1466 |
b2 := anAddress at:2. "/ net-low |
|
1467 |
b3 := anAddress at:3. "/ node |
|
1120 | 1468 |
|
1469 |
%{ /* STACK: 100000 */ |
|
525 | 1470 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
1471 |
struct sockaddr_at sa ; |
|
1472 |
struct hostent *hp ; |
|
1473 |
||
1474 |
sa.sat_family = -1; |
|
1475 |
||
1476 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
|
1477 |
bzero(&sa, sizeof(sa)) ; |
|
1478 |
||
1009 | 1479 |
sa.sat_addr.s_net = __intVal(b1) & 0xFF; |
1480 |
sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (__intVal(b2) & 0xFF); |
|
529 | 1481 |
sa.sat_addr.s_net = htons(sa.sat_addr.s_net); |
1009 | 1482 |
sa.sat_addr.s_node = __intVal(b3) & 0xFF; |
529 | 1483 |
sa.sat_family = AF_APPLETALK; |
1484 |
||
525 | 1485 |
/* do we know the host's address? */ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
1486 |
GETHOSTBYADDR(hp, (char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK); |
525 | 1487 |
if (hp != NULL) { |
1488 |
sa.sat_family = hp->h_addrtype; |
|
1489 |
} else { |
|
819 | 1490 |
DBGPRINTF(("SOCKET: unknown appletalk address: %d.%d.%d.%d\n", |
1009 | 1491 |
__intVal(b1), __intVal(b2), __intVal(b3))); |
525 | 1492 |
} |
1493 |
} |
|
1494 |
||
752 | 1495 |
/* if the addressing family is not AF_APPLETALK, Return nil */ |
525 | 1496 |
if (sa.sat_family != AF_APPLETALK) { |
819 | 1497 |
DBGPRINTF(("SOCKET: not an appletalk host\n")); |
525 | 1498 |
RETURN ( nil ); |
1499 |
} |
|
1500 |
||
1501 |
if (hp != NULL) { |
|
1502 |
RETURN (__MKSTRING(hp->h_name)); |
|
1503 |
} |
|
1504 |
#endif |
|
1505 |
RETURN (nil); |
|
1506 |
%}. |
|
1507 |
" |
|
1508 |
Socket appletalkAddressOfHost:'clam' |
|
1509 |
Socket hostWithAppletalkAddress:#[1 2 3] |
|
1510 |
" |
|
126 | 1511 |
! |
1512 |
||
1513 |
hostWithIpAddress:anAddress |
|
1514 |
"return the hostname for an IP (internet-) address. |
|
1515 |
The address is supposed to be a byteArray consisting of 4 bytes, |
|
1516 |
the network bytes come first (no matter what the local byteorder is). |
|
525 | 1517 |
Nil is returned for an unknown host or if its not an internet host. |
126 | 1518 |
This is the reverse operation to #ipAddressOfHost:." |
1519 |
||
1520 |
|b1 b2 b3 b4| |
|
1521 |
||
1522 |
b1 := anAddress at:1. |
|
1523 |
b2 := anAddress at:2. |
|
1524 |
b3 := anAddress at:3. |
|
1525 |
b4 := anAddress at:4. |
|
1120 | 1526 |
|
1527 |
%{ /* STACK: 100000 */ |
|
525 | 1528 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
126 | 1529 |
struct sockaddr_in sa ; |
1530 |
struct hostent *hp ; |
|
1531 |
||
525 | 1532 |
sa.sin_family = -1; |
126 | 1533 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
822 | 1534 |
bzero(&sa, sizeof(sa)) ; |
1009 | 1535 |
sa.sin_addr.s_addr = __intVal(b1) & 0xFF; |
1536 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b2) & 0xFF); |
|
1537 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b3) & 0xFF); |
|
1538 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b4) & 0xFF); |
|
822 | 1539 |
sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr); |
1540 |
sa.sin_family = AF_INET; |
|
1541 |
/* do we know the host's address? */ |
|
1542 |
GETHOSTBYADDR(hp, (char *) &sa.sin_addr, sizeof(sa.sin_addr), AF_INET); |
|
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1543 |
|
822 | 1544 |
if (hp == NULL) { |
1545 |
DBGPRINTF(("SOCKET: unknown ip address: %d.%d.%d.%d\n", |
|
1009 | 1546 |
__intVal(b1), __intVal(b2), __intVal(b3), __intVal(b4))); |
822 | 1547 |
} else { |
1548 |
sa.sin_family = hp->h_addrtype; |
|
1549 |
} |
|
126 | 1550 |
} |
1551 |
||
752 | 1552 |
/* if the addressing family is not AF_INET, Return nil */ |
126 | 1553 |
if (sa.sin_family != AF_INET) { |
822 | 1554 |
RETURN ( nil ); |
126 | 1555 |
} |
525 | 1556 |
|
1557 |
if (hp != NULL) { |
|
822 | 1558 |
RETURN (__MKSTRING(hp->h_name)); |
525 | 1559 |
} |
1560 |
||
1561 |
/* |
|
752 | 1562 |
* Return it in dot-notation |
525 | 1563 |
*/ |
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1564 |
RETURN (__MKSTRING(inet_ntoa(sa.sin_addr))); |
418 | 1565 |
#else |
1566 |
RETURN (nil); |
|
1567 |
#endif |
|
126 | 1568 |
%} |
1569 |
||
1570 |
" |
|
1571 |
Socket ipAddressOfHost:'clam' |
|
1572 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') |
|
1573 |
Socket ipAddressOfHost:'porty' |
|
1574 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') |
|
1575 |
Socket hostWithIpAddress:#[1 2 3 4] |
|
796 | 1576 |
Socket hostWithIpAddress:#[127 0 0 1] |
126 | 1577 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4') |
1578 |
" |
|
1579 |
! |
|
1580 |
||
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1581 |
hostWithIpV6Address:anAddress |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1582 |
"return the hostname for an IPv6 (internet-) address. |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1583 |
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
|
1584 |
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
|
1585 |
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
|
1586 |
This is the reverse operation to #ipV6AddressOfHost:." |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1587 |
|
1120 | 1588 |
%{ /* STACK: 100000 */ |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1589 |
#if !defined(NO_SOCKET) && defined(AF_INET6) |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1590 |
struct sockaddr_in6 sa ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1591 |
struct hostent *hp ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1592 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1593 |
sa.sin6_family = -1; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1594 |
if (__isByteArray(anAddress)) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1595 |
bzero(&sa, sizeof(sa)) ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1596 |
if (__byteArraySize(anAddress) <= sizeof(sa.sin6_addr.s6_addr)) |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1597 |
goto bad; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1598 |
bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(anAddress)->ba_element, sizeof(sa.sin6_addr.s6_addr)); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1599 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1600 |
sa.sin6_family = AF_INET6; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1601 |
/* do we know the host's address? */ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1602 |
GETHOSTBYADDR(hp, (char *) &sa.sin6_addr, sizeof(sa.sin6_addr), AF_INET6); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1603 |
if (hp == NULL) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1604 |
DBGPRINTF(("SOCKET: unknown ipv6 address: %d.%d.%d.%d...\n", |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1605 |
sa.sin6_addr.s6_addr[0], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1606 |
sa.sin6_addr.s6_addr[1], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1607 |
sa.sin6_addr.s6_addr[2], |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1608 |
sa.sin6_addr.s6_addr[3] )); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1609 |
} else { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1610 |
sa.sin6_family = hp->h_addrtype; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1611 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1612 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1613 |
bad: ; |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1614 |
/* if the addressing family is not AF_INET6, Return nil */ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1615 |
if (sa.sin6_family != AF_INET6) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1616 |
DBGPRINTF(("SOCKET: not an ipv6 host\n")); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1617 |
RETURN ( nil ); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1618 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1619 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1620 |
if (hp != NULL) { |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1621 |
RETURN (__MKSTRING(hp->h_name)); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1622 |
} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1623 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1624 |
/* |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1625 |
* Return it in dot-notation |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1626 |
*/ |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1627 |
RETURN (__MKSTRING(inet_ntoa(sa.sin6_addr))); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1628 |
#else |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1629 |
RETURN (nil); |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1630 |
#endif |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1631 |
%} |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1632 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1633 |
" |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1634 |
Socket ipV6AddressOfHost:'clam' |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1635 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1636 |
Socket ipV6AddressOfHost:'porty' |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1637 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1638 |
Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14] |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1639 |
" |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1640 |
! |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1641 |
|
6 | 1642 |
ipAddressOfHost:aHostName |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1643 |
"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
|
1644 |
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
|
1645 |
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
|
1646 |
This is the reverse operation to #hostWithIpAddress:." |
6 | 1647 |
|
1120 | 1648 |
%{ /* STACK: 100000 */ |
525 | 1649 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
6 | 1650 |
struct sockaddr_in sa ; |
1651 |
struct hostent *hp ; |
|
1652 |
long addr; |
|
653 | 1653 |
OBJ rslt; |
6 | 1654 |
|
525 | 1655 |
sa.sin_family = -1; |
1656 |
||
21 | 1657 |
if (__isString(aHostName)) { |
812 | 1658 |
bzero(&sa, sizeof(sa)) ; |
1659 |
if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) { |
|
1660 |
/* is Internet addr in octet notation */ |
|
1661 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); |
|
1662 |
sa.sin_family = AF_INET; |
|
1663 |
} else { |
|
1664 |
/* do we know the host's address? */ |
|
1665 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1666 |
if (hp == NULL) { |
|
819 | 1667 |
DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName))); |
812 | 1668 |
RETURN ( nil ); |
1669 |
} |
|
1670 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
1671 |
sa.sin_family = hp->h_addrtype; |
|
1672 |
} |
|
6 | 1673 |
} |
525 | 1674 |
|
752 | 1675 |
/* if the addressing family is not AF_INET, Return nil */ |
6 | 1676 |
if (sa.sin_family != AF_INET) { |
819 | 1677 |
DBGPRINTF(("SOCKET: not an ip host\n")); |
812 | 1678 |
RETURN ( nil ); |
6 | 1679 |
} |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1680 |
|
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1681 |
sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr); |
653 | 1682 |
rslt = __BYTEARRAY_NEW_INT(4); |
1683 |
if (rslt != nil) { |
|
812 | 1684 |
__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF; |
1685 |
__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF; |
|
1686 |
__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF; |
|
1687 |
__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF; |
|
653 | 1688 |
RETURN (rslt); |
1689 |
} |
|
418 | 1690 |
#endif |
525 | 1691 |
%}. |
653 | 1692 |
^ nil |
21 | 1693 |
|
71 | 1694 |
" |
796 | 1695 |
Socket ipAddressOfHost:'localhost' |
1696 |
Socket ipAddressOfHost:'exept' |
|
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1697 |
Socket ipAddressOfHost:'1.2.3.4' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1698 |
Socket ipAddressOfHost:'193.15.16.17' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1699 |
Socket ipAddressOfHost:'josef' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1700 |
Socket ipAddressOfHost:'styx.com' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1701 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1702 |
Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') |
71 | 1703 |
" |
819 | 1704 |
! |
1705 |
||
1706 |
ipV6AddressOfHost:aHostName |
|
1707 |
"return the IPv6 (internet-) number for a hostname as a byteArray, |
|
1708 |
where the network bytes come first (no matter what the cpus byteOrder is). |
|
1709 |
If the host is unknown, return nil. |
|
1710 |
This is the reverse operation to #hostWithIpV6Address:." |
|
1711 |
||
1120 | 1712 |
%{ /* STACK: 100000 */ |
819 | 1713 |
#if !defined(NO_SOCKET) && defined(AF_INET6) |
1714 |
struct sockaddr_in6 sa; |
|
1715 |
struct hostent *hp ; |
|
1716 |
long addr; |
|
1717 |
OBJ rslt; |
|
1718 |
||
1719 |
sa.sin6_family = -1; |
|
1720 |
||
1721 |
if (__isString(aHostName)) { |
|
1722 |
bzero(&sa, sizeof(sa)) ; |
|
1723 |
#if 0 |
|
1724 |
if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) { |
|
1725 |
/* is Internet addr in octet notation */ |
|
1726 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); |
|
1727 |
sa.sin_family = AF_INET; |
|
1728 |
} else |
|
1729 |
#endif |
|
1730 |
{ |
|
1731 |
/* do we know the host's address? */ |
|
1732 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
|
1733 |
if (hp == NULL) { |
|
1734 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName))); |
|
1735 |
RETURN ( nil ); |
|
1736 |
} |
|
1737 |
bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ; |
|
1738 |
sa.sin6_family = hp->h_addrtype; |
|
1739 |
} |
|
1740 |
} |
|
1741 |
||
1742 |
/* if the addressing family is not AF_INET, Return nil */ |
|
1743 |
if (sa.sin6_family != AF_INET) { |
|
1744 |
DBGPRINTF(("SOCKET: not an ipv6 host\n")); |
|
1745 |
RETURN ( nil ); |
|
1746 |
} |
|
1747 |
||
1748 |
rslt = __BYTEARRAY_NEW_INT(hp->h_length); |
|
1749 |
if (rslt != nil) { |
|
1750 |
bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(rslt)->ba_element, hp->h_length); |
|
1751 |
RETURN (rslt); |
|
1752 |
} |
|
1753 |
#endif |
|
1754 |
%}. |
|
1755 |
^ nil |
|
1756 |
||
1757 |
" |
|
1758 |
Socket ipV6AddressOfHost:'localhost' |
|
1759 |
Socket ipV6AddressOfHost:'exept' |
|
1760 |
Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16' |
|
1761 |
Socket ipV6AddressOfHost:'193.15.16.17' |
|
1762 |
Socket ipV6AddressOfHost:'josef' |
|
1763 |
Socket ipV6AddressOfHost:'styx.com' |
|
1764 |
Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') |
|
1765 |
Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') |
|
1766 |
" |
|
531 | 1767 |
! ! |
1768 |
||
1209 | 1769 |
!Socket class methodsFor:'obsolete'! |
1770 |
||
1771 |
connectTo:service on:host |
|
1772 |
"standard & easy client setup: |
|
1773 |
create new client tcp socket, bind and connect; |
|
1774 |
return the socket. |
|
1775 |
The thread block (interruptable), until the connection is |
|
1776 |
established." |
|
1777 |
||
1778 |
<resource:#obsolete> |
|
1779 |
||
1780 |
self obsoleteMethodWarning:'use newTCP: / connect'. |
|
1781 |
||
1782 |
^ (self new) for:host port:(self portOfService:service). |
|
1783 |
||
1784 |
" |
|
1785 |
Socket connectTo:9995 on:'clam' |
|
1786 |
Socket connectTo:4711 on:'exept' |
|
1787 |
Socket connectTo:'finger' on:'clam' |
|
1788 |
Socket connectTo:'ftp' on:'exept' |
|
1789 |
Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER') |
|
1790 |
" |
|
1791 |
! |
|
1792 |
||
1793 |
provide:service |
|
1794 |
"standard & easy server setup: |
|
1795 |
create a new TCP server socket providing a service." |
|
1796 |
||
1797 |
<resource:#obsolete> |
|
1798 |
||
1799 |
|newSock| |
|
1800 |
||
1801 |
self obsoleteMethodWarning:'use newTCP: / listen'. |
|
1802 |
||
1803 |
newSock := (self new) for:nil port:(self portOfService:service). |
|
1804 |
newSock notNil ifTrue:[ |
|
1805 |
newSock listenFor:5. |
|
1806 |
]. |
|
1807 |
^ newSock |
|
1808 |
||
1809 |
" |
|
1810 |
Socket provide:9995 |
|
1811 |
(Socket provide:9996) accept |
|
1812 |
Socket provide:'nntp' |
|
1813 |
" |
|
1814 |
! ! |
|
1815 |
||
531 | 1816 |
!Socket class methodsFor:'queries'! |
1817 |
||
1818 |
domainOfProtocol:aProtocol |
|
1819 |
"given a protocols name (i.e. tcp, udp etc) return the domain. |
|
1820 |
This method needs more ... - or is there a way to get this from the system ?" |
|
1821 |
||
1822 |
" |
|
1823 |
tcp/ip stuff |
|
1824 |
" |
|
1825 |
(aProtocol = 'tcp') ifTrue:[^ #inet]. |
|
1826 |
(aProtocol = 'udp') ifTrue:[^ #inet]. |
|
1827 |
(aProtocol = 'ip') ifTrue:[^ #inet]. |
|
1828 |
" |
|
1829 |
unix domain |
|
1830 |
" |
|
1831 |
(aProtocol = 'ud') ifTrue:[^ #unix]. |
|
1832 |
||
1833 |
" |
|
1834 |
add x25 stuff (if any) here ... |
|
1835 |
" |
|
1836 |
" |
|
1837 |
add appletalk stuff (if any) here ... |
|
1838 |
" |
|
1839 |
" |
|
1840 |
add other stuff (if any) here ... |
|
1841 |
" |
|
1842 |
^ nil |
|
1843 |
||
1844 |
" |
|
1845 |
Socket domainOfProtocol:'tcp' |
|
1846 |
Socket domainOfProtocol:'ucp' |
|
1847 |
Socket domainOfProtocol:(Socket protocolOfService:'nntp') |
|
1848 |
Socket domainOfProtocol:(Socket protocolOfService:'echo') |
|
1849 |
" |
|
6 | 1850 |
! |
1851 |
||
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1852 |
networkLongOrderIsMSB |
964 | 1853 |
"return true, if the network-byte-order of longs is MSB (which it is). |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1854 |
To be used as in: |
1009 | 1855 |
'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'." |
964 | 1856 |
|
1857 |
^ true |
|
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1858 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1859 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1860 |
Socket networkLongOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1861 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1862 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1863 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1864 |
networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1865 |
"return true, if the network-byte-order of shorts is MSB. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1866 |
To be used as in: |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1867 |
'aStream nextPutShort:someValue MSB:(Socket networkShortOrderIsMSB)'." |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1868 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1869 |
%{ /* NOCONTEXT */ |
418 | 1870 |
#ifndef NO_SOCKET |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1871 |
/* |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1872 |
* mhmh - do c-compilers optimize this away ? |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1873 |
*/ |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1874 |
if (htons(0x3210) == 0x3210) { |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1875 |
RETURN (true); |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1876 |
} |
418 | 1877 |
#endif |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1878 |
%}. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1879 |
^ false |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1880 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1881 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1882 |
Socket networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1883 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1884 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1885 |
|
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1886 |
peerFromDomain:domain name:peerName port:port |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1887 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1888 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1889 |
addrClass := self socketAddressClassForDomain:domain. |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1890 |
^ addrClass peerName:peerName port:port |
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
|
1891 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1892 |
|
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1893 |
peerNameFromDomain:domain peer:peer |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1894 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1895 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1896 |
addrClass := self socketAddressClassForDomain:domain. |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1897 |
^ 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
|
1898 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1899 |
|
0 | 1900 |
portOfService:aNameOrNumber |
819 | 1901 |
"returns the port-number for a given IP-service |
0 | 1902 |
or nil if no such service exists; |
1903 |
- used to convert service names to portNumbers" |
|
1904 |
||
91 | 1905 |
^ self portOfService:aNameOrNumber protocol:nil |
1906 |
||
28 | 1907 |
" |
1908 |
Socket portOfService:'finger' |
|
74 | 1909 |
Socket portOfService:'nntp' |
1910 |
Socket portOfService:'echo' |
|
1911 |
Socket portOfService:'snmp' |
|
28 | 1912 |
" |
0 | 1913 |
! |
1914 |
||
91 | 1915 |
portOfService:aNameOrNumber protocol:aProtocol |
819 | 1916 |
"returns the port-number for a given IP-service |
91 | 1917 |
or nil if no such service exists; |
1918 |
- used to convert service names to portNumbers" |
|
1919 |
||
604 | 1920 |
%{ /* NOCONTEXT */ |
418 | 1921 |
#ifndef NO_SOCKET |
91 | 1922 |
struct servent *servent = NULL; |
1923 |
char *protocol; |
|
1924 |
int tryBoth = 0; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1925 |
short portNo; |
91 | 1926 |
|
604 | 1927 |
if (__isSmallInteger(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1928 |
RETURN ( aNameOrNumber ); |
92 | 1929 |
} |
1930 |
||
604 | 1931 |
if (__isString(aProtocol)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1932 |
protocol = (char *)__stringVal(aProtocol); |
604 | 1933 |
} else { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1934 |
protocol = "tcp"; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1935 |
tryBoth = 1; |
91 | 1936 |
} |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1937 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1938 |
if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1939 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1940 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1941 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1942 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1943 |
if (tryBoth) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1944 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1945 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1946 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1947 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1948 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1949 |
RETURN ( nil ); |
91 | 1950 |
} |
418 | 1951 |
#endif |
91 | 1952 |
RETURN ( nil ); |
1953 |
%} |
|
1954 |
" |
|
1955 |
Socket portOfService:'echo' protocol:'udp' |
|
1956 |
Socket portOfService:'echo' protocol:'tcp' |
|
1957 |
" |
|
1958 |
! |
|
1959 |
||
0 | 1960 |
protocolOfService:aNameOrNumber |
819 | 1961 |
"returns the protocol (as string) for a given IP-service |
28 | 1962 |
or nil if no such service exists." |
0 | 1963 |
%{ |
418 | 1964 |
#ifndef NO_SOCKET |
0 | 1965 |
struct servent *servent = NULL; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1966 |
short portNo; |
0 | 1967 |
|
58 | 1968 |
if (__isSmallInteger(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1969 |
portNo = __intVal(aNameOrNumber); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1970 |
servent = getservbyport(htons(portNo), "tcp") ; |
42 | 1971 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1972 |
servent = getservbyport(htons(portNo), "udp") ; |
42 | 1973 |
if (servent == NULL) { |
1974 |
RETURN ( nil ); |
|
1975 |
} |
|
1976 |
} |
|
0 | 1977 |
} else { |
42 | 1978 |
if (__isString(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1979 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp"); |
42 | 1980 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1981 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
42 | 1982 |
if (servent == NULL) { |
1983 |
RETURN ( nil ); |
|
1984 |
} |
|
1985 |
} |
|
1986 |
} |
|
0 | 1987 |
} |
1988 |
if (servent) { |
|
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1989 |
RETURN ( __MKSTRING(servent->s_proto) ); |
0 | 1990 |
} |
418 | 1991 |
#endif |
0 | 1992 |
RETURN ( nil ); |
1993 |
%} |
|
28 | 1994 |
" |
74 | 1995 |
Socket protocolOfService:'finger' |
1996 |
Socket protocolOfService:'nntp' |
|
28 | 1997 |
Socket protocolOfService:'xxx' |
1998 |
Socket protocolOfService:79 |
|
74 | 1999 |
Socket protocolOfService:'snmp' |
28 | 2000 |
" |
2001 |
! |
|
2002 |
||
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
|
2003 |
socketAddressClassForDomain:domain |
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2004 |
^ SocketAddress knownClassFromCode:domain |
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2005 |
|
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2006 |
" |
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2007 |
self socketAddressClassForDomain:#inet |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
2008 |
self socketAddressClassForDomain:#unix |
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2009 |
" |
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
|
2010 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
2011 |
|
532 | 2012 |
supportedProtocolFamilies |
2013 |
"return a collection of supported protocol families. |
|
2014 |
This list specifies what the Socket class supports - |
|
2015 |
socket creation may still fail, if your system was built |
|
2016 |
without it." |
|
2017 |
||
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
2018 |
^ OperatingSystem socketAccessor supportedProtocolFamilies |
532 | 2019 |
|
2020 |
" |
|
2021 |
Socket supportedProtocolFamilies |
|
2022 |
" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2023 |
! |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2024 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2025 |
typeOfProtocol:aProtocol |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2026 |
"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
|
2027 |
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
|
2028 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2029 |
(aProtocol = 'tcp') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2030 |
(aProtocol = 'udp') ifTrue:[^ #datagram]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2031 |
(aProtocol = 'ip') ifTrue:[^ #raw]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2032 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2033 |
unix domain |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2034 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2035 |
(aProtocol = 'ud') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2036 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2037 |
add x25 stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2038 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2039 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2040 |
add appletalk stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2041 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2042 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2043 |
add other stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2044 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2045 |
^ nil |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2046 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2047 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2048 |
Socket typeOfProtocol:'tcp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2049 |
Socket typeOfProtocol:'ucp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2050 |
Socket typeOfProtocol:(Socket protocolOfService:'nntp') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2051 |
Socket typeOfProtocol:(Socket protocolOfService:'echo') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
2052 |
" |
28 | 2053 |
! ! |
2054 |
||
1202 | 2055 |
!Socket methodsFor:'Compatibility-Dolphin'! |
1110 | 2056 |
|
2057 |
setReceiveTimeout: milliseconds |
|
2058 |
self receiveTimeout:(milliseconds / 1000) |
|
2059 |
! |
|
2060 |
||
2061 |
setSendTimeout: milliseconds |
|
2062 |
self sendTimeout:(milliseconds / 1000) |
|
2063 |
! ! |
|
2064 |
||
1202 | 2065 |
!Socket methodsFor:'Compatibility-ST80'! |
28 | 2066 |
|
887 | 2067 |
acceptNonBlock |
2068 |
^ self accept |
|
2069 |
! |
|
2070 |
||
870 | 2071 |
connectTo:aSocketAddress |
2072 |
^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port |
|
2073 |
! |
|
2074 |
||
126 | 2075 |
errorReporter |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2076 |
"ST-80 mimicry." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2077 |
|
126 | 2078 |
^ self |
28 | 2079 |
! |
2080 |
||
887 | 2081 |
ioConnection |
2082 |
^ self |
|
2083 |
! |
|
2084 |
||
126 | 2085 |
notReadySignal |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2086 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2087 |
for now - this is not yet raised" |
71 | 2088 |
|
126 | 2089 |
^ Signal new |
486 | 2090 |
! |
2091 |
||
576 | 2092 |
readAppendStream |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2093 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2094 |
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
|
2095 |
ST-80 code therefore uses 'Socket readWriteStream' to access |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2096 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2097 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2098 |
this method returns the receiver, for transparency" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2099 |
|
576 | 2100 |
^ self |
2101 |
! |
|
2102 |
||
486 | 2103 |
readStream |
2104 |
"ST-80 mimicry. |
|
2105 |
In ST-80, socket is not a stream, but referes to one. |
|
2106 |
ST-80 code therefore uses 'Socket readStream' to access |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2107 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2108 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2109 |
this method returns the receiver, for transparency" |
486 | 2110 |
|
2111 |
^ self |
|
2112 |
||
2113 |
"Created: 24.1.1997 / 23:52:57 / cg" |
|
2114 |
! |
|
2115 |
||
576 | 2116 |
shutdown:how |
2117 |
"ST-80 compatibility" |
|
2118 |
||
2119 |
self shutDown |
|
2120 |
! |
|
2121 |
||
486 | 2122 |
writeStream |
2123 |
"ST-80 mimicry. |
|
2124 |
In ST-80, socket is not a stream, but referes to one. |
|
2125 |
ST-80 code therefore uses 'Socket writeStream' to access |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2126 |
the actual stream. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2127 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2128 |
this method returns the receiver, for transparency" |
486 | 2129 |
|
2130 |
^ self |
|
2131 |
||
2132 |
"Created: 24.1.1997 / 10:34:35 / cg" |
|
2133 |
"Modified: 24.1.1997 / 23:52:52 / cg" |
|
71 | 2134 |
! ! |
2135 |
||
1202 | 2136 |
!Socket methodsFor:'Compatibility-Squeak'! |
771 | 2137 |
|
2138 |
peerName |
|
2139 |
"return my peer (i.e. ipAddr + port); |
|
2140 |
May return nil if not yet setup completely." |
|
2141 |
||
2142 |
^ self getPeer |
|
2143 |
! ! |
|
2144 |
||
126 | 2145 |
!Socket methodsFor:'datagram transmission'! |
28 | 2146 |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2147 |
receiveBuffer:aDataBuffer start:startIndex for:nBytes |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2148 |
"receive data |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2149 |
Return the number of bytes received, or a negative number on error. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2150 |
On error, the unix error code is left in the lastErrorNumber |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2151 |
instance variable. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2152 |
The thread blocks until data arrives - you may want to wait before |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2153 |
receiving, using #readWait or #readWaitWithTimeout:." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2154 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2155 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2156 |
|nReceived| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2157 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2158 |
%{ |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2159 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2160 |
OBJ oClass, myDomain; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2161 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2162 |
int nInstVars, nInstBytes, objSize; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2163 |
int sock; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2164 |
int n; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2165 |
char *cp; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2166 |
int flags = 0; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2167 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2168 |
if (fp != nil) { |
1009 | 2169 |
sock = fileno(__FILEVal(fp)); |
2170 |
||
2171 |
oClass = __Class(aDataBuffer); |
|
2172 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2173 |
case BYTEARRAY: |
|
2174 |
case WORDARRAY: |
|
2175 |
case SWORDARRAY: |
|
2176 |
case LONGARRAY: |
|
2177 |
case SLONGARRAY: |
|
2178 |
case FLOATARRAY: |
|
2179 |
case DOUBLEARRAY: |
|
2180 |
break; |
|
2181 |
default: |
|
2182 |
goto bad; |
|
2183 |
} |
|
2184 |
||
2185 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2186 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2187 |
objSize = _Size(aDataBuffer) - nInstBytes; |
|
2188 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
|
2189 |
if (__isSmallInteger(startIndex)) { |
|
2190 |
cp += __intVal(startIndex); |
|
2191 |
objSize -= __intVal(startIndex); |
|
2192 |
} |
|
2193 |
if (__isSmallInteger(nBytes)) { |
|
2194 |
if (__intVal(nBytes) < objSize) { |
|
2195 |
objSize = __intVal(nBytes); |
|
2196 |
} |
|
2197 |
} |
|
2198 |
||
2199 |
__BEGIN_INTERRUPTABLE__ |
|
2200 |
do { |
|
2201 |
n = recv(sock, cp, objSize, flags); |
|
2202 |
} while ((n < 0) && (errno == EINTR)); |
|
2203 |
__END_INTERRUPTABLE__ |
|
2204 |
||
2205 |
if (n < 0) { |
|
2206 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2207 |
} |
|
2208 |
nReceived = __MKSMALLINT(n); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2209 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2210 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2211 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2212 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2213 |
nReceived notNil ifTrue:[ |
1009 | 2214 |
nReceived < 0 ifTrue:[ |
2215 |
'Socket [warning]: ' infoPrint. |
|
2216 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
|
2217 |
]. |
|
2218 |
^ nReceived |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2219 |
]. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2220 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2221 |
arrive here if you try to receive into an invalid buffer |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2222 |
(i.e. not ByteArray-like), |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2223 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2224 |
or if the addressBuffer is nonNil AND too small. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2225 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2226 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2227 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2228 |
|
126 | 2229 |
receiveFrom:anAddressBuffer buffer:aDataBuffer |
2230 |
"receive datagramm data - put address of originating host into |
|
2231 |
anAddressBuffer, data into aBuffer. |
|
2232 |
Both must be ByteArray-like. The addressBuffer must |
|
2233 |
provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2234 |
Return the number of bytes received, or a negative number on error. |
|
2235 |
On error, the unix error code is left in the lastErrorNumber |
|
2236 |
instance variable." |
|
28 | 2237 |
|
126 | 2238 |
^ 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
|
2239 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2240 |
|
126 | 2241 |
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes |
2242 |
"receive datagramm data - put address of originating host into |
|
2243 |
anAddressBuffer, data into aBuffer. For ST-80 compatibility, |
|
2244 |
the addressBuffer may be a non-ByteArray; then, it must understand |
|
2245 |
the addressBytes-message (i.e. be a SocketAddress instance). |
|
2246 |
Return the number of bytes received, or a negative number on error. |
|
2247 |
On error, the unix error code is left in the lastErrorNumber |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2248 |
instance variable. |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2249 |
The thread blocks until data arrives - you may want to wait before |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2250 |
receiving, using #readWait or #readWaitWithTimeout:." |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2251 |
|
1009 | 2252 |
|addrBytes addrLen nReceived addrPort| |
28 | 2253 |
|
126 | 2254 |
addrBytes := ByteArray new:100. |
2255 |
%{ |
|
418 | 2256 |
#ifndef NO_SOCKET |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2257 |
OBJ oClass, myDomain; |
217 | 2258 |
OBJ fp = __INST(filePointer); |
126 | 2259 |
int nInstVars, nInstBytes, objSize; |
2260 |
int sock; |
|
819 | 2261 |
union sockaddr_u sa; |
1009 | 2262 |
int alen = 0; |
2263 |
int n, offs, sIdx; |
|
126 | 2264 |
char *cp; |
2265 |
int flags = 0; |
|
2266 |
||
2267 |
if (fp != nil) { |
|
1009 | 2268 |
sock = fileno(__FILEVal(fp)); |
2269 |
||
2270 |
oClass = __Class(aDataBuffer); |
|
2271 |
offs = 0; |
|
1010 | 2272 |
sIdx = 0; |
2273 |
if (__isSmallInteger(startIndex)) { |
|
2274 |
sIdx = __intVal(startIndex) - 1; |
|
2275 |
} |
|
1009 | 2276 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
2277 |
case BYTEARRAY: |
|
2278 |
offs = sIdx; |
|
2279 |
break; |
|
2280 |
case WORDARRAY: |
|
2281 |
case SWORDARRAY: |
|
2282 |
offs = sIdx * 2; |
|
2283 |
break; |
|
2284 |
case LONGARRAY: |
|
2285 |
case SLONGARRAY: |
|
2286 |
offs = sIdx * 4; |
|
2287 |
break; |
|
2288 |
case LONGLONGARRAY: |
|
2289 |
case SLONGLONGARRAY: |
|
2290 |
offs = sIdx * 8; |
|
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2291 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2292 |
offs += 4; |
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2293 |
# endif |
1010 | 2294 |
break; |
1009 | 2295 |
case FLOATARRAY: |
2296 |
offs = sIdx * sizeof(float); |
|
2297 |
break; |
|
2298 |
case DOUBLEARRAY: |
|
2299 |
offs = sIdx * sizeof(double); |
|
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2300 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2301 |
offs += 4; |
1003
0157b8af9a1e
oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents:
969
diff
changeset
|
2302 |
# endif |
1009 | 2303 |
break; |
2304 |
default: |
|
2305 |
goto bad; |
|
2306 |
} |
|
2307 |
||
2308 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2309 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2310 |
objSize = _Size(aDataBuffer) - nInstBytes; |
|
2311 |
objSize -= offs; |
|
2312 |
if (__isSmallInteger(nBytes)) { |
|
2313 |
if (__intVal(nBytes) < objSize) { |
|
2314 |
objSize = __intVal(nBytes); |
|
2315 |
} |
|
2316 |
} |
|
2317 |
||
2318 |
__BEGIN_INTERRUPTABLE__ |
|
2319 |
do { |
|
2320 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs; |
|
2321 |
alen = sizeof(sa); |
|
2322 |
n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen); |
|
2323 |
} while ((n < 0) && (errno == EINTR)); |
|
2324 |
__END_INTERRUPTABLE__ |
|
2325 |
||
2326 |
if (n >= 0) { |
|
2327 |
if (__isNonNilObject(addrBytes)) { |
|
2328 |
oClass = __qClass(addrBytes); |
|
2329 |
if ((__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) |
|
2330 |
goto bad; |
|
2331 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2332 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
|
2333 |
objSize = __qSize(addrBytes) - nInstBytes; |
|
2334 |
cp = (char *)__InstPtr(addrBytes) + nInstBytes; |
|
2335 |
if (objSize < alen) |
|
2336 |
goto bad; |
|
2337 |
||
2338 |
myDomain = __INST(domain); |
|
2339 |
||
2340 |
/* |
|
2341 |
* extract the datagrams address |
|
2342 |
*/ |
|
2343 |
if (0) { |
|
2344 |
/* for else below */ |
|
2345 |
} |
|
653 | 2346 |
# ifdef AF_INET |
1009 | 2347 |
else if (myDomain == @symbol(inet)) { |
2348 |
if (objSize < 4) |
|
2349 |
goto bad; |
|
2350 |
# ifdef DGRAM_DEBUG |
|
2351 |
printf("alen: %d s_addr:%x\n", alen, sa.in.sin_addr.s_addr); |
|
2352 |
# endif /* DGRAM_DEBUG */ |
|
2353 |
addrPort = __MKSMALLINT( ntohs(sa.in.sin_port) ); |
|
2354 |
sa.in.sin_addr.s_addr = ntohl(sa.in.sin_addr.s_addr); |
|
2355 |
cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF; |
|
2356 |
cp[1] = (sa.in.sin_addr.s_addr >> 16) & 0xFF; |
|
2357 |
cp[2] = (sa.in.sin_addr.s_addr >> 8) & 0xFF; |
|
2358 |
cp[3] = (sa.in.sin_addr.s_addr >> 0) & 0xFF; |
|
1010 | 2359 |
alen = 4; |
1009 | 2360 |
# ifdef DGRAM_DEBUG |
2361 |
printf("addr:%d.%d.%d.%d\n", cp[0], cp[1], cp[2], cp[3]); |
|
2362 |
# endif /* DGRAM_DEBUG */ |
|
2363 |
} |
|
653 | 2364 |
# endif /* AF_INET */ |
2365 |
||
812 | 2366 |
# ifdef AF_INET6 |
1009 | 2367 |
else if (myDomain == @symbol(inet6)) { |
2368 |
if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) |
|
2369 |
goto bad; |
|
2370 |
bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr)); |
|
2371 |
alen = sizeof(sa.in6.sin6_addr.s6_addr); |
|
2372 |
} |
|
812 | 2373 |
# endif /* AF_INET6 */ |
2374 |
||
2375 |
# ifdef AF_APPLETALK |
|
1009 | 2376 |
else if (myDomain == @symbol(appletalk)) { |
2377 |
if (objSize < 3) |
|
2378 |
goto bad; |
|
2379 |
cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF; |
|
2380 |
cp[1] = (sa.at.sat_addr.s_net) & 0xFF; |
|
2381 |
cp[2] = (sa.at.sat_addr.s_node) & 0xFF; |
|
2382 |
alen = 3; |
|
2383 |
} |
|
812 | 2384 |
# endif /* AF_APPLETALK */ |
2385 |
||
1009 | 2386 |
/* |
2387 |
* XXXX add addressing stuff for other domains here ... |
|
2388 |
*/ |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2389 |
# ifdef AF_X25 |
1009 | 2390 |
else if (myDomain == @symbol(x25)) { |
2391 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2392 |
# endif |
812 | 2393 |
|
2394 |
# ifdef AF_AX25 |
|
1009 | 2395 |
else if (myDomain == @symbol(ax25)) { |
2396 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2397 |
# endif |
812 | 2398 |
|
2399 |
# ifdef AF_NS |
|
1009 | 2400 |
else if ((myDomain == @symbol(ns)) |
2401 |
|| (myDomain == @symbol(xns))) { |
|
2402 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2403 |
# endif |
812 | 2404 |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2405 |
# ifdef AF_SNA |
1009 | 2406 |
else if (myDomain == @symbol(sna)) { |
2407 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2408 |
# endif |
812 | 2409 |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2410 |
# ifdef AF_RAW |
1009 | 2411 |
else if (myDomain == @symbol(raw)) { |
2412 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2413 |
# endif |
812 | 2414 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2415 |
# ifdef AF_ISO |
1009 | 2416 |
else if (myDomain == @symbol(iso)) { |
2417 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2418 |
# endif |
812 | 2419 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2420 |
# ifdef AF_DECnet |
1009 | 2421 |
else if (myDomain == @symbol(decnet)) { |
2422 |
} |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
2423 |
# endif |
812 | 2424 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2425 |
# ifdef AF_NETBIOS |
1009 | 2426 |
else if (myDomain == @symbol(netbios)) { |
2427 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2428 |
# endif |
812 | 2429 |
|
653 | 2430 |
# ifdef AF_IPX |
1009 | 2431 |
else if (myDomain == @symbol(ipx)) { |
2432 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2433 |
# endif |
812 | 2434 |
|
653 | 2435 |
# ifdef AF_BRIDGE |
1009 | 2436 |
else if (myDomain == @symbol(bridge)) { |
2437 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2438 |
# endif |
812 | 2439 |
|
653 | 2440 |
# ifdef AF_BSC |
1009 | 2441 |
else if (myDomain == @symbol(bsc)) { |
2442 |
} |
|
571 | 2443 |
# endif |
812 | 2444 |
|
2445 |
# ifdef AF_ROSE |
|
1009 | 2446 |
else if (myDomain == @symbol(rose)) { |
2447 |
} |
|
812 | 2448 |
# endif |
2449 |
||
869 | 2450 |
# ifdef AF_IRDA |
1009 | 2451 |
else if (myDomain == @symbol(irda)) { |
2452 |
} |
|
869 | 2453 |
# endif |
2454 |
||
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2455 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 2456 |
else if (myDomain == @symbol(ccitt)) { |
2457 |
} |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2458 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2459 |
|
1009 | 2460 |
addrLen = __MKSMALLINT(alen); |
2461 |
} |
|
2462 |
} |
|
2463 |
if (n < 0) { |
|
2464 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2465 |
} |
|
2466 |
nReceived = __MKSMALLINT(n); |
|
126 | 2467 |
} |
418 | 2468 |
#endif |
126 | 2469 |
bad: ; |
2470 |
%}. |
|
2471 |
nReceived notNil ifTrue:[ |
|
1009 | 2472 |
nReceived < 0 ifTrue:[ |
2473 |
'Socket [warning]: ' infoPrint. |
|
2474 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
|
2475 |
]. |
|
2476 |
addrLen notNil ifTrue:[ |
|
2477 |
(anAddressBuffer isKindOf:SocketAddress) ifFalse:[ |
|
2478 |
"/ can be a ByteArray for ST/X compatibility |
|
2479 |
anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes |
|
2480 |
domain == #inet ifTrue:[ |
|
2481 |
addrBytes := anAddressBuffer copyFrom:1 to:4. |
|
2482 |
anAddressBuffer at:5 put:(addrPort digitByteAt:2). |
|
2483 |
anAddressBuffer at:6 put:(addrPort digitByteAt:1). |
|
2484 |
] ifFalse:[ |
|
2485 |
domain == #appletalk ifTrue:[ |
|
2486 |
addrBytes := anAddressBuffer copyFrom:1 to:3. |
|
2487 |
anAddressBuffer at:4 put:(addrPort digitByteAt:2). |
|
2488 |
anAddressBuffer at:5 put:(addrPort digitByteAt:1). |
|
2489 |
] ifFalse:[ |
|
2490 |
self error:'please use a SocketAddress' |
|
2491 |
] |
|
2492 |
] |
|
2493 |
] ifTrue:[ |
|
2494 |
"/ can be a SocketAddress for ST-80 compatibility |
|
2495 |
anAddressBuffer hostAddress:(addrBytes copyTo:addrLen) port:addrPort. |
|
2496 |
]. |
|
2497 |
]. |
|
2498 |
^ nReceived |
|
28 | 2499 |
]. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2500 |
" |
126 | 2501 |
arrive here if you try to receive into an invalid buffer |
2502 |
(i.e. not ByteArray-like), |
|
2503 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2504 |
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
|
2505 |
" |
126 | 2506 |
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
|
2507 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2508 |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2509 |
sendBuffer:aDataBuffer start:startIndex for:count flags:flags |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2510 |
"send data. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2511 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2512 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2513 |
Return the number of bytes transmitted, or a negative number on error. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2514 |
On error, the unix error code is left in the lastErrorNumber |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2515 |
instance variable." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2516 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2517 |
|nReceived portNo| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2518 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2519 |
%{ |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2520 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2521 |
OBJ oClass; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2522 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2523 |
int nInstVars, nInstBytes, objSize; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2524 |
int sock; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2525 |
int n; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2526 |
char *cp; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2527 |
int _flags = 0; |
1009 | 2528 |
int offs, nBytes, sIdx; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2529 |
unsigned long norder; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2530 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2531 |
_flags = __longIntVal(flags); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2532 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2533 |
if ((fp != nil) |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2534 |
&& __isSmallInteger(startIndex) |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2535 |
&& __isSmallInteger(count)) { |
1009 | 2536 |
sock = fileno(__FILEVal(fp)); |
2537 |
||
2538 |
oClass = __Class(aDataBuffer); |
|
2539 |
sIdx = __intVal(startIndex) - 1; |
|
2540 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2541 |
case BYTEARRAY: |
|
2542 |
offs = sIdx; |
|
2543 |
break; |
|
2544 |
case WORDARRAY: |
|
2545 |
case SWORDARRAY: |
|
2546 |
offs = sIdx * 2; |
|
2547 |
break; |
|
2548 |
case LONGARRAY: |
|
2549 |
case SLONGARRAY: |
|
2550 |
offs = sIdx * 4; |
|
2551 |
break; |
|
2552 |
case LONGLONGARRAY: |
|
2553 |
case SLONGLONGARRAY: |
|
2554 |
offs = sIdx * 8; |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2555 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2556 |
offs += 4; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2557 |
# endif |
1010 | 2558 |
break; |
1009 | 2559 |
case FLOATARRAY: |
2560 |
offs = sIdx * sizeof(float); |
|
2561 |
break; |
|
2562 |
case DOUBLEARRAY: |
|
2563 |
offs = sIdx * sizeof(double); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2564 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2565 |
offs += 4; |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2566 |
# endif |
1009 | 2567 |
break; |
2568 |
default: |
|
2569 |
goto bad; |
|
2570 |
} |
|
2571 |
nBytes = __intVal(count); |
|
2572 |
||
2573 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2574 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2575 |
objSize = __qSize(aDataBuffer) - nInstBytes; |
|
2576 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
|
2577 |
cp += offs; |
|
2578 |
if ((offs + nBytes) > objSize) { |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2579 |
# ifdef DGRAM_DEBUG |
1009 | 2580 |
printf("cut off ...\n"); |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2581 |
# endif |
1009 | 2582 |
nBytes = objSize - offs; |
2583 |
} |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2584 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2585 |
# ifdef DGRAM_DEBUG |
1009 | 2586 |
printf("sending %d bytes ...\n", nBytes); |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2587 |
# endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2588 |
|
1009 | 2589 |
__BEGIN_INTERRUPTABLE__ |
2590 |
do { |
|
2591 |
n = send(sock, cp, nBytes, _flags); |
|
2592 |
} while ((n < 0) && (errno == EINTR)); |
|
2593 |
__END_INTERRUPTABLE__ |
|
2594 |
||
2595 |
if (n < 0) { |
|
2596 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2597 |
} |
|
2598 |
RETURN (__MKSMALLINT(n)); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2599 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2600 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2601 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2602 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2603 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2604 |
arrive here if you try to send from an invalid buffer |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2605 |
(i.e. not ByteArray-like), |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2606 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2607 |
or if the addressBuffer is nonNil AND too small. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2608 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2609 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2610 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
2611 |
|
126 | 2612 |
sendTo:anAddressBuffer buffer:buffer |
2613 |
"send datagramm data - fetch address of destination host from |
|
2614 |
anAddressBuffer, data from aDataBuffer. |
|
2615 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2616 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2617 |
Return the number of bytes transmitted, or a negative number on error. |
|
2618 |
On error, the unix error code is left in the lastErrorNumber |
|
2619 |
instance variable. |
|
2620 |
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
|
2621 |
|
126 | 2622 |
^ 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
|
2623 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2624 |
|
817 | 2625 |
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count |
2626 |
"send datagramm data - fetch address of destination host from |
|
2627 |
anAddressBuffer, data from aDataBuffer. |
|
2628 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2629 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2630 |
Return the number of bytes transmitted, or a negative number on error. |
|
2631 |
On error, the unix error code is left in the lastErrorNumber |
|
2632 |
instance variable. |
|
2633 |
Flags is currently ignored; it is there for ST-80 compatibility." |
|
2634 |
||
2635 |
^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 |
|
2636 |
! |
|
2637 |
||
126 | 2638 |
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags |
2639 |
"send datagramm data - fetch address of destination host from |
|
2640 |
anAddressBuffer, data from aDataBuffer starting at startIndex, |
|
2641 |
sending count bytes. |
|
2642 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2643 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2644 |
Return the number of bytes transmitted, or a negative number on error. |
|
2645 |
On error, the unix error code is left in the lastErrorNumber |
|
2646 |
instance variable." |
|
0 | 2647 |
|
126 | 2648 |
|addrBytes addrLen nReceived portNo| |
93 | 2649 |
|
819 | 2650 |
"/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first) |
2651 |
"/ or (better) an instance of SocketAddress |
|
126 | 2652 |
"/ |
888 | 2653 |
(anAddressBuffer isKindOf:SocketAddress) ifFalse:[ |
1009 | 2654 |
domain == #inet ifTrue:[ |
2655 |
addrBytes := anAddressBuffer copyFrom:1 to:4. |
|
2656 |
portNo := ((anAddressBuffer at:5) bitShift:8) |
|
2657 |
+ (anAddressBuffer at:6). |
|
2658 |
] ifFalse:[ |
|
2659 |
domain == #appletalk ifTrue:[ |
|
2660 |
addrBytes := anAddressBuffer copyFrom:1 to:3. |
|
2661 |
portNo := ((anAddressBuffer at:5) bitShift:8) |
|
2662 |
+ (anAddressBuffer at:6). |
|
2663 |
] ifFalse:[ |
|
2664 |
self error:'please use a SocketAddress' |
|
2665 |
] |
|
2666 |
]. |
|
888 | 2667 |
] ifTrue:[ |
1009 | 2668 |
addrBytes := anAddressBuffer hostAddress. |
2669 |
portNo := anAddressBuffer port. |
|
28 | 2670 |
]. |
0 | 2671 |
%{ |
418 | 2672 |
#ifndef NO_SOCKET |
126 | 2673 |
OBJ oClass; |
217 | 2674 |
OBJ fp = __INST(filePointer); |
126 | 2675 |
int nInstVars, nInstBytes, objSize; |
2676 |
int sock; |
|
819 | 2677 |
union sockaddr_u sa; |
126 | 2678 |
struct sockaddr *saPtr = (struct sockaddr *)&sa; |
2679 |
int alen = sizeof(sa); |
|
2680 |
int n; |
|
2681 |
char *cp; |
|
2682 |
int _flags = 0; |
|
2683 |
int offs, nBytes; |
|
2684 |
unsigned long norder; |
|
21 | 2685 |
|
126 | 2686 |
_flags = __longIntVal(flags); |
2687 |
||
2688 |
if ((fp != nil) |
|
2689 |
&& __isSmallInteger(startIndex) |
|
2690 |
&& __isSmallInteger(count)) { |
|
1009 | 2691 |
sock = fileno(__FILEVal(fp)); |
2692 |
||
2693 |
if (addrBytes == nil) { |
|
2694 |
alen = 0; |
|
2695 |
saPtr = (struct sockaddr *)0; |
|
2696 |
} else { |
|
2697 |
if (! __isByteArray(addrBytes)) goto bad; |
|
2698 |
||
2699 |
cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element; |
|
2700 |
n = __byteArraySize(addrBytes); |
|
2701 |
if (alen < n) n = alen; |
|
790 | 2702 |
# ifdef DGRAM_DEBUG |
1009 | 2703 |
printf("address is %d bytes ... %d.%d.%d.%d\n", n, cp[0], cp[1], cp[2], cp[3]); |
790 | 2704 |
# endif |
1009 | 2705 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
2706 |
||
2707 |
if (0) { |
|
2708 |
/* for else below */ |
|
2709 |
} |
|
790 | 2710 |
# ifdef AF_INET |
1009 | 2711 |
else if (__INST(domain) == @symbol(inet)) { |
2712 |
sa.in.sin_family = AF_INET; |
|
2713 |
sa.in.sin_port = htons((u_short) __intVal(portNo)); |
|
2714 |
} |
|
790 | 2715 |
# endif |
2716 |
# ifdef AF_INET6 |
|
1009 | 2717 |
else if (__INST(domain) == @symbol(inet6)) { |
2718 |
sa.in6.sin6_family = AF_INET6; |
|
2719 |
sa.in6.sin6_port = htons((u_short) __intVal(portNo)); |
|
2720 |
} |
|
790 | 2721 |
# endif |
2722 |
# ifdef AF_APPLETALK |
|
1009 | 2723 |
else if (__INST(domain) == @symbol(appletalk)) { |
2724 |
sa.at.sat_family = AF_APPLETALK; |
|
2725 |
sa.at.sat_port = __intVal(portNo); |
|
2726 |
} |
|
790 | 2727 |
# endif |
869 | 2728 |
# ifdef AF_IRDA |
1009 | 2729 |
else if (__INST(domain) == @symbol(irda)) { |
2730 |
} |
|
869 | 2731 |
# endif |
1009 | 2732 |
} |
2733 |
||
2734 |
oClass = __Class(aDataBuffer); |
|
2735 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2736 |
case BYTEARRAY: |
|
2737 |
offs = __intVal(startIndex) - 1; |
|
2738 |
break; |
|
2739 |
case WORDARRAY: |
|
2740 |
case SWORDARRAY: |
|
2741 |
offs = (__intVal(startIndex) - 1) * 2; |
|
2742 |
break; |
|
2743 |
case LONGARRAY: |
|
2744 |
case SLONGARRAY: |
|
2745 |
offs = (__intVal(startIndex) - 1) * 4; |
|
2746 |
break; |
|
2747 |
case LONGLONGARRAY: |
|
2748 |
case SLONGLONGARRAY: |
|
2749 |
offs = (__intVal(startIndex) - 1) * 8; |
|
790 | 2750 |
# ifdef __NEED_LONGLONG_ALIGN |
1009 | 2751 |
offs += 4; |
790 | 2752 |
# endif |
1010 | 2753 |
break; |
1009 | 2754 |
case FLOATARRAY: |
2755 |
offs = (__intVal(startIndex) - 1) * sizeof(float); |
|
2756 |
break; |
|
2757 |
case DOUBLEARRAY: |
|
2758 |
offs = (__intVal(startIndex) - 1) * sizeof(double); |
|
790 | 2759 |
# ifdef __NEED_DOUBLE_ALIGN |
1009 | 2760 |
offs += 4; |
790 | 2761 |
# endif |
1009 | 2762 |
break; |
2763 |
default: |
|
2764 |
goto bad; |
|
2765 |
} |
|
2766 |
nBytes = __intVal(count); |
|
2767 |
||
2768 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
2769 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2770 |
objSize = __qSize(aDataBuffer) - nInstBytes; |
|
2771 |
if ((offs + nBytes) > objSize) { |
|
790 | 2772 |
# ifdef DGRAM_DEBUG |
1009 | 2773 |
printf("cut off ...\n"); |
790 | 2774 |
# endif |
1009 | 2775 |
nBytes = objSize - offs; |
2776 |
} |
|
2777 |
||
2778 |
norder = htonl(sa.in.sin_addr.s_addr); |
|
790 | 2779 |
# ifdef DGRAM_DEBUG |
1009 | 2780 |
printf("sending %d bytes ... to ", nBytes); |
2781 |
printf("%d.%d.%d.%d\n", |
|
2782 |
(norder >> 24) & 0xFF, |
|
2783 |
(norder >> 16) & 0xFF, |
|
2784 |
(norder >> 8) & 0xFF, |
|
2785 |
norder & 0xFF); |
|
790 | 2786 |
# endif |
0 | 2787 |
|
1009 | 2788 |
__BEGIN_INTERRUPTABLE__ |
2789 |
do { |
|
2790 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs; |
|
2791 |
n = sendto(sock, cp, nBytes, _flags, saPtr, alen); |
|
2792 |
} while ((n < 0) && (errno == EINTR)); |
|
2793 |
__END_INTERRUPTABLE__ |
|
2794 |
||
2795 |
if (n < 0) { |
|
2796 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2797 |
} |
|
2798 |
RETURN (__MKSMALLINT(n)); |
|
0 | 2799 |
} |
418 | 2800 |
#endif |
126 | 2801 |
bad: ; |
42 | 2802 |
%}. |
2803 |
" |
|
126 | 2804 |
arrive here if you try to send from an invalid buffer |
2805 |
(i.e. not ByteArray-like), |
|
2806 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2807 |
or if the addressBuffer is nonNil AND too small. |
|
42 | 2808 |
" |
126 | 2809 |
self primitiveFailed |
0 | 2810 |
! ! |
2811 |
||
2812 |
!Socket methodsFor:'low level'! |
|
2813 |
||
507 | 2814 |
bindAnonymously |
2815 |
^ self |
|
2816 |
bindTo:0 |
|
2817 |
address:nil |
|
509 | 2818 |
reuseAddress:false |
2819 |
! |
|
2820 |
||
2821 |
bindAnonymouslyToAddress:addressString |
|
2822 |
^ self |
|
2823 |
bindTo:0 |
|
2824 |
address:addressString |
|
2825 |
reuseAddress:false |
|
507 | 2826 |
! |
2827 |
||
71 | 2828 |
bindTo:aSocketAddress |
425 | 2829 |
"ST80 compatible bind, expecting a socketAddress argument. |
2830 |
The socketAddress object (an instance of SocketAddress) |
|
2831 |
is supposed to respond to #portOrName and #address requests." |
|
71 | 2832 |
|
2833 |
^ self bindTo:(aSocketAddress portOrName) |
|
2834 |
address:(aSocketAddress address) |
|
425 | 2835 |
reuseAddress:true |
71 | 2836 |
! |
2837 |
||
425 | 2838 |
bindTo:portNrOrNameString address:addressString |
28 | 2839 |
"low level bind - returns true if ok, false otherwise. |
71 | 2840 |
Currently only non-address binding is supported; |
425 | 2841 |
i.e. the address must always be nil. |
71 | 2842 |
|
2843 |
The interpretation of portNrOrName depends on the domain: |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2844 |
inet domain uses (4byte) byteArray like internet numbers, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2845 |
unix domain uses pathname strings, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2846 |
others use whatever will come up in the future |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2847 |
" |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2848 |
|
425 | 2849 |
^ self |
2850 |
bindTo:portNrOrNameString |
|
2851 |
address:addressString |
|
2852 |
reuseAddress:true |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2853 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2854 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2855 |
bindTo:portNrOrName address:address reuseAddress:reuse |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2856 |
"low level bind - returns true if ok, false otherwise. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2857 |
Currently only non-address binding is supported; |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2858 |
i.e. address must always be nil. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2859 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2860 |
The interpretation of portNrOrName depends on the domain: |
789 | 2861 |
inet domain uses (4byte) byteArray like internet numbers, |
2862 |
unix domain uses pathname strings, |
|
2863 |
others use whatever will come up in the future |
|
425 | 2864 |
|
2865 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
2866 |
is to be set (to avoid the 'bind: address in use' error). |
|
2867 |
" |
|
28 | 2868 |
|
2869 |
filePointer isNil ifTrue:[ |
|
789 | 2870 |
^ self errorNotOpen |
28 | 2871 |
]. |
1120 | 2872 |
%{ /* STACK: 100000 */ |
418 | 2873 |
#ifndef NO_SOCKET |
217 | 2874 |
OBJ t = __INST(filePointer); |
71 | 2875 |
OBJ myDomain; |
28 | 2876 |
int sock; |
819 | 2877 |
union sockaddr_u sa; |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2878 |
int sockaddr_size; |
6 | 2879 |
int ret; |
25 | 2880 |
int on = 1; |
28 | 2881 |
int ok; |
0 | 2882 |
|
217 | 2883 |
if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) { |
789 | 2884 |
DBGPRINTF(("SOCKET: invalid domain arg\n")); |
2885 |
RETURN (false); |
|
28 | 2886 |
} |
2887 |
||
2888 |
ok = 0; |
|
217 | 2889 |
myDomain = __INST(domain); |
525 | 2890 |
|
1009 | 2891 |
if (0) { |
2892 |
/* for else below */ |
|
2893 |
} |
|
2894 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2895 |
# ifdef AF_INET |
1009 | 2896 |
else if (myDomain == @symbol(inet)) { |
789 | 2897 |
/* |
2898 |
* INET addresses - port must be a smallinteger or nil |
|
2899 |
*/ |
|
2900 |
sa.in.sin_family = AF_INET; |
|
2901 |
||
2902 |
if (portNrOrName == nil) { |
|
2903 |
sa.in.sin_port = 0; |
|
2904 |
} else { |
|
2905 |
if (! __isSmallInteger(portNrOrName)) { |
|
2906 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
2907 |
RETURN (false); |
|
2908 |
} |
|
1009 | 2909 |
sa.in.sin_port = htons((u_short) __intVal(portNrOrName)); |
789 | 2910 |
} |
2911 |
||
2912 |
/* |
|
2913 |
* INET addresses - addr must be nil, integer or byteArray |
|
2914 |
*/ |
|
2915 |
if (address == nil) { |
|
2916 |
sa.in.sin_addr.s_addr = htonl(INADDR_ANY); |
|
2917 |
} else { |
|
2918 |
if (__isInteger(address)) { |
|
2919 |
sa.in.sin_addr.s_addr = htonl(__longIntVal(address)); |
|
2920 |
} else { |
|
2921 |
if (__isByteArray(address)) { |
|
2922 |
unsigned char *cp; |
|
2923 |
int n; |
|
2924 |
||
2925 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
2926 |
n = __byteArraySize(address); |
|
2927 |
if (n > 4) n = 4; |
|
2928 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
|
2929 |
} else { |
|
2930 |
unsigned addr; |
|
2931 |
struct hostent *hp ; |
|
2932 |
||
2933 |
if (! __isString(address)) { |
|
2934 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
2935 |
RETURN (false); |
|
2936 |
} |
|
2937 |
||
2938 |
if ((addr = inet_addr(__stringVal(address))) != -1) { |
|
2939 |
/* |
|
2940 |
* is Internet addr in octet notation |
|
2941 |
*/ |
|
2942 |
bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */ |
|
2943 |
} else { |
|
2944 |
/* |
|
2945 |
* do we know the host's address? |
|
2946 |
*/ |
|
2947 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
2948 |
if (hp == NULL) { |
|
2949 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
|
2950 |
RETURN (false); |
|
2951 |
} |
|
812 | 2952 |
if (hp->h_addrtype != AF_INET) { |
2953 |
DBGPRINTF(("SOCKET: host:%s is not an inet host\n", __stringVal(address))); |
|
2954 |
RETURN (false); |
|
2955 |
} |
|
789 | 2956 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
2957 |
sa.in.sin_family = hp->h_addrtype; |
|
2958 |
} |
|
2959 |
} |
|
2960 |
} |
|
2961 |
} |
|
2962 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
|
2963 |
sockaddr_size = sizeof(struct sockaddr_in); |
|
2964 |
ok = 1; |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2965 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2966 |
# endif /* AF_INET */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2967 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2968 |
# ifdef AF_INET6 |
1009 | 2969 |
else if (myDomain == @symbol(inet6)) { |
789 | 2970 |
/* |
2971 |
* INET6 addresses - port must be a smallinteger or nil |
|
2972 |
*/ |
|
2973 |
sa.in6.sin6_family = AF_INET6; |
|
2974 |
||
2975 |
if (portNrOrName == nil) { |
|
2976 |
sa.in6.sin6_port = 0; |
|
2977 |
} else { |
|
2978 |
if (! __isSmallInteger(portNrOrName)) { |
|
2979 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
2980 |
RETURN (false); |
|
2981 |
} |
|
1009 | 2982 |
sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName)); |
789 | 2983 |
} |
2984 |
||
2985 |
/* |
|
2986 |
* INET6 addresses - addr must be nil or byteArray or string |
|
2987 |
*/ |
|
2988 |
if (address == nil) { |
|
812 | 2989 |
bzero(sa.in6.sin6_addr.s6_addr, sizeof(sa.in6.sin6_addr.s6_addr)); |
789 | 2990 |
} else { |
2991 |
if (__isByteArray(address)) { |
|
2992 |
unsigned char *cp; |
|
2993 |
int n; |
|
2994 |
||
2995 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
2996 |
n = __byteArraySize(address); |
|
812 | 2997 |
if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr); |
2998 |
bcopy(cp, sa.in6.sin6_addr.s6_addr, n); |
|
789 | 2999 |
} else { |
3000 |
unsigned addr; |
|
3001 |
struct hostent *hp ; |
|
3002 |
||
3003 |
if (! __isString(address)) { |
|
3004 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
3005 |
RETURN (false); |
|
3006 |
} |
|
3007 |
||
3008 |
/* |
|
3009 |
* do we know the host's address? |
|
3010 |
*/ |
|
3011 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
3012 |
if (hp == NULL) { |
|
3013 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
|
3014 |
RETURN (false); |
|
3015 |
} |
|
812 | 3016 |
if (hp->h_addrtype != AF_INET6) { |
3017 |
DBGPRINTF(("SOCKET: host:%s is not an ipv6 host\n", __stringVal(address))); |
|
3018 |
RETURN (false); |
|
3019 |
} |
|
789 | 3020 |
bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ; |
3021 |
sa.in.sin_family = hp->h_addrtype; |
|
3022 |
} |
|
3023 |
} |
|
3024 |
||
812 | 3025 |
DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x... port: %x\n", |
789 | 3026 |
sa.in6.sin6_addr.s6_addr[0], |
3027 |
sa.in6.sin6_addr.s6_addr[1], |
|
3028 |
sa.in6.sin6_addr.s6_addr[2], |
|
3029 |
sa.in6.sin6_addr.s6_addr[3], |
|
3030 |
sa.in6.sin6_addr.s6_addr[4], |
|
3031 |
sa.in6.sin6_addr.s6_addr[5], |
|
3032 |
sa.in6.sin6_port)); |
|
3033 |
sockaddr_size = sizeof(struct sockaddr_in6); |
|
3034 |
ok = 1; |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3035 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3036 |
# endif /* AF_INET6 */ |
525 | 3037 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3038 |
# ifdef AF_UNIX |
525 | 3039 |
/* |
3040 |
* UNIX domain - port is ignored; address must be a string (path) |
|
3041 |
*/ |
|
1009 | 3042 |
else if (myDomain == @symbol(unix)) { |
789 | 3043 |
char *pathName; |
3044 |
int l; |
|
3045 |
||
3046 |
if (! __isString(portNrOrName)) { |
|
3047 |
DBGPRINTF(("SOCKET: invalid port (pathname) arg\n")); |
|
3048 |
RETURN (false); |
|
3049 |
} |
|
3050 |
pathName = (char *)__stringVal(portNrOrName); |
|
3051 |
l = strlen(pathName); |
|
3052 |
if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) { |
|
3053 |
DBGPRINTF(("SOCKET: pathname too long\n")); |
|
3054 |
RETURN (false); |
|
3055 |
} |
|
3056 |
||
3057 |
strcpy(sa.un.sun_path, pathName); |
|
3058 |
sa.un.sun_family = AF_UNIX; |
|
3059 |
sockaddr_size = l + sizeof ( sa.un.sun_family ); |
|
3060 |
ok = 1; |
|
28 | 3061 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3062 |
# endif /* AF_UNIX */ |
525 | 3063 |
|
3064 |
# ifdef AF_APPLETALK |
|
3065 |
/* |
|
3066 |
* this has never been tested .... |
|
3067 |
*/ |
|
1009 | 3068 |
else if (myDomain == @symbol(appletalk)) { |
789 | 3069 |
/* |
3070 |
* APPLETALK addresses - port must be a smallinteger or nil |
|
3071 |
*/ |
|
3072 |
sa.at.sat_family = AF_APPLETALK; |
|
3073 |
||
3074 |
if (portNrOrName == nil) { |
|
3075 |
sa.at.sat_port = 0; |
|
3076 |
} else { |
|
3077 |
if (! __isSmallInteger(portNrOrName)) { |
|
3078 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3079 |
RETURN (false); |
|
3080 |
} |
|
3081 |
sa.at.sat_port = __intVal(portNrOrName); |
|
3082 |
} |
|
3083 |
||
3084 |
/* |
|
3085 |
* APPLETALK addresses - addr must be nil, integer or byteArray |
|
819 | 3086 |
* if integer, the first byte are the hi net bits, next byte are low net bits, |
3087 |
* last byte is node. |
|
789 | 3088 |
*/ |
3089 |
if (address == nil) { |
|
3090 |
sa.at.sat_addr.s_net = ATADDR_ANYNET; |
|
3091 |
sa.at.sat_addr.s_node = ATADDR_ANYNODE; |
|
3092 |
} else { |
|
3093 |
if (__isInteger(address)) { |
|
3094 |
unsigned a = __longIntVal(address); |
|
3095 |
sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF); |
|
3096 |
sa.at.sat_addr.s_node = htons(a & 0xFF); |
|
3097 |
} else { |
|
3098 |
if (__isByteArray(address)) { |
|
3099 |
unsigned char *cp; |
|
3100 |
int n; |
|
3101 |
||
3102 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
3103 |
n = __byteArraySize(address); |
|
3104 |
if (n > 3) n = 3; |
|
3105 |
bcopy(cp, &sa.at.sat_addr, n); |
|
3106 |
} else { |
|
3107 |
unsigned addr; |
|
3108 |
struct hostent *hp ; |
|
3109 |
||
3110 |
if (! __isString(address)) { |
|
3111 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
3112 |
RETURN (false); |
|
3113 |
} |
|
3114 |
||
3115 |
/* |
|
3116 |
* do we know the host's address? |
|
3117 |
*/ |
|
3118 |
GETHOSTBYNAME(hp, __stringVal(address)) |
|
3119 |
if (hp == NULL) { |
|
3120 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address))); |
|
3121 |
RETURN (false); |
|
3122 |
} |
|
3123 |
if (hp->h_addrtype != AF_APPLETALK) { |
|
3124 |
DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(address))); |
|
3125 |
RETURN (false); |
|
3126 |
} |
|
3127 |
bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ; |
|
3128 |
sa.at.sat_family = hp->h_addrtype; |
|
3129 |
} |
|
3130 |
} |
|
3131 |
} |
|
3132 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
|
3133 |
sockaddr_size = sizeof(struct sockaddr_at); |
|
3134 |
ok = 1; |
|
525 | 3135 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3136 |
# endif /* AF_APPLETALK */ |
525 | 3137 |
|
28 | 3138 |
/* |
3139 |
* XXXX add addressing stuff for other domains here ... |
|
3140 |
*/ |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3141 |
# ifdef AF_X25 |
1009 | 3142 |
else if (myDomain == @symbol(x25)) { |
28 | 3143 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3144 |
# endif |
819 | 3145 |
# ifdef AF_AX25 |
1009 | 3146 |
else if (myDomain == @symbol(ax25)) { |
819 | 3147 |
} |
3148 |
# endif |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3149 |
# ifdef AF_NS |
1009 | 3150 |
else if ((myDomain == @symbol(ns)) |
812 | 3151 |
|| (myDomain == @symbol(xns))) { |
28 | 3152 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3153 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3154 |
# ifdef AF_DECnet |
1009 | 3155 |
else if (myDomain == @symbol(decnet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3156 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3157 |
# endif |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3158 |
# ifdef AF_SNA |
1009 | 3159 |
else if (myDomain == @symbol(sna)) { |
93 | 3160 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3161 |
# endif |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3162 |
# ifdef AF_RAW |
1009 | 3163 |
else if (myDomain == @symbol(raw)) { |
93 | 3164 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3165 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3166 |
# ifdef AF_ISO |
1009 | 3167 |
else if (myDomain == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3168 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3169 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3170 |
# ifdef AF_NETBIOS |
1009 | 3171 |
else if (myDomain == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3172 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3173 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3174 |
# ifdef AF_IPX |
1009 | 3175 |
else if (myDomain == @symbol(ipx)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3176 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3177 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3178 |
# ifdef AF_BRIDGE |
1009 | 3179 |
else if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3180 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3181 |
# endif |
571 | 3182 |
# ifdef AF_BSC |
1009 | 3183 |
else if (myDomain == @symbol(bsc)) { |
571 | 3184 |
} |
3185 |
# endif |
|
812 | 3186 |
# ifdef AF_ROSE |
1009 | 3187 |
else if (myDomain == @symbol(rose)) { |
812 | 3188 |
} |
3189 |
# endif |
|
869 | 3190 |
# ifdef AF_IRDA |
1009 | 3191 |
else if (myDomain == @symbol(irda)) { |
869 | 3192 |
} |
3193 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3194 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3195 |
else if (myDomain == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3196 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3197 |
# endif |
0 | 3198 |
|
28 | 3199 |
if (! ok) { |
789 | 3200 |
DBGPRINTF(("SOCKET: unsupported domain\n")); |
3201 |
RETURN (false); |
|
28 | 3202 |
} |
3203 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
3204 |
sock = fileno(__FILEVal(t)); |
28 | 3205 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3206 |
# ifdef SO_REUSEADDR |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3207 |
if (reuse == true) { |
789 | 3208 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
3209 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
3210 |
} |
|
28 | 3211 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3212 |
# endif /* SO_REUSEADDR */ |
28 | 3213 |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3214 |
__BEGIN_INTERRUPTABLE__ |
28 | 3215 |
do { |
789 | 3216 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
28 | 3217 |
} while ((ret < 0) && (errno == EINTR)); |
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3218 |
__END_INTERRUPTABLE__ |
28 | 3219 |
|
3220 |
if (ret < 0) { |
|
789 | 3221 |
DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno)); |
3222 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3223 |
RETURN (false); |
|
0 | 3224 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3225 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3226 |
__INST(port) = portNrOrName; __STORE(self, portNrOrName); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3227 |
|
1009 | 3228 |
if (0) { |
3229 |
/* for else below */ |
|
3230 |
} |
|
3231 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3232 |
# ifdef AF_INET |
1009 | 3233 |
else if (myDomain == @symbol(inet)) { |
789 | 3234 |
if (! __isSmallInteger(portNrOrName) |
3235 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3236 |
int p; |
|
3237 |
||
3238 |
/* |
|
3239 |
* INET anonymous port - get the actual portNr |
|
3240 |
*/ |
|
3241 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3242 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3243 |
} else { |
|
3244 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3245 |
p = ntohs(sa.in.sin_port); |
|
3246 |
__INST(port) = __MKSMALLINT(p); |
|
3247 |
} |
|
3248 |
} |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3249 |
} |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3250 |
# endif |
819 | 3251 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3252 |
# ifdef AF_INET6 |
1009 | 3253 |
else if (myDomain == @symbol(inet6)) { |
789 | 3254 |
if (! __isSmallInteger(portNrOrName) |
3255 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3256 |
int p; |
|
3257 |
||
3258 |
/* |
|
3259 |
* INET6 anonymous port - get the actual portNr |
|
3260 |
*/ |
|
3261 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3262 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3263 |
} else { |
|
3264 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3265 |
p = ntohs(sa.in6.sin6_port); |
|
3266 |
__INST(port) = __MKSMALLINT(p); |
|
3267 |
} |
|
3268 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3269 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3270 |
# endif |
819 | 3271 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3272 |
# ifdef AF_APPLETALK |
1009 | 3273 |
else if (myDomain == @symbol(appletalk)) { |
789 | 3274 |
if (! __isSmallInteger(portNrOrName) |
3275 |
|| (portNrOrName == __MKSMALLINT(0))) { |
|
3276 |
int p; |
|
3277 |
||
3278 |
/* |
|
3279 |
* APPLETALK anonymous port - get the actual portNr |
|
3280 |
*/ |
|
3281 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
|
3282 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
|
3283 |
} else { |
|
3284 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
|
3285 |
p = sa.at.sat_port; |
|
3286 |
__INST(port) = __MKSMALLINT(p); |
|
3287 |
} |
|
3288 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3289 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3290 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3291 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3292 |
#else /* NO_SOCKET */ |
418 | 3293 |
RETURN (false); |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3294 |
#endif /* NO_SOCKET */ |
42 | 3295 |
%}. |
28 | 3296 |
^ true |
0 | 3297 |
|
28 | 3298 |
" |
3299 |
(Socket domain:#inet type:#stream) |
|
789 | 3300 |
bindTo:9999 |
3301 |
address:nil |
|
28 | 3302 |
" |
0 | 3303 |
! |
3304 |
||
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3305 |
closeFile |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3306 |
"low level close" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3307 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3308 |
%{ /* NOCONTEXT */ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3309 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3310 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3311 |
OBJ t; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3312 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3313 |
t = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3314 |
if (t != nil) { |
812 | 3315 |
FILE *fp; |
3316 |
||
3317 |
fp = __FILEVal(t); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3318 |
DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fileno(fp))); |
812 | 3319 |
fflush(fp); |
3320 |
/* shutdown(fileno(fp), 2); */ |
|
1035 | 3321 |
if (@global(FileOpenTrace) == true) { |
876 | 3322 |
fprintf(stderr, "fclose [Socket] %x\n", fp); |
3323 |
} |
|
812 | 3324 |
fclose(fp); |
3325 |
__INST(filePointer) = nil; |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3326 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3327 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3328 |
%} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3329 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3330 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3331 |
getSocketError |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3332 |
"get the SO_ERROR form the socket, which indicates the |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3333 |
result of an asynchronous operation" |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3334 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3335 |
%{ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3336 |
OBJ t; |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3337 |
int err; |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3338 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3339 |
t = __INST(filePointer); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3340 |
if (t == nil) |
1009 | 3341 |
err = EBADF; |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3342 |
else { |
1009 | 3343 |
int sz, fd; |
3344 |
||
3345 |
fd = fileno(__FILEVal(t)); |
|
3346 |
sz = sizeof(err); |
|
3347 |
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) |
|
3348 |
err = errno; |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3349 |
} |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3350 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3351 |
RETURN(__MKSMALLINT(err)); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3352 |
%} |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3353 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3354 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3355 |
! |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3356 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3357 |
listenFor:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3358 |
"same as listenWithBacklog: - for ST-80 compatibility" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3359 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3360 |
^ self listenWithBacklog:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3361 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3362 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3363 |
listenWithBacklog:aNumber |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3364 |
"start listening; return true if ok, false on error" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3365 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3366 |
filePointer isNil ifTrue:[ |
789 | 3367 |
^ self errorNotOpen |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3368 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3369 |
%{ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3370 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3371 |
OBJ fp = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3372 |
int sock; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3373 |
int ret; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3374 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3375 |
if (! __isSmallInteger(aNumber)) { |
789 | 3376 |
DBGPRINTF(("SOCKET: invalid arg\n")); |
3377 |
RETURN (false); |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3378 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3379 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3380 |
sock = fileno(__FILEVal(fp)); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3381 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3382 |
__BEGIN_INTERRUPTABLE__ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3383 |
do { |
1009 | 3384 |
ret = listen(sock, __intVal(aNumber)); |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3385 |
} while ((ret < 0) && (errno == EINTR)); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3386 |
__END_INTERRUPTABLE__ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3387 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3388 |
if (ret < 0) { |
789 | 3389 |
DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno)); |
3390 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3391 |
RETURN (false); |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3392 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3393 |
#else |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3394 |
RETURN (false); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3395 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3396 |
%}. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3397 |
^ true |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3398 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3399 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3400 |
shutDown |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3401 |
"shutDown and close without flushing " |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3402 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3403 |
filePointer isNil ifTrue:[^ self]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3404 |
Lobby unregister:self. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3405 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3406 |
%{ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3407 |
#ifndef NO_SOCKET |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3408 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3409 |
OBJ fp; |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3410 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3411 |
fp = __INST(filePointer); |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3412 |
if (fp != nil) { |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3413 |
FILE *f; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3414 |
int fd; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3415 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3416 |
__INST(filePointer) = nil; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3417 |
f = __FILEVal(fp); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3418 |
fd = fileno(f); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3419 |
__BEGIN_INTERRUPTABLE__ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3420 |
shutdown(fd, 2); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3421 |
DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fd)); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3422 |
if (@global(FileOpenTrace) == true) { |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3423 |
fprintf(stderr, "fclose [Socket] %x\n", f); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3424 |
} |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3425 |
fclose(f); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3426 |
/* close(fd); */ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3427 |
__END_INTERRUPTABLE__ |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3428 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3429 |
#endif |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3430 |
%} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3431 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3432 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3433 |
!Socket methodsFor:'low level-accepting'! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3434 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3435 |
accept |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3436 |
"create a new TCP socket from accepting on the receiver. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3437 |
This method will suspend the current process if no connection is waiting. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3438 |
For ST-80 compatibility" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3439 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3440 |
|newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3441 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3442 |
newSock := self class new. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3443 |
(newSock acceptOn:self) ifFalse:[^ nil]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3444 |
^ newSock |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3445 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3446 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3447 |
|sock newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3448 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3449 |
sock := Socket provide:8004. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3450 |
sock listenFor:5. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3451 |
newSock := sock accept. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3452 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3453 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3454 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3455 |
acceptOn:aSocket |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3456 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3457 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3458 |
This method will suspend the current process if no connection is waiting. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3459 |
Return the true if ok; false if not." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3460 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3461 |
aSocket readWait. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3462 |
^ self primAcceptOn:aSocket |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3463 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3464 |
"Modified: / 11.3.1996 / 14:21:31 / stefan" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3465 |
"Modified: / 1.8.1998 / 23:39:10 / cg" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3466 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3467 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3468 |
primAcceptOn:aSocket |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3469 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3470 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3471 |
Return the true if ok; false if not." |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3472 |
|
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
|
3473 |
|serverSocketFd addrBytes| |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3474 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3475 |
filePointer notNil ifTrue:[ |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3476 |
^ self errorAlreadyOpen |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3477 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3478 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3479 |
domain := aSocket domain. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3480 |
socketType := aSocket type. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3481 |
serverSocketFd := aSocket fileDescriptor. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3482 |
serverSocketFd isNil ifTrue:[ |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3483 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3484 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3485 |
(serverSocketFd isMemberOf:SmallInteger) ifFalse:[ |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3486 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3487 |
]. |
1120 | 3488 |
%{ /* STACK: 100000 */ |
418 | 3489 |
#ifndef NO_SOCKET |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3490 |
FILE *fp; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3491 |
int flags; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3492 |
int sock, newSock; |
819 | 3493 |
union sockaddr_u sa; |
464 | 3494 |
int alen, alen0; |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3495 |
struct hostent *he ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3496 |
char dotted[20] ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3497 |
|
1009 | 3498 |
if (0) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3499 |
/* for else below */ |
1009 | 3500 |
} |
876 | 3501 |
# ifdef AF_INET |
1009 | 3502 |
else if (__INST(domain) == @symbol(inet)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3503 |
alen0 = sizeof(sa.in); |
464 | 3504 |
} |
876 | 3505 |
# endif |
3506 |
# ifdef AF_INET6 |
|
1009 | 3507 |
else if (__INST(domain) == @symbol(inet6)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3508 |
alen0 = sizeof(sa.in6); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3509 |
} |
876 | 3510 |
# endif |
3511 |
# ifdef AF_UNIX |
|
1009 | 3512 |
else if (__INST(domain) == @symbol(unix)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3513 |
alen0 = sizeof(sa.un); |
464 | 3514 |
} |
876 | 3515 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3516 |
# ifdef AF_APPLETALK |
1009 | 3517 |
else if (__INST(domain) == @symbol(appletalk)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3518 |
alen0 = sizeof(sa.at); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3519 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3520 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3521 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3522 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3523 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3524 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3525 |
# ifdef AF_X25 |
1009 | 3526 |
else if (__INST(domain) == @symbol(x25)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3527 |
alen0 = sizeof(sa.x25); |
819 | 3528 |
} |
3529 |
# endif |
|
3530 |
# ifdef AF_AX25 |
|
1009 | 3531 |
else if (__INST(domain) == @symbol(ax25)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3532 |
alen0 = sizeof(sa.ax25); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3533 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3534 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3535 |
# ifdef AF_NS |
1009 | 3536 |
else if ((__INST(domain) == @symbol(ns)) |
812 | 3537 |
|| (__INST(domain) == @symbol(xns))) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3538 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3539 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3540 |
# ifdef AF_DECnet |
1009 | 3541 |
else if (__INST(domain) == @symbol(decnet)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3542 |
alen0 = sizeof(sa.dn); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3543 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3544 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3545 |
# ifdef AF_SNA |
1009 | 3546 |
else if (__INST(domain) == @symbol(sna)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3547 |
alen0 = sizeof(sa.sna); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3548 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3549 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3550 |
# ifdef AF_RAW |
1009 | 3551 |
else if (__INST(domain) == @symbol(raw)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3552 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3553 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3554 |
# ifdef AF_ISO |
1009 | 3555 |
else if (__INST(domain) == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3556 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3557 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3558 |
# ifdef AF_NETBIOS |
1009 | 3559 |
else if (__INST(domain) == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3560 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3561 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3562 |
# ifdef AF_IPX |
1009 | 3563 |
else if (__INST(domain) == @symbol(ipx)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3564 |
alen0 = sizeof(sa.ipx); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3565 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3566 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3567 |
# ifdef AF_BRIDGE |
1009 | 3568 |
else if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3569 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3570 |
# endif |
571 | 3571 |
# ifdef AF_BSC |
1009 | 3572 |
else if (__INST(domain) == @symbol(bsc)) { |
571 | 3573 |
} |
3574 |
# endif |
|
812 | 3575 |
# ifdef AF_ROSE |
1009 | 3576 |
else if (__INST(domain) == @symbol(rose)) { |
812 | 3577 |
} |
3578 |
# endif |
|
869 | 3579 |
# ifdef AF_IRDA |
1009 | 3580 |
else if (__INST(domain) == @symbol(irda)) { |
869 | 3581 |
} |
3582 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3583 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3584 |
else if (__INST(domain) == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3585 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3586 |
# endif |
464 | 3587 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3588 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3589 |
sock = __intVal(serverSocketFd); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3590 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3591 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3592 |
flags = ioctl(sock, F_GETFL, 0); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3593 |
ioctl(sock, F_SETFL, flags | O_NDELAY); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3594 |
# endif |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3595 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3596 |
__BEGIN_INTERRUPTABLE__ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3597 |
do { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3598 |
alen = alen0; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3599 |
newSock = accept(sock, (struct sockaddr *) &sa, &alen); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3600 |
} while ((newSock < 0) && (errno == EINTR)); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3601 |
__END_INTERRUPTABLE__ |
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
3602 |
DBGFPRINTF((stderr, "socket accept newSock=%d\n", newSock)); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3603 |
|
876 | 3604 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3605 |
ioctl(sock, F_SETFL, flags); |
876 | 3606 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3607 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3608 |
if (newSock < 0) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3609 |
DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno)); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3610 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3611 |
RETURN (false); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3612 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3613 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3614 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3615 |
* extract the partners address |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3616 |
*/ |
1009 | 3617 |
if (0) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3618 |
/* for else below */ |
1009 | 3619 |
} |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3620 |
|
876 | 3621 |
# ifdef AF_INET |
1009 | 3622 |
else if (__INST(domain) == @symbol(inet)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3623 |
# ifdef RESOLVE_NAME_NOW |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3624 |
GETHOSTBYADDR(he, (char *) &sa.in.sin_addr, sizeof(sa.in.sin_addr), AF_INET); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3625 |
if (! he) { |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3626 |
unsigned long norder; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3627 |
|
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3628 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3629 |
sprintf(dotted, "%d.%d.%d.%d", |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3630 |
(norder >> 24) & 0xFF, |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3631 |
(norder >> 16) & 0xFF, |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3632 |
(norder >> 8) & 0xFF, |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3633 |
norder & 0xFF); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3634 |
} |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3635 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3636 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3637 |
__STORESELF(peerName); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3638 |
# else |
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
|
3639 |
addrBytes = __MKBYTEARRAY(&sa.in, sizeof(sa.in)); |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3640 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3641 |
} |
876 | 3642 |
# endif |
3643 |
||
3644 |
# ifdef AF_INET6 |
|
1009 | 3645 |
else if (__INST(domain) == @symbol(inet6)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3646 |
# ifdef RESOLVE_NAME_NOW |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3647 |
GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr, sizeof(sa.in6.sin6_addr), AF_INET6); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3648 |
if (! he) { |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3649 |
unsigned long norder; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3650 |
|
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3651 |
/* |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3652 |
* XXX: what is inet6's naming convention ? |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3653 |
*/ |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3654 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3655 |
sprintf(dotted, "%d.%d.%d.%d.%d.%d...", |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3656 |
sa.in6.sin6_addr.s6_addr[0], |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3657 |
sa.in6.sin6_addr.s6_addr[1], |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3658 |
sa.in6.sin6_addr.s6_addr[2], |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3659 |
sa.in6.sin6_addr.s6_addr[3], |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3660 |
sa.in6.sin6_addr.s6_addr[4], |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3661 |
sa.in6.sin6_addr.s6_addr[5]); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3662 |
} |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3663 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3664 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3665 |
__STORESELF(peerName); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3666 |
# else |
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
|
3667 |
addrBytes = __MKBYTEARRAY(&sa.in6, sizeof(sa.in6)); |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3668 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3669 |
} |
876 | 3670 |
# endif |
3671 |
||
3672 |
# ifdef AF_UNIX |
|
1009 | 3673 |
else if (__INST(domain) == @symbol(unix)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3674 |
DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3675 |
/* nothing to be done here */ |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3676 |
} |
876 | 3677 |
# endif |
3678 |
||
3679 |
# ifdef AF_APPLETALK |
|
1009 | 3680 |
else if (__INST(domain) == @symbol(appletalk)) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3681 |
# ifdef RESOLVE_NAME_NOW |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3682 |
GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, sizeof(sa.at.sat_addr), AF_APPLETALK); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3683 |
if (! he) { |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3684 |
unsigned net; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3685 |
|
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3686 |
/* |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3687 |
* XXX: what is apples naming convention ? |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3688 |
*/ |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3689 |
net = htons(sa.at.sat_addr.s_net) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3690 |
sprintf(dotted, "%d.%d", |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3691 |
net, |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3692 |
sa.at.sat_addr.s_node); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3693 |
} |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3694 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3695 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3696 |
__STORESELF(peerName); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3697 |
# else |
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
|
3698 |
addrBytes = __MKBYTEARRAY(&sa.at, sizeof(sa.at)); |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3699 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3700 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3701 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3702 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3703 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3704 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3705 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3706 |
# ifdef AF_X25 |
1009 | 3707 |
else if (__INST(domain) == @symbol(x25)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3708 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3709 |
# endif |
819 | 3710 |
# ifdef AF_AX25 |
1009 | 3711 |
else if (__INST(domain) == @symbol(ax25)) { |
819 | 3712 |
} |
3713 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3714 |
# ifdef AF_NS |
1009 | 3715 |
else if ((__INST(domain) == @symbol(ns)) |
812 | 3716 |
|| (__INST(domain) == @symbol(xns))) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3717 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3718 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3719 |
# ifdef AF_DECnet |
1009 | 3720 |
else if (__INST(domain) == @symbol(decnet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3721 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3722 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3723 |
# ifdef AF_SNA |
1009 | 3724 |
else if (__INST(domain) == @symbol(sna)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3725 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3726 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3727 |
# ifdef AF_RAW |
1009 | 3728 |
else if (__INST(domain) == @symbol(raw)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3729 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3730 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3731 |
# ifdef AF_ISO |
1009 | 3732 |
else if (__INST(domain) == @symbol(iso)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3733 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3734 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3735 |
# ifdef AF_NETBIOS |
1009 | 3736 |
else if (__INST(domain) == @symbol(netbios)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3737 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3738 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3739 |
# ifdef AF_IPX |
1009 | 3740 |
else if (__INST(domain) == @symbol(ipx)) { |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3741 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3742 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3743 |
# ifdef AF_BRIDGE |
1009 | 3744 |
else if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3745 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3746 |
# endif |
571 | 3747 |
# ifdef AF_BSC |
1009 | 3748 |
else if (__INST(domain) == @symbol(bsc)) { |
571 | 3749 |
} |
3750 |
# endif |
|
812 | 3751 |
# ifdef AF_ROSE |
1009 | 3752 |
else if (__INST(domain) == @symbol(rose)) { |
812 | 3753 |
} |
3754 |
# endif |
|
869 | 3755 |
# ifdef AF_IRDA |
1009 | 3756 |
else if (__INST(domain) == @symbol(irda)) { |
869 | 3757 |
} |
3758 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3759 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
1009 | 3760 |
else if (__INST(domain) == @symbol(ccitt)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3761 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3762 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3763 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3764 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3765 |
* make it a FILE * |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3766 |
*/ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3767 |
fp = fdopen(newSock, "r+"); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3768 |
if (! fp) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3769 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3770 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3771 |
close(newSock); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3772 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", newSock)); |
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3773 |
RETURN (false); |
876 | 3774 |
} |
1035 | 3775 |
if (@global(FileOpenTrace) == true) { |
1185
7b269562f7b4
prepare for lazy peerName resolving
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
3776 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3777 |
} |
876 | 3778 |
|
3779 |
# ifdef BUGGY_STDIO_LIB |
|
3780 |
setbuf(fp, NULL); |
|
3781 |
__INST(buffered) = false; |
|
3782 |
# endif |
|
3783 |
||
3784 |
__INST(filePointer) = __MKOBJ(fp); |
|
3785 |
__STORESELF(filePointer); |
|
3786 |
#endif /* not NO_SOCKET */ |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3787 |
%}. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3788 |
mode := #readwrite. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3789 |
Lobby register:self. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3790 |
binary := false. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3791 |
port := aSocket port. |
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
|
3792 |
|
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3793 |
addrBytes notNil ifTrue:[ |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3794 |
addrBytes changeClassTo:(self class socketAddressClassForDomain:domain). |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3795 |
peer := addrBytes. |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3796 |
]. |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3797 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3798 |
^ true |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3799 |
! |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3800 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3801 |
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3802 |
"suspend the current process, until either a new connection comes |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3803 |
in at the receiver, or data arrives on any of the otherConnections. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3804 |
For a new connection, an accept is performed and the new socket is returned. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3805 |
For an old connection, that socket is returned. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3806 |
In any case, the caller gets a socket to operate on as return value, |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3807 |
or nil, if a timeout occured. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3808 |
This method implements the inner wait-primitive of a multi-connection |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3809 |
server application." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3810 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3811 |
"/ first, a quick check if data is already available |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3812 |
|
1035 | 3813 |
|wasBlocked sema| |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3814 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3815 |
self canReadWithoutBlocking ifTrue:[ |
1170 | 3816 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3817 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3818 |
otherConnections do:[:aConnection | |
1170 | 3819 |
aConnection canReadWithoutBlocking ifTrue:[ |
3820 |
^ aConnection |
|
3821 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3822 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3823 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3824 |
[ |
1170 | 3825 |
"/ check again - prevent incoming interrupts from disturbing our setup |
3826 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3827 |
||
3828 |
self canReadWithoutBlocking ifTrue:[ |
|
3829 |
^ self accept. |
|
3830 |
]. |
|
3831 |
otherConnections do:[:aConnection | |
|
3832 |
aConnection canReadWithoutBlocking ifTrue:[ |
|
3833 |
^ aConnection |
|
3834 |
] |
|
3835 |
]. |
|
3836 |
||
3837 |
"/ nope - must wait. |
|
3838 |
||
3839 |
sema := Semaphore new name:'multiReadWait'. |
|
3840 |
otherConnections do:[:aConnection | |
|
3841 |
Processor signal:sema onInput:(aConnection fileDescriptor). |
|
3842 |
]. |
|
3843 |
Processor signal:sema onInput:(self fileDescriptor). |
|
3844 |
timeoutSeconds notNil ifTrue:[ |
|
3845 |
Processor signal:sema afterSeconds:timeoutSeconds |
|
3846 |
]. |
|
3847 |
Processor activeProcess state:#ioWait. |
|
3848 |
sema wait. |
|
1136 | 3849 |
] ensure:[ |
1170 | 3850 |
sema notNil ifTrue:[Processor disableSemaphore:sema]. |
3851 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3852 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3853 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3854 |
"/ see who it was ... |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3855 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3856 |
self canReadWithoutBlocking ifTrue:[ |
1170 | 3857 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3858 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3859 |
otherConnections do:[:aConnection | |
1170 | 3860 |
aConnection canReadWithoutBlocking ifTrue:[ |
3861 |
^ aConnection |
|
3862 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3863 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3864 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3865 |
"/ none - a timeout |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3866 |
^ nil |
867 | 3867 |
! |
3868 |
||
3869 |
waitForNewConnectionWithTimeout:timeoutSeconds |
|
3870 |
"suspend the current process, until a new connection comes |
|
3871 |
in at the receiver or a timeout occurs. |
|
3872 |
For a new connection, an accept is performed and the new socket is returned. |
|
3873 |
Returns nil, if a timeout occured. |
|
3874 |
This method implements the inner wait-primitive of a single-connection |
|
3875 |
server application." |
|
3876 |
||
3877 |
(self readWaitWithTimeout:timeoutSeconds) ifTrue:[ |
|
3878 |
"/ a timeout occurred - no connection within timeout |
|
3879 |
^ nil |
|
3880 |
]. |
|
3881 |
^ self accept. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3882 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3883 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3884 |
!Socket methodsFor:'low level-connecting'! |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
3885 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3886 |
connectTo:hostOrPathName port:portNrOrName |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3887 |
"low level connect; connect to port, portNrOrNameOrNil on host, hostName. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3888 |
For backward compatibility, host may be also a string or a byteArray, |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3889 |
but it is recommended to pass socketAddress instances. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3890 |
|
71 | 3891 |
Return true if ok, false otherwise. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3892 |
The current process will block (but not the whole Smalltalk) until the connection is established. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3893 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
28 | 3894 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3895 |
^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil |
649 | 3896 |
! |
3897 |
||
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3898 |
connectTo:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil withTimeout:timeout |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3899 |
"low level connect; connect to port, portNrOrNameOrNil on host, hostName. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3900 |
For backward compatibility, host may be also a string or a byteArray, |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3901 |
but it is recommended to pass socketAddress instances. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3902 |
|
649 | 3903 |
Return true if ok, false otherwise. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3904 |
The current process will block (but not the whole Smalltalk) until the connection is established, |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3905 |
or timeout millliseconds have passed." |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3906 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3907 |
|isAsync err domainClass addr addrName| |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3908 |
|
28 | 3909 |
filePointer isNil ifTrue:[ |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3910 |
^ self errorNotOpen |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3911 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3912 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3913 |
domainClass := self class socketAddressClassForDomain:domain. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3914 |
domainClass isNil ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3915 |
^ self error:'invalid (unsupported) domain'. |
28 | 3916 |
]. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3917 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3918 |
"/ backward compatibility: support for byteArray and string arg |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3919 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3920 |
hostOrPathNameOrSocketAddr isString ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3921 |
addr := domainClass hostName:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3922 |
addrName := hostOrPathNameOrSocketAddr. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3923 |
] ifFalse:[ |
1235
9b35e58bf392
Fix broken connect (broken in recent change).
Stefan Vogel <sv@exept.de>
parents:
1230
diff
changeset
|
3924 |
hostOrPathNameOrSocketAddr isByteArray ifFalse:[ |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3925 |
^ self error:'bad host (socketAddress) argument' |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3926 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3927 |
(hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3928 |
addr := hostOrPathNameOrSocketAddr. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3929 |
portNrOrNameOrNil notNil ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3930 |
addr port:portNrOrNameOrNil. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3931 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3932 |
] ifFalse:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3933 |
addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3934 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3935 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3936 |
|
1120 | 3937 |
%{ /* STACK: 100000 */ |
649 | 3938 |
|
418 | 3939 |
#ifndef NO_SOCKET |
217 | 3940 |
OBJ t = __INST(filePointer); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3941 |
struct sockaddr *sockaddr_ptr; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3942 |
int a, sock; |
28 | 3943 |
FILE *fp; |
649 | 3944 |
int ret, oldFlags; |
28 | 3945 |
int on = 1; |
115 | 3946 |
int sockaddr_size; |
28 | 3947 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3948 |
if (!__isNonNilObject(addr) || !__isBytes(addr)) { |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3949 |
DBGPRINTF(("SOCKET: invalid addrBytes\n")); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3950 |
RETURN (false); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3951 |
} |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3952 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3953 |
{ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3954 |
int indx, nIndex; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3955 |
OBJ cls; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3956 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3957 |
indx = 0; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3958 |
if ((cls = __qClass(addr)) != @global(ByteArray)) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3959 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3960 |
nIndex = __qSize(addr) - OHDR_SIZE; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3961 |
sockaddr_size = nIndex - indx; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3962 |
sockaddr_ptr = (struct sockaddr *)(__byteArrayVal(addr) + indx); |
28 | 3963 |
} |
3964 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
3965 |
sock = fileno(__FILEVal(t)); |
28 | 3966 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3967 |
# if defined(O_NONBLOCK) |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3968 |
/* |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3969 |
* set to non-blocking and wait later |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3970 |
*/ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3971 |
oldFlags = fcntl(sock, F_GETFL, 0); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3972 |
/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3973 |
fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3974 |
# endif |
649 | 3975 |
|
28 | 3976 |
/* |
3977 |
* connect |
|
3978 |
*/ |
|
81 | 3979 |
__BEGIN_INTERRUPTABLE__ |
28 | 3980 |
do { |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3981 |
ret = connect(sock, sockaddr_ptr, sockaddr_size); |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3982 |
} while ((ret < 0) |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3983 |
&& ((errno == EINTR) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3984 |
# ifdef EAGAIN |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3985 |
|| (errno == EAGAIN) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3986 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3987 |
)); |
81 | 3988 |
__END_INTERRUPTABLE__ |
28 | 3989 |
|
3990 |
if (ret < 0) { |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3991 |
# if defined(EINPROGRESS) || defined(EALREADY) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3992 |
if (0 |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3993 |
# ifdef EINPROGRESS |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3994 |
|| (errno == EINPROGRESS) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3995 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3996 |
# ifdef EALREADY |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3997 |
|| (errno == EALREADY) |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3998 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3999 |
) { |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4000 |
/* |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4001 |
* This was a nonblocking operation that will take some time. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4002 |
* Do a select on read to get informed when the operation is ready. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4003 |
*/ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4004 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4005 |
isAsync = true; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4006 |
} else |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4007 |
# endif /* EINPROGRESS or EALREADY */ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4008 |
{ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4009 |
DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno)); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4010 |
# ifdef DUMP_ADDRESS |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4011 |
{ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4012 |
char *cp = (char *)(&sa); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4013 |
int i; |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4014 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4015 |
printf("address data:\n"); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4016 |
for (i=0; i<sockaddr_size; i++) { |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4017 |
printf(" %02x\n", *cp++); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4018 |
} |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4019 |
} |
649 | 4020 |
# endif |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4021 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4022 |
RETURN (false); |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4023 |
} |
28 | 4024 |
} |
649 | 4025 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4026 |
# if defined(O_NONBLOCK) |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4027 |
fcntl(sock, F_SETFL, oldFlags); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4028 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4029 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4030 |
# else /* NO_SOCKET */ |
418 | 4031 |
RETURN (false); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4032 |
# endif /* NO_SOCKET */ |
42 | 4033 |
%}. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4034 |
isAsync == true ifTrue:[ |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4035 |
(self writeWaitWithTimeoutMs:timeout) ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4036 |
"/ a timeout occured |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4037 |
"/ should cancel the connect? |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4038 |
^ false. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4039 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4040 |
err := self getSocketError. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4041 |
err ~~ 0 ifTrue:[ |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4042 |
lastErrorNumber := err. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4043 |
^ false. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4044 |
]. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
4045 |
]. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4046 |
port := portNrOrNameOrNil. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4047 |
peer := addr. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4048 |
peerName := addrName. |
28 | 4049 |
^ true |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4050 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4051 |
" |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4052 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4053 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4054 |
sock connectTo:'localhost' port:21 withTimeout:1000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4055 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4056 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4057 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4058 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4059 |
sock connectTo:'localhost' port:9876 withTimeout:2000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4060 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
4061 |
" |
25 | 4062 |
! ! |
4063 |
||
4064 |
!Socket methodsFor:'queries'! |
|
4065 |
||
126 | 4066 |
domain |
4067 |
"return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)" |
|
4068 |
||
4069 |
^ domain |
|
4070 |
! |
|
4071 |
||
4072 |
getName |
|
4073 |
"return the name; here, we return the ports name" |
|
4074 |
||
4075 |
^ port printString |
|
4076 |
! |
|
4077 |
||
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4078 |
getPeer |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4079 |
"ST-80 compatibility: return an IPSocketAddress instance representing |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4080 |
my hostname/port combination. |
155
fcf846c707b7
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
4081 |
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
|
4082 |
|
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
|
4083 |
peer isNil ifTrue:[ |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
4084 |
peer := self class peerFromDomain:domain name:peerName port:port. |
819 | 4085 |
]. |
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
|
4086 |
^ peer |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4087 |
! |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
4088 |
|
25 | 4089 |
getPeerName |
4090 |
"return the peer name; thats the hostname (or dotted name) of the |
|
4091 |
partners host after an accept." |
|
4092 |
||
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
|
4093 |
peerName isNil ifTrue:[ |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
4094 |
peerName := self class peerNameFromDomain:domain peer:peer. |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
4095 |
]. |
25 | 4096 |
^ peerName |
28 | 4097 |
! |
4098 |
||
1146 | 4099 |
getSocketAddress |
4100 |
"implemented for swazoo project primitive code cant load as extension |
|
1170 | 4101 |
answer my own address (I am bound to this address). |
1146 | 4102 |
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
|
4103 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4104 |
|socketAddress error| |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4105 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4106 |
filePointer isNil ifTrue:[ |
1170 | 4107 |
^ self errorNotOpen |
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4108 |
]. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4109 |
socketAddress := ByteArray new:16. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4110 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4111 |
%{ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4112 |
#ifndef NO_SOCKET |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4113 |
OBJ t = __INST(filePointer); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4114 |
int sock; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4115 |
int sockaddr_size; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4116 |
int ret; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4117 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4118 |
if (!__isNonNilObject(socketAddress) || |
1170 | 4119 |
(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) { |
4120 |
error = @symbol(badArgument1); |
|
4121 |
goto err; |
|
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4122 |
} |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4123 |
sockaddr_size = __byteArraySize(socketAddress); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4124 |
|
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4125 |
sock = fileno(__FILEVal(t)); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4126 |
ret = getsockname(sock, (struct sockaddr *)__byteArrayVal(socketAddress), &sockaddr_size); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4127 |
if (ret < 0) { |
1170 | 4128 |
DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno)); |
4129 |
error = __MKSMALLINT(errno); |
|
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4130 |
} |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4131 |
err:; |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4132 |
#else /* NO_SOCKET */ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4133 |
error = @symbol(notImplemented); |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4134 |
#endif /* NO_SOCKET */ |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4135 |
%}. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4136 |
error notNil ifTrue:[ |
1170 | 4137 |
^ self errorReporter reportOn:error |
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4138 |
]. |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4139 |
^ socketAddress copyFrom:5 to:8 |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4140 |
! |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
4141 |
|
1146 | 4142 |
getSocketAdress |
4143 |
"implemented for swazoo project primitive code cant load as extension |
|
4144 |
answer the my own address (I am bound to this address). |
|
4145 |
Note that this address may change after connect or accept. |
|
4146 |
||
4147 |
BAD SPELLING, kept for compatibility with swazoo" |
|
4148 |
||
4149 |
||
4150 |
^ self getSocketAddress |
|
4151 |
! |
|
4152 |
||
126 | 4153 |
isActive |
4154 |
"return true, if the receiver has a connection" |
|
81 | 4155 |
|
126 | 4156 |
^ filePointer notNil |
81 | 4157 |
! |
4158 |
||
1110 | 4159 |
isConnected |
4160 |
"return true, if the receiver has a connection" |
|
4161 |
||
4162 |
^ self isActive |
|
4163 |
and:[port notNil |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4164 |
and:[peerName notNil or:[peer notNil]]] |
1110 | 4165 |
! |
4166 |
||
71 | 4167 |
port |
4168 |
"return the port number (or name for unix-sockets) to which the socket is bound" |
|
28 | 4169 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4170 |
|p| |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4171 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4172 |
port == 0 ifTrue:[ |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4173 |
p := self getPort. |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4174 |
p notNil ifTrue:[ |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4175 |
port := p |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4176 |
] |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
4177 |
]. |
71 | 4178 |
^ port |
28 | 4179 |
! |
4180 |
||
4181 |
type |
|
4182 |
"return the sockets connection type (i.e. #datagram, #stream etc)" |
|
4183 |
||
4184 |
^ socketType |
|
81 | 4185 |
! ! |
4186 |
||
126 | 4187 |
!Socket methodsFor:'socket setup'! |
4188 |
||
4189 |
domain:domainArg type:typeArg |
|
4190 |
"set up socket with domain and type. |
|
4191 |
This is a low level entry; no binding, listening or connect |
|
4192 |
is done. Both arguments must be symbols from one of |
|
4193 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
4194 |
||
649 | 4195 |
^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true |
126 | 4196 |
! |
4197 |
||
4198 |
domain:domainArg type:typeArg protocol:protocolNumber |
|
4199 |
"set up socket with domain, type and protocol number. |
|
4200 |
This is a low level entry; no binding, listening or connect |
|
4201 |
is done. Both arguments must be symbols from one of |
|
4202 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
4203 |
||
649 | 4204 |
^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true |
4205 |
||
4206 |
" |
|
4207 |
Socket new domain:#inet type:#stream |
|
4208 |
Socket new domain:#unix type:#stream |
|
4209 |
" |
|
4210 |
! |
|
4211 |
||
4212 |
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse |
|
4213 |
"set up socket with domain, type and protocol number. |
|
4214 |
This is a low level entry; no binding, listening or connect |
|
4215 |
is done. Both arguments must be symbols from one of |
|
4216 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp. |
|
4217 |
||
4218 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
4219 |
is to be set (to avoid the 'bind: address in use' error)." |
|
4220 |
||
126 | 4221 |
|errorNr| |
4222 |
||
4223 |
filePointer notNil ifTrue:[ |
|
789 | 4224 |
^ self errorAlreadyOpen |
126 | 4225 |
]. |
4226 |
%{ |
|
649 | 4227 |
|
418 | 4228 |
#ifndef NO_SOCKET |
126 | 4229 |
FILE *fp; |
4230 |
int dom, typ, pf, proto = 0, sock; |
|
649 | 4231 |
int on = 1; |
126 | 4232 |
|
4233 |
if (! __isSymbol(domainArg)) { |
|
789 | 4234 |
DBGPRINTF(("SOCKET: bad domain\n")); |
4235 |
RETURN ( nil ); |
|
126 | 4236 |
} |
4237 |
if (! __isSymbol(typeArg)) { |
|
789 | 4238 |
DBGPRINTF(("SOCKET: bad type\n")); |
4239 |
RETURN ( nil ); |
|
126 | 4240 |
} |
4241 |
if (protocolNumber != nil) { |
|
789 | 4242 |
if (!__isSmallInteger(protocolNumber)) { |
4243 |
DBGPRINTF(("SOCKET: bad protocol\n")); |
|
4244 |
RETURN ( nil ); |
|
4245 |
} |
|
4246 |
proto = __intVal(protocolNumber); |
|
126 | 4247 |
} |
4248 |
||
81 | 4249 |
|
126 | 4250 |
/* |
4251 |
* get address and protocol-family |
|
4252 |
*/ |
|
4253 |
#ifdef AF_UNIX |
|
4254 |
if (domainArg == @symbol(unix)) { |
|
789 | 4255 |
dom = AF_UNIX; |
126 | 4256 |
} else |
4257 |
#endif |
|
4258 |
#ifdef AF_INET |
|
4259 |
if (domainArg == @symbol(inet)) { |
|
789 | 4260 |
dom = AF_INET; |
126 | 4261 |
} else |
4262 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4263 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4264 |
if (domainArg == @symbol(inet6)) { |
789 | 4265 |
dom = AF_INET6; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4266 |
} else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4267 |
#endif |
126 | 4268 |
#ifdef AF_DECnet |
819 | 4269 |
if (domainArg == @symbol(decnet)) { |
789 | 4270 |
dom = AF_DECnet; |
126 | 4271 |
} else |
4272 |
#endif |
|
4273 |
#ifdef AF_APPLETALK |
|
4274 |
if (domainArg == @symbol(appletalk)) { |
|
789 | 4275 |
dom = AF_APPLETALK; |
126 | 4276 |
} else |
4277 |
#endif |
|
4278 |
#ifdef AF_X25 |
|
4279 |
if (domainArg == @symbol(x25)) { |
|
789 | 4280 |
dom = AF_X25; |
126 | 4281 |
} else |
4282 |
#endif |
|
819 | 4283 |
#ifdef AF_AX25 |
4284 |
if (domainArg == @symbol(ax25)) { |
|
4285 |
dom = AF_AX25; |
|
4286 |
} else |
|
4287 |
#endif |
|
126 | 4288 |
#ifdef AF_NS |
812 | 4289 |
if ((domainArg == @symbol(xns)) |
4290 |
|| (domainArg == @symbol(ns))) { |
|
789 | 4291 |
dom = AF_NS; |
126 | 4292 |
} else |
4293 |
#endif |
|
4294 |
#ifdef AF_SNA |
|
4295 |
if (domainArg == @symbol(sna)) { |
|
789 | 4296 |
dom = AF_SNA; |
126 | 4297 |
} else |
4298 |
#endif |
|
4299 |
#ifdef AF_RAW |
|
4300 |
if (domainArg == @symbol(raw)) { |
|
789 | 4301 |
dom = AF_RAW; |
126 | 4302 |
} else |
4303 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4304 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4305 |
if (domainArg == @symbol(iso)) { |
789 | 4306 |
dom = AF_ISO; |
874 | 4307 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4308 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4309 |
# ifdef AF_NETBIOS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4310 |
if (domainArg == @symbol(netbios)) { |
789 | 4311 |
dom = AF_NETBIOS; |
874 | 4312 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4313 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4314 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4315 |
if (domainArg == @symbol(ipx)) { |
789 | 4316 |
dom = AF_IPX; |
874 | 4317 |
} else |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4318 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4319 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4320 |
if (domainArg == @symbol(bridge)) { |
789 | 4321 |
dom = AF_BRIDGE; |
874 | 4322 |
} else |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
4323 |
# endif |
571 | 4324 |
# ifdef AF_BSC |
4325 |
if (domainArg == @symbol(bsc)) { |
|
789 | 4326 |
dom = AF_BSC; |
874 | 4327 |
} else |
571 | 4328 |
# endif |
812 | 4329 |
# ifdef AF_ROSE |
4330 |
if (domainArg == @symbol(rose)) { |
|
4331 |
dom = AF_ROSE; |
|
874 | 4332 |
} else |
812 | 4333 |
# endif |
869 | 4334 |
# ifdef AF_IRDA |
4335 |
if (domainArg == @symbol(irda)) { |
|
4336 |
dom = AF_IRDA; |
|
874 | 4337 |
} else |
869 | 4338 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4339 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4340 |
if (domainArg == @symbol(ccitt)) { |
789 | 4341 |
dom = AF_CCITT; |
874 | 4342 |
} else |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
4343 |
# endif |
126 | 4344 |
{ |
789 | 4345 |
DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg))); |
4346 |
RETURN ( nil ); |
|
126 | 4347 |
} |
4348 |
||
4349 |
#ifdef SOCK_STREAM |
|
4350 |
if (typeArg == @symbol(stream)) { |
|
789 | 4351 |
typ = SOCK_STREAM; |
126 | 4352 |
} else |
4353 |
#endif |
|
4354 |
#ifdef SOCK_DGRAM |
|
4355 |
if (typeArg == @symbol(datagram)) { |
|
789 | 4356 |
typ = SOCK_DGRAM; |
126 | 4357 |
} else |
4358 |
#endif |
|
4359 |
#ifdef SOCK_RAW |
|
4360 |
if (typeArg == @symbol(raw)) |
|
789 | 4361 |
typ = SOCK_RAW; |
126 | 4362 |
else |
4363 |
#endif |
|
4364 |
#ifdef SOCK_SEQPACKET |
|
4365 |
if (typeArg == @symbol(seqPacket)) |
|
789 | 4366 |
typ = SOCK_SEQPACKET; |
126 | 4367 |
else |
4368 |
#endif |
|
4369 |
{ |
|
789 | 4370 |
DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg))); |
4371 |
RETURN ( nil ); |
|
126 | 4372 |
} |
4373 |
||
4374 |
__BEGIN_INTERRUPTABLE__ |
|
4375 |
do { |
|
789 | 4376 |
DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto)); |
4377 |
sock = socket(dom, typ, proto); |
|
126 | 4378 |
#if defined(EPROTONOSUPPORT) /* for SGI */ |
789 | 4379 |
if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) { |
4380 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
|
4381 |
proto = 0; |
|
4382 |
sock = socket(dom, typ, 0); |
|
4383 |
} |
|
126 | 4384 |
#endif |
4385 |
} while ((sock < 0) && (errno == EINTR)); |
|
4386 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4387 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4388 |
|
4389 |
if (sock < 0) { |
|
789 | 4390 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno)); |
4391 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4392 |
} else { |
649 | 4393 |
# ifdef SO_REUSEADDR |
789 | 4394 |
if (reuse == true) { |
4395 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n")); |
|
4396 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
4397 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
4398 |
} |
|
4399 |
} |
|
649 | 4400 |
# endif /* SO_REUSEADDR */ |
711 | 4401 |
|
789 | 4402 |
/* |
4403 |
* make it a FILE * |
|
4404 |
*/ |
|
4405 |
fp = fdopen(sock, "r+"); |
|
4406 |
if (! fp) { |
|
4407 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
4408 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4409 |
__BEGIN_INTERRUPTABLE__ |
|
4410 |
close(sock); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4411 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4412 |
__END_INTERRUPTABLE__ |
4413 |
} else { |
|
1035 | 4414 |
if (@global(FileOpenTrace) == true) { |
1009 | 4415 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
4416 |
} |
|
876 | 4417 |
|
789 | 4418 |
__INST(filePointer) = __MKOBJ(fp); |
4419 |
__STORESELF(filePointer); |
|
4420 |
} |
|
126 | 4421 |
} |
418 | 4422 |
#endif |
126 | 4423 |
%}. |
4424 |
||
4425 |
"all ok?" |
|
4426 |
filePointer notNil ifTrue:[ |
|
789 | 4427 |
domain := domainArg. |
4428 |
socketType := typeArg. |
|
4429 |
Lobby register:self. |
|
126 | 4430 |
] ifFalse:[ |
789 | 4431 |
^ nil |
126 | 4432 |
]. |
4433 |
||
4434 |
" |
|
4435 |
Socket new domain:#inet type:#stream |
|
4436 |
Socket new domain:#unix type:#stream |
|
4437 |
" |
|
81 | 4438 |
! |
4439 |
||
126 | 4440 |
for:hostName port:portNr |
4441 |
"setup for a TCP socket (i.e. inet domain, stream type) |
|
4442 |
If hostname is nil, a server port is opened, |
|
4443 |
otherwise a client port to the server on host. |
|
4444 |
||
4445 |
HISTORIC LEFTOVER: |
|
4446 |
This method will vanish, as soon as the low level |
|
4447 |
connect/bind works," |
|
4448 |
||
4449 |
self obsoleteMethodWarning. |
|
4450 |
||
4451 |
filePointer notNil ifTrue:[ |
|
789 | 4452 |
^ self errorAlreadyOpen |
126 | 4453 |
]. |
4454 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
789 | 4455 |
self error:'invalid portNr' |
126 | 4456 |
]. |
1120 | 4457 |
%{ /* STACK: 100000 */ |
418 | 4458 |
#ifndef NO_SOCKET |
126 | 4459 |
struct sockaddr_in sa ; |
4460 |
struct hostent *hp ; |
|
4461 |
int a, sock ; |
|
4462 |
long addr; |
|
4463 |
FILE *fp; |
|
4464 |
int ret; |
|
4465 |
int on = 1; |
|
4466 |
||
4467 |
bzero((char *) &sa, sizeof(sa)) ; |
|
4468 |
sa.sin_family = AF_INET; |
|
4469 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
4470 |
||
4471 |
if ((hostName != nil) && __isString(hostName)){ |
|
789 | 4472 |
bzero(&sa, sizeof(sa)) ; |
4473 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
|
4474 |
/* |
|
4475 |
* is Internet addr in octet notation |
|
4476 |
*/ |
|
4477 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
4478 |
} else { |
|
4479 |
/* |
|
4480 |
* do we know the host's address? |
|
4481 |
*/ |
|
4482 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
|
4483 |
if (hp == NULL) { |
|
4484 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
|
4485 |
RETURN ( nil ); |
|
4486 |
} |
|
4487 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
4488 |
sa.sin_family = hp->h_addrtype; |
|
4489 |
} |
|
126 | 4490 |
} |
4491 |
||
4492 |
/* |
|
4493 |
* create the socket |
|
4494 |
*/ |
|
4495 |
__BEGIN_INTERRUPTABLE__ |
|
4496 |
do { |
|
789 | 4497 |
sock = socket(sa.sin_family, SOCK_STREAM, 0); |
126 | 4498 |
} while ((sock < 0) && (errno == EINTR)); |
4499 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4500 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4501 |
|
4502 |
if (sock < 0) { |
|
789 | 4503 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno)); |
4504 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4505 |
} else { |
789 | 4506 |
/* |
4507 |
* connect/bind |
|
4508 |
*/ |
|
1009 | 4509 |
sa.sin_port = htons((u_short) __intVal(portNr)) ; |
789 | 4510 |
|
4511 |
__BEGIN_INTERRUPTABLE__ |
|
4512 |
if (hostName != nil) { |
|
4513 |
do { |
|
4514 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4515 |
} while ((ret < 0) && (errno == EINTR)); |
|
4516 |
} else { |
|
126 | 4517 |
#ifdef SO_REUSEADDR |
789 | 4518 |
/* |
4519 |
* should I also do this for DGRAM sockets ? |
|
4520 |
*/ |
|
4521 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
4522 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
4523 |
} |
|
126 | 4524 |
#endif /* SO_REUSEADDR */ |
789 | 4525 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
4526 |
do { |
|
4527 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4528 |
} while ((ret < 0) && (errno == EINTR)); |
|
4529 |
} |
|
4530 |
__END_INTERRUPTABLE__ |
|
4531 |
||
4532 |
if (ret < 0) { |
|
4533 |
DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno)); |
|
4534 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4535 |
__BEGIN_INTERRUPTABLE__ |
|
4536 |
close(sock) ; |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4537 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4538 |
__END_INTERRUPTABLE__ |
4539 |
} else { |
|
4540 |
/* |
|
4541 |
* make it a FILE * |
|
4542 |
*/ |
|
4543 |
fp = fdopen(sock, "r+"); |
|
4544 |
if (! fp) { |
|
4545 |
DBGPRINTF(("SOCKET: fdopen failed\n")); |
|
4546 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4547 |
__BEGIN_INTERRUPTABLE__ |
|
4548 |
close(sock); |
|
822 | 4549 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4550 |
__END_INTERRUPTABLE__ |
4551 |
} else { |
|
1035 | 4552 |
if (@global(FileOpenTrace) == true) { |
1009 | 4553 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
4554 |
} |
|
876 | 4555 |
|
444 | 4556 |
#ifdef BUGGY_STDIO_LIB |
789 | 4557 |
setbuf(fp, NULL); |
4558 |
__INST(buffered) = false; |
|
126 | 4559 |
#endif |
789 | 4560 |
__INST(filePointer) = __MKOBJ(fp); |
4561 |
__STORESELF(filePointer); |
|
4562 |
} |
|
4563 |
} |
|
126 | 4564 |
} |
418 | 4565 |
#endif |
126 | 4566 |
%}. |
4567 |
filePointer isNil ifTrue:[ |
|
789 | 4568 |
^ nil |
126 | 4569 |
]. |
4570 |
mode := #readwrite. |
|
169 | 4571 |
Lobby register:self. |
126 | 4572 |
binary := false. |
4573 |
||
4574 |
domain := #inet. |
|
4575 |
socketType := #stream. |
|
4576 |
protocol := portNr. |
|
4577 |
peerName := hostName. |
|
81 | 4578 |
|
126 | 4579 |
" |
4580 |
Socket new for:'clam' port:(Socket portOfService:'echo') |
|
4581 |
||
4582 |
Socket new for:nil port:9999 |
|
4583 |
Socket new for:(OperatingSystem getHostName) port:9999 |
|
4584 |
" |
|
4585 |
! |
|
4586 |
||
4587 |
for:hostName udpPort:portNr |
|
4588 |
"setup for a UDP socket (i.e. inet domain, datagram type) |
|
4589 |
if hostname is nil, a server port is opened; |
|
4590 |
otherwise a client port to the server on host. |
|
4591 |
||
4592 |
HISTORIC LEFTOVER: |
|
4593 |
This method will vanish, as soon as the low level |
|
4594 |
connect/bind works," |
|
4595 |
||
4596 |
self obsoleteMethodWarning. |
|
4597 |
||
4598 |
filePointer notNil ifTrue:[ |
|
789 | 4599 |
^ self errorAlreadyOpen |
126 | 4600 |
]. |
4601 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
789 | 4602 |
self error:'invalid portNr' |
126 | 4603 |
]. |
1120 | 4604 |
%{ /* STACK: 100000 */ |
418 | 4605 |
#ifndef NO_SOCKET |
126 | 4606 |
struct sockaddr_in sa ; |
4607 |
struct hostent *hp ; |
|
4608 |
int a, sock ; |
|
4609 |
long addr; |
|
4610 |
FILE *fp; |
|
4611 |
int ret; |
|
4612 |
||
4613 |
if (hostName != nil) { |
|
789 | 4614 |
bzero(&sa, sizeof(sa)) ; |
4615 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
|
4616 |
/* |
|
4617 |
* is Internet addr in octet notation |
|
4618 |
*/ |
|
4619 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
4620 |
sa.sin_family = AF_INET ; |
|
4621 |
} else { |
|
4622 |
/* |
|
4623 |
* is hostname - |
|
4624 |
* do we know the host's address? |
|
4625 |
*/ |
|
4626 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
|
4627 |
if (hp == NULL) { |
|
4628 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
|
4629 |
RETURN ( nil ); |
|
4630 |
} |
|
4631 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
4632 |
sa.sin_family = hp->h_addrtype ; |
|
4633 |
} |
|
526 | 4634 |
} else { |
789 | 4635 |
sa.sin_family = AF_INET; |
526 | 4636 |
} |
126 | 4637 |
|
4638 |
/* |
|
4639 |
* create the socket |
|
4640 |
*/ |
|
4641 |
__BEGIN_INTERRUPTABLE__ |
|
4642 |
do { |
|
789 | 4643 |
sock = socket(sa.sin_family, SOCK_DGRAM, 0); |
126 | 4644 |
} while ((sock < 0) && (errno == EINTR)); |
4645 |
__END_INTERRUPTABLE__ |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4646 |
DBGFPRINTF((stderr, "socket create newSock=%d\n", sock)); |
126 | 4647 |
|
4648 |
if (sock < 0) { |
|
789 | 4649 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno)); |
4650 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 4651 |
} else { |
789 | 4652 |
/* |
4653 |
* ok, |
|
4654 |
* connect/bind |
|
4655 |
*/ |
|
4656 |
__BEGIN_INTERRUPTABLE__ |
|
4657 |
if (hostName == nil) { |
|
4658 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
4659 |
do { |
|
4660 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4661 |
} while ((ret < 0) && (errno == EINTR)); |
|
4662 |
} else { |
|
1009 | 4663 |
sa.sin_port = htons((u_short) __intVal(portNr)) ; |
789 | 4664 |
do { |
4665 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4666 |
} while ((ret < 0) && (errno == EINTR)); |
|
4667 |
} |
|
4668 |
__END_INTERRUPTABLE__ |
|
4669 |
||
4670 |
if (ret < 0) { |
|
4671 |
DBGPRINTF(("SOCKET: bind/connect call failed\n")); |
|
4672 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4673 |
__BEGIN_INTERRUPTABLE__ |
|
4674 |
close(sock) ; |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4675 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4676 |
__END_INTERRUPTABLE__ |
4677 |
} else { |
|
4678 |
/* |
|
4679 |
* make it a FILE * |
|
4680 |
*/ |
|
4681 |
fp = fdopen(sock, "r+"); |
|
4682 |
if (! fp) { |
|
4683 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
4684 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4685 |
__BEGIN_INTERRUPTABLE__ |
|
4686 |
close(sock); |
|
821
40b0b69bf4b5
more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
4687 |
DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock)); |
789 | 4688 |
__END_INTERRUPTABLE__ |
4689 |
} else { |
|
1009 | 4690 |
if (@global(ExternalStream:FileOpenTrace) == true) { |
4691 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
|
4692 |
} |
|
876 | 4693 |
|
444 | 4694 |
#ifdef BUGGY_STDIO_LIB |
789 | 4695 |
setbuf(fp, NULL); |
4696 |
__INST(buffered) = false; |
|
126 | 4697 |
#endif |
789 | 4698 |
__INST(filePointer) = __MKOBJ(fp); |
4699 |
__STORESELF(filePointer); |
|
4700 |
} |
|
4701 |
} |
|
126 | 4702 |
} |
418 | 4703 |
#endif |
126 | 4704 |
%}. |
4705 |
filePointer isNil ifTrue:[ |
|
789 | 4706 |
^ nil |
126 | 4707 |
]. |
4708 |
||
4709 |
mode := #readwrite. |
|
169 | 4710 |
Lobby register:self. |
126 | 4711 |
binary := false. |
4712 |
||
4713 |
domain := #inet. |
|
4714 |
socketType := #datagram. |
|
4715 |
protocol := portNr. |
|
4716 |
peerName := hostName. |
|
4717 |
||
4718 |
" |
|
4719 |
Socket new for:'clam' udpPort:(Socket portOfService:'echo') |
|
4720 |
" |
|
28 | 4721 |
! ! |
4722 |
||
4723 |
!Socket methodsFor:'specials'! |
|
4724 |
||
4725 |
receiveTimeout:seconds |
|
71 | 4726 |
"set the receive timeout - for special applications only. |
4727 |
Not all operatingSystems offer this functionality |
|
4728 |
(returns false, if unsupported)" |
|
28 | 4729 |
|
4730 |
|millis| |
|
4731 |
||
4732 |
filePointer isNil ifTrue:[ |
|
789 | 4733 |
^ self errorNotOpen |
28 | 4734 |
]. |
4735 |
millis := (seconds * 1000) rounded. |
|
4736 |
%{ |
|
4737 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
58 | 4738 |
if (__isSmallInteger(millis)) { |
789 | 4739 |
OBJ fp = __INST(filePointer); |
4740 |
int sock; |
|
4741 |
int opt; |
|
4742 |
||
4743 |
sock = fileno(__FILEVal(fp)); |
|
1009 | 4744 |
opt = __intVal(millis) / (1000 / HZ); |
789 | 4745 |
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int)); |
4746 |
RETURN(true); |
|
28 | 4747 |
} |
4748 |
#endif |
|
71 | 4749 |
%}. |
28 | 4750 |
^ false |
81 | 4751 |
! |
4752 |
||
126 | 4753 |
sendTimeout:seconds |
4754 |
"set the send timeout - for special applications only. |
|
4755 |
Not all operatingSystems offer this functionality |
|
4756 |
(returns false, if unsupported)" |
|
81 | 4757 |
|
126 | 4758 |
|millis| |
25 | 4759 |
|
126 | 4760 |
filePointer isNil ifTrue:[ |
789 | 4761 |
^ self errorNotOpen |
126 | 4762 |
]. |
4763 |
millis := (seconds * 1000) rounded. |
|
4764 |
%{ |
|
4765 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
4766 |
if (__isSmallInteger(millis)) { |
|
789 | 4767 |
OBJ fp = __INST(filePointer); |
4768 |
int sock; |
|
4769 |
int opt; |
|
4770 |
||
4771 |
sock = fileno(__FILEVal(fp)); |
|
1009 | 4772 |
opt = __intVal(millis) / (1000 / HZ); |
789 | 4773 |
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int)); |
4774 |
RETURN(true); |
|
126 | 4775 |
} |
4776 |
#endif |
|
4777 |
%}. |
|
4778 |
^ false |
|
4779 |
! ! |
|
82 | 4780 |
|
464 | 4781 |
!Socket class methodsFor:'documentation'! |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4782 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4783 |
version |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
4784 |
^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.179 2003-07-09 14:26:57 cg Exp $' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4785 |
! ! |