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