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