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