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