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