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