author | Claus Gittinger <cg@exept.de> |
Wed, 15 Feb 2006 14:52:13 +0100 | |
changeset 1600 | f3acd5382fa1 |
parent 1584 | 84d0e5730798 |
child 1781 | 7e5b6c83e627 |
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 |
||
1600 | 1018 |
!Socket class methodsFor:'Compatibility-Squeak'! |
1019 |
||
1020 |
initializeNetwork |
|
1021 |
"/ intentionally left blank here |
|
1022 |
! |
|
1023 |
||
1024 |
wildcardPort |
|
1025 |
^ nil |
|
1026 |
! ! |
|
1027 |
||
1462 | 1028 |
!Socket class methodsFor:'Compatibility-VW'! |
1029 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1030 |
AF_INET |
1462 | 1031 |
^ #AF_INET |
1032 |
! |
|
1033 |
||
1034 |
SOCK_STREAM |
|
1035 |
^ #SOCK_STREAM |
|
1036 |
! ! |
|
1037 |
||
1038 |
!Socket class methodsFor:'Signal constants'! |
|
1039 |
||
1040 |
brokenConnectionSignal |
|
1041 |
"return the signal used to tell broken connections. |
|
1042 |
Since in unix, this is the same as the broken pipe signal, |
|
1043 |
return that one. |
|
1044 |
(for other Operatingsystems, this may change ..)" |
|
1045 |
||
1046 |
^ PipeStream brokenPipeSignal |
|
1047 |
! |
|
1048 |
||
1049 |
invalidArgumentsSignal |
|
1050 |
"dummy for compatibility" |
|
1051 |
||
1052 |
^ self errorSignal |
|
1053 |
! ! |
|
1054 |
||
1055 |
!Socket class methodsFor:'debugging'! |
|
1056 |
||
1057 |
debug:aBoolean |
|
1058 |
"turn on/off internal debugprints. |
|
1059 |
This method is for ST/X debugging only and |
|
1060 |
may be removed in later versions" |
|
1061 |
||
1062 |
%{ /* NOCONTEXT */ |
|
1063 |
||
1064 |
__debugging__ = (aBoolean == true); |
|
1065 |
%} |
|
1066 |
" |
|
1067 |
Socket debug:true |
|
1068 |
Socket debug:false |
|
1069 |
" |
|
1070 |
! ! |
|
1071 |
||
525 | 1072 |
!Socket class methodsFor:'host queries'! |
1073 |
||
1074 |
appletalkAddressOfHost:aHostName |
|
1075 |
"return the APPLETALK address for a hostname as a byteArray, |
|
819 | 1076 |
where the network bytes come first (no matter what the local byteorder is) |
1077 |
followed by the node byte. |
|
525 | 1078 |
If the host is unknown, return nil. |
812 | 1079 |
This is the reverse operation to #hostWithAppletalkAddress:. |
1080 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1081 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1082 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1083 |
handle:[:ex | |
1343 | 1084 |
^ nil |
1085 |
] |
|
1086 |
do:[ |
|
1087 |
^ (AppletalkSocketAddress hostName:aHostName) address |
|
1088 |
] |
|
525 | 1089 |
! |
1090 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1091 |
hostWithAppletalkAddress:addrByteArray |
525 | 1092 |
"return the hostname for an APPLETALK address. |
1093 |
The address is supposed to be a byteArray consisting of 3 bytes, |
|
1094 |
the network bytes come first (no matter what the local byteorder is). |
|
1095 |
The last byte is the node number. |
|
1096 |
Nil is returned for an unknown host or if its not an appletalk host. |
|
812 | 1097 |
This is is the reverse operation to #appletalkAddressOfHost:. |
1098 |
WARNING: untested code - I have no appletalk to test this." |
|
525 | 1099 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1100 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1101 |
handle:[:ex | |
1343 | 1102 |
^ nil |
1103 |
] |
|
1104 |
do:[ |
|
1105 |
^ (AppletalkSocketAddress hostAddress:addrByteArray) hostName |
|
1106 |
] |
|
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1107 |
|
525 | 1108 |
" |
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1109 |
Socket appletalkAddressOfHost:'yourAppleHere' |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1110 |
Socket hostWithAppletalkAddress:#[1 2 3] |
525 | 1111 |
" |
126 | 1112 |
! |
1113 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1114 |
hostWithIpAddress:addrByteArray |
126 | 1115 |
"return the hostname for an IP (internet-) address. |
1116 |
The address is supposed to be a byteArray consisting of 4 bytes, |
|
1117 |
the network bytes come first (no matter what the local byteorder is). |
|
525 | 1118 |
Nil is returned for an unknown host or if its not an internet host. |
126 | 1119 |
This is the reverse operation to #ipAddressOfHost:." |
1120 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1121 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1122 |
handle:[:ex | |
1343 | 1123 |
^ nil |
1124 |
] |
|
1125 |
do:[ |
|
1126 |
^ (IPSocketAddress hostAddress:addrByteArray) hostName |
|
1127 |
] |
|
126 | 1128 |
|
1129 |
" |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1130 |
Socket ipAddressOfHost:'clam' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1131 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1132 |
Socket ipAddressOfHost:'porty' |
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1133 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1134 |
Socket hostWithIpAddress:#[1 2 3 4] |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1135 |
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
|
1136 |
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
|
1137 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'www.altavista.com') |
126 | 1138 |
" |
1139 |
! |
|
1140 |
||
1278
7251c65b8d38
use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
1141 |
hostWithIpV6Address:addrByteArray |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1142 |
"return the hostname for an IPv6 (internet-) address. |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1143 |
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
|
1144 |
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
|
1145 |
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
|
1146 |
This is the reverse operation to #ipV6AddressOfHost:." |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1147 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1148 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1149 |
handle:[:ex | |
1343 | 1150 |
^ nil |
1151 |
] |
|
1152 |
do:[ |
|
1153 |
^ (IPv6SocketAddress hostAddress:addrByteArray) hostName |
|
1154 |
] |
|
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1155 |
|
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1156 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1157 |
Socket ipV6AddressOfHost:'clam' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1158 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1159 |
Socket ipV6AddressOfHost:'porty' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1160 |
Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1161 |
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
|
1162 |
Socket ipV6AddressOfHost:'www.exept.de' |
820
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1163 |
" |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1164 |
! |
b6860c3660c8
Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents:
819
diff
changeset
|
1165 |
|
6 | 1166 |
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
|
1167 |
"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
|
1168 |
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
|
1169 |
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
|
1170 |
This is the reverse operation to #hostWithIpAddress:." |
6 | 1171 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1172 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1173 |
handle:[:ex | |
1343 | 1174 |
^ nil |
1175 |
] |
|
1176 |
do:[ |
|
1177 |
^ (IPSocketAddress hostName:aHostName) address |
|
1178 |
] |
|
21 | 1179 |
|
71 | 1180 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1181 |
Socket ipAddressOfHost:'localhost' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1182 |
Socket ipAddressOfHost:'exept' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1183 |
Socket ipAddressOfHost:'1.2.3.4' |
1274
f257a1b16b4d
use naemLookup from SocketAddress for ipv6
Claus Gittinger <cg@exept.de>
parents:
1263
diff
changeset
|
1184 |
Socket ipAddressOfHost:'193.15.16.17' |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1185 |
Socket ipAddressOfHost:'josef' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1186 |
Socket ipAddressOfHost:'styx.com' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1187 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1188 |
Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') |
71 | 1189 |
" |
819 | 1190 |
! |
1191 |
||
1192 |
ipV6AddressOfHost:aHostName |
|
1193 |
"return the IPv6 (internet-) number for a hostname as a byteArray, |
|
1194 |
where the network bytes come first (no matter what the cpus byteOrder is). |
|
1195 |
If the host is unknown, return nil. |
|
1196 |
This is the reverse operation to #hostWithIpV6Address:." |
|
1197 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1198 |
NameLookupError |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1199 |
handle:[:ex | |
1343 | 1200 |
^ nil |
1201 |
] |
|
1202 |
do:[ |
|
1203 |
^ (IPv6SocketAddress hostName:aHostName) address |
|
1204 |
] |
|
819 | 1205 |
|
1206 |
" |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1207 |
Socket ipV6AddressOfHost:'localhost' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1208 |
Socket ipV6AddressOfHost:'exept' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1209 |
Socket ipV6AddressOfHost:'exept.exept.de' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1210 |
Socket ipV6AddressOfHost:'www.google.de' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1211 |
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
|
1212 |
Socket ipV6AddressOfHost:'josef' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1213 |
Socket ipV6AddressOfHost:'styx.com' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1214 |
Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1215 |
Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') |
819 | 1216 |
" |
531 | 1217 |
! ! |
1218 |
||
1209 | 1219 |
!Socket class methodsFor:'obsolete'! |
1220 |
||
1221 |
connectTo:service on:host |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1222 |
"standard & easy client setup: |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1223 |
create new client tcp socket, bind and connect; |
1343 | 1224 |
return the socket. |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1225 |
The thread blocks (interruptable), until the connection is established." |
1282 | 1226 |
|
1227 |
^ self newTCPclientToHost:host port:(self portOfService:service). |
|
1209 | 1228 |
|
1229 |
" |
|
1230 |
Socket connectTo:9995 on:'clam' |
|
1231 |
Socket connectTo:4711 on:'exept' |
|
1232 |
Socket connectTo:'finger' on:'clam' |
|
1233 |
Socket connectTo:'ftp' on:'exept' |
|
1234 |
Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER') |
|
1235 |
" |
|
1236 |
! |
|
1237 |
||
1282 | 1238 |
provide:aService |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1239 |
"standard & easy server setup: |
1209 | 1240 |
create a new TCP server socket providing a service." |
1241 |
||
1242 |
<resource:#obsolete> |
|
1243 |
||
1244 |
|newSock| |
|
1245 |
||
1584 | 1246 |
self obsoleteMethodWarning:'use #newTCPserverAtPort: / #listen'. |
1282 | 1247 |
|
1248 |
newSock := self newTCPserverAtPort:(self portOfService:aService). |
|
1209 | 1249 |
newSock notNil ifTrue:[ |
1584 | 1250 |
newSock listenFor:5. |
1209 | 1251 |
]. |
1252 |
^ newSock |
|
1253 |
||
1254 |
" |
|
1255 |
Socket provide:9995 |
|
1256 |
(Socket provide:9996) accept |
|
1257 |
Socket provide:'nntp' |
|
1258 |
" |
|
1259 |
! ! |
|
1260 |
||
531 | 1261 |
!Socket class methodsFor:'queries'! |
1262 |
||
1263 |
domainOfProtocol:aProtocol |
|
1264 |
"given a protocols name (i.e. tcp, udp etc) return the domain. |
|
1265 |
This method needs more ... - or is there a way to get this from the system ?" |
|
1266 |
||
1267 |
" |
|
1268 |
tcp/ip stuff |
|
1269 |
" |
|
1270 |
(aProtocol = 'tcp') ifTrue:[^ #inet]. |
|
1271 |
(aProtocol = 'udp') ifTrue:[^ #inet]. |
|
1272 |
(aProtocol = 'ip') ifTrue:[^ #inet]. |
|
1273 |
" |
|
1274 |
unix domain |
|
1275 |
" |
|
1276 |
(aProtocol = 'ud') ifTrue:[^ #unix]. |
|
1277 |
||
1278 |
" |
|
1279 |
add x25 stuff (if any) here ... |
|
1280 |
" |
|
1281 |
" |
|
1282 |
add appletalk stuff (if any) here ... |
|
1283 |
" |
|
1284 |
" |
|
1285 |
add other stuff (if any) here ... |
|
1286 |
" |
|
1287 |
^ nil |
|
1288 |
||
1289 |
" |
|
1290 |
Socket domainOfProtocol:'tcp' |
|
1291 |
Socket domainOfProtocol:'ucp' |
|
1292 |
Socket domainOfProtocol:(Socket protocolOfService:'nntp') |
|
1293 |
Socket domainOfProtocol:(Socket protocolOfService:'echo') |
|
1294 |
" |
|
6 | 1295 |
! |
1296 |
||
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1297 |
networkLongOrderIsMSB |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1298 |
"return the well known fact, that network byte order is most significant byte first" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1299 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1300 |
<resource: #obsolete> |
964 | 1301 |
|
1302 |
^ true |
|
206
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 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1305 |
networkShortOrderIsMSB |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1306 |
"return the well known fact, that network byte order is most significant byte first" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1307 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1308 |
<resource: #obsolete> |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1309 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
1310 |
^ true |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1311 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1312 |
|
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1313 |
peerFromDomain:domain name:peerName port:port |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1314 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1315 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1316 |
addrClass := self socketAddressClassForDomain:domain. |
1263
23161346a162
no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents:
1260
diff
changeset
|
1317 |
^ 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
|
1318 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1319 |
|
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1320 |
peerNameFromDomain:domain peer:peer |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1321 |
|addrClass| |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1322 |
|
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1323 |
addrClass := self socketAddressClassForDomain:domain. |
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1324 |
^ 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
|
1325 |
! |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
1326 |
|
0 | 1327 |
portOfService:aNameOrNumber |
819 | 1328 |
"returns the port-number for a given IP-service |
0 | 1329 |
or nil if no such service exists; |
1330 |
- used to convert service names to portNumbers" |
|
1331 |
||
91 | 1332 |
^ self portOfService:aNameOrNumber protocol:nil |
1333 |
||
28 | 1334 |
" |
1335 |
Socket portOfService:'finger' |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1336 |
Socket portOfService:'nntp' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1337 |
Socket portOfService:'echo' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1338 |
Socket portOfService:'snmp' |
28 | 1339 |
" |
0 | 1340 |
! |
1341 |
||
91 | 1342 |
portOfService:aNameOrNumber protocol:aProtocol |
819 | 1343 |
"returns the port-number for a given IP-service |
91 | 1344 |
or nil if no such service exists; |
1345 |
- used to convert service names to portNumbers" |
|
1346 |
||
1499
1ff98f9bc58f
Unlimitedstack for some methods which call getXXXByName().
Stefan Vogel <sv@exept.de>
parents:
1486
diff
changeset
|
1347 |
%{ /* UNLIMITEDSTACK */ |
418 | 1348 |
#ifndef NO_SOCKET |
91 | 1349 |
struct servent *servent = NULL; |
1350 |
char *protocol; |
|
1351 |
int tryBoth = 0; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1352 |
short portNo; |
91 | 1353 |
|
604 | 1354 |
if (__isSmallInteger(aNameOrNumber)) { |
1503 | 1355 |
RETURN ( aNameOrNumber ); |
92 | 1356 |
} |
1357 |
||
604 | 1358 |
if (__isString(aProtocol)) { |
1503 | 1359 |
protocol = (char *)__stringVal(aProtocol); |
604 | 1360 |
} else { |
1503 | 1361 |
protocol = "tcp"; |
1362 |
tryBoth = 1; |
|
91 | 1363 |
} |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1364 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1365 |
if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) { |
1503 | 1366 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol); |
1367 |
if (servent != NULL) { |
|
1368 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
|
1369 |
} |
|
1370 |
if (tryBoth) { |
|
1371 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
|
1372 |
if (servent != NULL) { |
|
1373 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
|
1374 |
} |
|
1375 |
} |
|
1376 |
RETURN ( nil ); |
|
91 | 1377 |
} |
418 | 1378 |
#endif |
91 | 1379 |
RETURN ( nil ); |
1380 |
%} |
|
1381 |
" |
|
1382 |
Socket portOfService:'echo' protocol:'udp' |
|
1383 |
Socket portOfService:'echo' protocol:'tcp' |
|
1384 |
" |
|
1385 |
! |
|
1386 |
||
0 | 1387 |
protocolOfService:aNameOrNumber |
819 | 1388 |
"returns the protocol (as string) for a given IP-service |
28 | 1389 |
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
|
1390 |
|
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1391 |
%{ /* UNLIMITEDSTACK(noWIN32) */ |
418 | 1392 |
#ifndef NO_SOCKET |
0 | 1393 |
struct servent *servent = NULL; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1394 |
short portNo; |
0 | 1395 |
|
58 | 1396 |
if (__isSmallInteger(aNameOrNumber)) { |
1503 | 1397 |
portNo = __intVal(aNameOrNumber); |
1398 |
servent = getservbyport(htons(portNo), "tcp") ; |
|
1399 |
if (servent == NULL) { |
|
1400 |
servent = getservbyport(htons(portNo), "udp") ; |
|
1401 |
if (servent == NULL) { |
|
1402 |
RETURN ( nil ); |
|
1403 |
} |
|
1404 |
} |
|
0 | 1405 |
} else { |
1503 | 1406 |
if (__isString(aNameOrNumber)) { |
1407 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp"); |
|
1408 |
if (servent == NULL) { |
|
1409 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
|
1410 |
if (servent == NULL) { |
|
1411 |
RETURN ( nil ); |
|
1412 |
} |
|
1413 |
} |
|
1414 |
} |
|
0 | 1415 |
} |
1416 |
if (servent) { |
|
1503 | 1417 |
RETURN ( __MKSTRING(servent->s_proto) ); |
0 | 1418 |
} |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1419 |
#endif /* !NO_SOCKET */ |
0 | 1420 |
RETURN ( nil ); |
1421 |
%} |
|
28 | 1422 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1423 |
Socket protocolOfService:'finger' |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1424 |
Socket protocolOfService:'nntp' |
28 | 1425 |
Socket protocolOfService:'xxx' |
1426 |
Socket protocolOfService:79 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1427 |
Socket protocolOfService:'snmp' |
28 | 1428 |
" |
1429 |
! |
|
1430 |
||
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
|
1431 |
socketAddressClassForDomain:domain |
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1432 |
^ SocketAddress knownClassFromCode:domain |
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1433 |
|
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1434 |
" |
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1435 |
self socketAddressClassForDomain:#inet |
1260
9a8fb2391174
instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents:
1235
diff
changeset
|
1436 |
self socketAddressClassForDomain:#unix |
1230
2cfb8c270cb5
more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents:
1224
diff
changeset
|
1437 |
" |
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
|
1438 |
! |
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 |
|
532 | 1440 |
supportedProtocolFamilies |
1441 |
"return a collection of supported protocol families. |
|
1442 |
This list specifies what the Socket class supports - |
|
1443 |
socket creation may still fail, if your system was built |
|
1444 |
without it." |
|
1445 |
||
1280
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
1446 |
^ OperatingSystem supportedProtocolFamilies |
532 | 1447 |
|
1448 |
" |
|
1449 |
Socket supportedProtocolFamilies |
|
1450 |
" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1451 |
! |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1452 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1453 |
typeOfProtocol:aProtocol |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1454 |
"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
|
1455 |
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
|
1456 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1457 |
(aProtocol = 'tcp') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1458 |
(aProtocol = 'udp') ifTrue:[^ #datagram]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1459 |
(aProtocol = 'ip') ifTrue:[^ #raw]. |
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 |
unix domain |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1462 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1463 |
(aProtocol = 'ud') ifTrue:[^ #stream]. |
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 |
add x25 stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1466 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1467 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1468 |
add appletalk stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1469 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1470 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1471 |
add other stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1472 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1473 |
^ nil |
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 |
Socket typeOfProtocol:'tcp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1477 |
Socket typeOfProtocol:'ucp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1478 |
Socket typeOfProtocol:(Socket protocolOfService:'nntp') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1479 |
Socket typeOfProtocol:(Socket protocolOfService:'echo') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1480 |
" |
28 | 1481 |
! ! |
1482 |
||
1202 | 1483 |
!Socket methodsFor:'Compatibility-Dolphin'! |
1110 | 1484 |
|
1485 |
setReceiveTimeout: milliseconds |
|
1486 |
self receiveTimeout:(milliseconds / 1000) |
|
1487 |
! |
|
1488 |
||
1489 |
setSendTimeout: milliseconds |
|
1490 |
self sendTimeout:(milliseconds / 1000) |
|
1491 |
! ! |
|
1492 |
||
1202 | 1493 |
!Socket methodsFor:'Compatibility-ST80'! |
28 | 1494 |
|
887 | 1495 |
acceptNonBlock |
1496 |
^ self accept |
|
1497 |
! |
|
1498 |
||
870 | 1499 |
connectTo:aSocketAddress |
1500 |
^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port |
|
1501 |
! |
|
1502 |
||
126 | 1503 |
errorReporter |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1504 |
"ST-80 mimicry." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1505 |
|
1535 | 1506 |
^ self class |
28 | 1507 |
! |
1508 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1509 |
ioConnection |
887 | 1510 |
^ self |
1511 |
! |
|
1512 |
||
126 | 1513 |
notReadySignal |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1514 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1515 |
for now - this is not yet raised" |
71 | 1516 |
|
126 | 1517 |
^ Signal new |
486 | 1518 |
! |
1519 |
||
576 | 1520 |
readAppendStream |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1521 |
"ST-80 mimicry. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1522 |
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
|
1523 |
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
|
1524 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1525 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1526 |
this method returns the receiver, for transparency" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1527 |
|
576 | 1528 |
^ self |
1529 |
! |
|
1530 |
||
486 | 1531 |
readStream |
1532 |
"ST-80 mimicry. |
|
1533 |
In ST-80, socket is not a stream, but referes to one. |
|
1534 |
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
|
1535 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1536 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1537 |
this method returns the receiver, for transparency" |
486 | 1538 |
|
1539 |
^ self |
|
1540 |
||
1541 |
"Created: 24.1.1997 / 23:52:57 / cg" |
|
1542 |
! |
|
1543 |
||
1544 |
writeStream |
|
1545 |
"ST-80 mimicry. |
|
1546 |
In ST-80, socket is not a stream, but referes to one. |
|
1547 |
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
|
1548 |
the actual stream. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1549 |
In ST/X, sockets inherit from stream, so |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
1550 |
this method returns the receiver, for transparency" |
486 | 1551 |
|
1552 |
^ self |
|
1553 |
||
1554 |
"Created: 24.1.1997 / 10:34:35 / cg" |
|
1555 |
"Modified: 24.1.1997 / 23:52:52 / cg" |
|
71 | 1556 |
! ! |
1557 |
||
1202 | 1558 |
!Socket methodsFor:'Compatibility-Squeak'! |
771 | 1559 |
|
1462 | 1560 |
address |
1561 |
^ self getSocketAddress |
|
1562 |
! |
|
1563 |
||
1564 |
dataAvailable |
|
1565 |
^ self canReadWithoutBlocking |
|
1566 |
! |
|
1567 |
||
1568 |
listenOn:aPortNr |
|
1569 |
self bindTo:aPortNr address:nil. |
|
1570 |
self listenWithBacklog:5 |
|
1571 |
! |
|
1572 |
||
771 | 1573 |
peerName |
1574 |
"return my peer (i.e. ipAddr + port); |
|
1575 |
May return nil if not yet setup completely." |
|
1576 |
||
1577 |
^ self getPeer |
|
1462 | 1578 |
! |
1579 |
||
1600 | 1580 |
primSocketLocalPort:aSocket |
1581 |
^ port |
|
1582 |
! |
|
1583 |
||
1584 |
sendData: aStringOrByteArray |
|
1585 |
"Send all of the data in the given array, even if it requires multiple calls to send it all. |
|
1586 |
Return the number of bytes sent." |
|
1587 |
||
1588 |
"An experimental version use on slow lines: Longer timeout and smaller writes to try to avoid spurious timeouts." |
|
1589 |
||
1590 |
|remaining nWritten| |
|
1591 |
||
1592 |
Transcript show:'>> '; showCR:aStringOrByteArray. |
|
1593 |
||
1594 |
remaining := aStringOrByteArray size. |
|
1595 |
[remaining > 0] whileTrue:[ |
|
1596 |
nWritten := self nextPutBytes:remaining from:aStringOrByteArray startingAt:1. |
|
1597 |
remaining := remaining - nWritten. |
|
1598 |
]. |
|
1599 |
^ aStringOrByteArray size. |
|
1600 |
||
1601 |
"/ | bytesSent bytesToSend count | |
|
1602 |
"/ bytesToSend := aStringOrByteArray size. |
|
1603 |
"/ bytesSent := 0. |
|
1604 |
"/ [bytesSent < bytesToSend] whileTrue: [ |
|
1605 |
"/ (self waitForSendDoneFor: 60) |
|
1606 |
"/ ifFalse: [ConnectionTimedOut signal: 'send data timeout; data not sent']. |
|
1607 |
"/ count := self primSocket: socketHandle |
|
1608 |
"/ sendData: aStringOrByteArray |
|
1609 |
"/ startIndex: bytesSent + 1 |
|
1610 |
"/ count: (bytesToSend - bytesSent min: 5000). |
|
1611 |
"/ bytesSent := bytesSent + count]. |
|
1612 |
"/ |
|
1613 |
"/ ^ bytesSent |
|
1614 |
! |
|
1615 |
||
1462 | 1616 |
setOption: optionName value: optionValue |
1617 |
optionName = 'TCP_NODELAY' ifTrue:[ |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1618 |
^ self setTCPNoDelay:optionValue |
1462 | 1619 |
]. |
1620 |
self error:'unimplemented socketoption' mayProceed:true |
|
1621 |
! |
|
1622 |
||
1600 | 1623 |
socketHandle |
1624 |
^ self |
|
1625 |
! |
|
1626 |
||
1462 | 1627 |
waitForConnectionUntil:aMillisecondClockValue |
1505 | 1628 |
self shouldImplement. |
771 | 1629 |
! ! |
1630 |
||
1576
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1631 |
!Socket methodsFor:'closing'! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1632 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1633 |
shutDown |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1634 |
"shutDown and close the socket" |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1635 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1636 |
self shutdown:2. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1637 |
self close |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1638 |
! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1639 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1640 |
shutDownInput |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1641 |
"shutDown the input side of the socket. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1642 |
Any read on the socket will signal end-of-file from now on. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1643 |
The other side MAY be informed, that no more data will be accepted |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1644 |
(e.g. setting the TCP-Windowsize to 0)" |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1645 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1646 |
self shutdown:0. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1647 |
! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1648 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1649 |
shutDownOutput |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1650 |
"shutDown the output side of the socket. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1651 |
Any write to the socket will signal end-of-file from now on. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1652 |
The other side will get a end-of-file condition, |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1653 |
after the last buffered data has been read" |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1654 |
|
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1655 |
self shutdown:0. |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1656 |
! ! |
a2ffb22c5f5e
New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents:
1568
diff
changeset
|
1657 |
|
126 | 1658 |
!Socket methodsFor:'datagram transmission'! |
28 | 1659 |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1660 |
receiveBuffer:aDataBuffer start:startIndex for:nBytes |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1661 |
"receive data |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1662 |
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
|
1663 |
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
|
1664 |
instance variable. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1665 |
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
|
1666 |
receiving, using #readWait or #readWaitWithTimeout:." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1667 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1668 |
|nReceived| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1669 |
|
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 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1672 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1673 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1674 |
if (fp != nil) { |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1675 |
SOCKET sock; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1676 |
int objSize, offs; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1677 |
int n; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1678 |
char *extPtr; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1679 |
unsigned char *buffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1680 |
unsigned char *allocatedBuffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1681 |
int flags = 0; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1682 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1683 |
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
|
1684 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1685 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
1343 | 1686 |
if (__isSmallInteger(nBytes)) { |
1687 |
if (__intVal(nBytes) < objSize) { |
|
1688 |
objSize = __intVal(nBytes); |
|
1689 |
} |
|
1690 |
} |
|
1691 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1692 |
# ifdef DO_WRAP_CALLS |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1693 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1694 |
buffer = extPtr + offs; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1695 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1696 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1697 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1698 |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1699 |
do { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1700 |
__threadErrno = 0; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1701 |
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
|
1702 |
} 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
|
1703 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1704 |
if (allocatedBuffer) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1705 |
if (n > 0) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1706 |
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
|
1707 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1708 |
free(allocatedBuffer); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1709 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1710 |
# else |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1711 |
__BEGIN_INTERRUPTABLE__ |
1343 | 1712 |
do { |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1713 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1714 |
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
|
1715 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1716 |
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
|
1717 |
} |
1343 | 1718 |
} while ((n < 0) && (errno == EINTR)); |
1719 |
__END_INTERRUPTABLE__ |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1720 |
# endif |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1721 |
|
1343 | 1722 |
if (n < 0) { |
1723 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1724 |
} |
|
1725 |
nReceived = __MKSMALLINT(n); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1726 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1727 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1728 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1729 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1730 |
nReceived notNil ifTrue:[ |
1343 | 1731 |
nReceived < 0 ifTrue:[ |
1732 |
'Socket [warning]: ' infoPrint. |
|
1733 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
|
1734 |
]. |
|
1735 |
^ nReceived |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1736 |
]. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1737 |
" |
1282 | 1738 |
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
|
1739 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1740 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1741 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1742 |
|
126 | 1743 |
receiveFrom:anAddressBuffer buffer:aDataBuffer |
1744 |
"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
|
1745 |
anAddressBuffer, data into aBuffer. |
126 | 1746 |
Both must be ByteArray-like. The addressBuffer must |
1747 |
provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
1748 |
Return the number of bytes received, or a negative number on error. |
|
1749 |
On error, the unix error code is left in the lastErrorNumber |
|
1750 |
instance variable." |
|
28 | 1751 |
|
126 | 1752 |
^ 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
|
1753 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
1754 |
|
126 | 1755 |
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
|
1756 |
"receive datagramm data |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1757 |
- 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
|
1758 |
For backward compatibility, the addressBuffer may be a non-SocketAddress; |
1282 | 1759 |
then, it must be a byteArray with appropriate size for the addressBytes. |
1760 |
||
126 | 1761 |
Return the number of bytes received, or a negative number on error. |
1762 |
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
|
1763 |
instance variable. |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1764 |
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
|
1765 |
receiving, using #readWait or #readWaitWithTimeout:." |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1766 |
|
1282 | 1767 |
|domainClass addr addrLen nReceived| |
1768 |
||
1769 |
domainClass := self class socketAddressClassForDomain:domain. |
|
1770 |
domainClass isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1771 |
^ self error:'invalid (unsupported) domain'. |
1282 | 1772 |
]. |
1773 |
(anAddressBuffer isKindOf:SocketAddress) ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1774 |
anAddressBuffer class == domainClass ifFalse:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1775 |
^ self error:'addressBuffer class mismatch (domain)'. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1776 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1777 |
addr := anAddressBuffer. |
1282 | 1778 |
] ifFalse:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1779 |
anAddressBuffer notNil ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1780 |
addr := domainClass new. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1781 |
]. |
1282 | 1782 |
]. |
1783 |
||
126 | 1784 |
%{ |
418 | 1785 |
#ifndef NO_SOCKET |
217 | 1786 |
OBJ fp = __INST(filePointer); |
126 | 1787 |
|
1788 |
if (fp != nil) { |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1789 |
SOCKET sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1790 |
int objSize; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1791 |
union sockaddr_u sa; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1792 |
unsigned int alen = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1793 |
int n, offs; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1794 |
int flags = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1795 |
char *extPtr; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1796 |
unsigned char *allocatedBuffer = NULL; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1797 |
unsigned char *buffer = NULL; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1798 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1799 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1800 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1801 |
if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1802 |
if (__isSmallInteger(nBytes)) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1803 |
if (__intVal(nBytes) < objSize) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1804 |
objSize = __intVal(nBytes); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1805 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1806 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1807 |
# ifdef DO_WRAP_CALLS |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1808 |
if (extPtr) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1809 |
buffer = extPtr + offs; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1810 |
} else { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1811 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1812 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1813 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1814 |
do { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1815 |
__threadErrno = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1816 |
alen = sizeof(sa); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1817 |
n = STX_WSA_CALL6("recvfrom", recvfrom, sock, buffer, objSize, flags, (struct sockaddr *)&sa, &alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1818 |
} while ((n < 0) && (__threadErrno == EINTR)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1819 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1820 |
if (allocatedBuffer) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1821 |
if (n > 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1822 |
bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1823 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1824 |
free(allocatedBuffer); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1825 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1826 |
# else |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1827 |
__BEGIN_INTERRUPTABLE__ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1828 |
do { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1829 |
alen = sizeof(sa); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1830 |
if (extPtr) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1831 |
n = recvfrom(sock, extPtr + offs, objSize, flags, (struct sockaddr *) &sa, &alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1832 |
} else { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1833 |
n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags, (struct sockaddr *) &sa, &alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1834 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1835 |
} while ((n < 0) && (errno == EINTR)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1836 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1837 |
# endif |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1838 |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1839 |
if (n >= 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1840 |
if (__isNonNilObject(addr)) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1841 |
char *addrPtr; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1842 |
OBJ oClass; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1843 |
int nInstVars, nInstBytes, objSize; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1844 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1845 |
oClass = __qClass(addr); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1846 |
if (! __isBytes(addr) ) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1847 |
goto bad; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1848 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1849 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1850 |
objSize = __qSize(addr) - nInstBytes; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1851 |
addrPtr = (char *)__InstPtr(addr) + nInstBytes; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1852 |
if (objSize < alen) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1853 |
goto bad; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1854 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1855 |
/* |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1856 |
* extract the datagrams address |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1857 |
*/ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1858 |
bcopy((char *)&sa, addrPtr, alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1859 |
addrLen = __MKSMALLINT(alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1860 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1861 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1862 |
if (n < 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1863 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1864 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1865 |
nReceived = __MKSMALLINT(n); |
126 | 1866 |
} |
418 | 1867 |
#endif |
126 | 1868 |
bad: ; |
1869 |
%}. |
|
1870 |
nReceived notNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1871 |
nReceived < 0 ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1872 |
'Socket [warning]: ' infoPrint. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1873 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1874 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1875 |
addrLen notNil ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1876 |
(addr == anAddressBuffer) ifFalse:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1877 |
self obsoleteFeatureWarning:'please use a socketAddress argument'. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1878 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1879 |
" can be a ByteArray for backward compatibility " |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1880 |
anAddressBuffer replaceFrom:1 to:addrLen with:(addr hostAddress). |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1881 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1882 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
1883 |
^ nReceived |
28 | 1884 |
]. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1885 |
" |
126 | 1886 |
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
|
1887 |
(i.e. not ByteArray-like), |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1888 |
or if the addressBuffer is nonNil AND not a SocketAddress/ByteArray |
126 | 1889 |
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
|
1890 |
" |
126 | 1891 |
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
|
1892 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1893 |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1894 |
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
|
1895 |
"send data. |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1896 |
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
|
1897 |
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
|
1898 |
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
|
1899 |
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
|
1900 |
instance variable." |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1901 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1902 |
|nReceived portNo| |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1903 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1904 |
%{ |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1905 |
#ifndef NO_SOCKET |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1906 |
OBJ fp = __INST(filePointer); |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1907 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1908 |
if ((fp != nil) |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1909 |
&& __isSmallInteger(startIndex) |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1910 |
&& __isSmallInteger(nBytes)) { |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1911 |
SOCKET sock; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1912 |
int objSize; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1913 |
int n; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1914 |
char *extPtr; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1915 |
int _flags = 0; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1916 |
int offs; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1917 |
unsigned long norder; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1918 |
unsigned char *buffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1919 |
unsigned char *allocatedBuffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1920 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1921 |
_flags = __longIntVal(flags); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1922 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1923 |
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
|
1924 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1925 |
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
|
1926 |
if (__isSmallInteger(nBytes)) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1927 |
if (__intVal(nBytes) < objSize) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1928 |
objSize = __intVal(nBytes); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1929 |
} |
1343 | 1930 |
} |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1931 |
|
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1932 |
# ifdef DGRAM_DEBUG |
1343 | 1933 |
printf("sending %d bytes ...\n", nBytes); |
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1934 |
# endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1935 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1936 |
#ifdef DO_WRAP_CALLS |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1937 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1938 |
buffer = extPtr + offs; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1939 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1940 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1941 |
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
|
1942 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1943 |
|
1343 | 1944 |
do { |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1945 |
__threadErrno = 0; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
1946 |
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
|
1947 |
} 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
|
1948 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1949 |
if (allocatedBuffer) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1950 |
free(allocatedBuffer); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1951 |
} |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1952 |
#else |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
1953 |
__BEGIN_INTERRUPTABLE__ |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1954 |
do { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1955 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1956 |
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
|
1957 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1958 |
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
|
1959 |
} |
1343 | 1960 |
} while ((n < 0) && (errno == EINTR)); |
1961 |
__END_INTERRUPTABLE__ |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1962 |
#endif |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
1963 |
|
1343 | 1964 |
if (n < 0) { |
1965 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1966 |
} |
|
1967 |
RETURN (__MKSMALLINT(n)); |
|
915
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1968 |
} |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1969 |
#endif |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1970 |
bad: ; |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1971 |
%}. |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1972 |
" |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1973 |
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
|
1974 |
" |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1975 |
self primitiveFailed |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1976 |
! |
3dc0e3cd838a
added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1977 |
|
126 | 1978 |
sendTo:anAddressBuffer buffer:buffer |
1979 |
"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
|
1980 |
anAddressBuffer, data from aDataBuffer. |
126 | 1981 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
1982 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
1983 |
Return the number of bytes transmitted, or a negative number on error. |
|
1984 |
On error, the unix error code is left in the lastErrorNumber |
|
1985 |
instance variable. |
|
1986 |
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
|
1987 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
1988 |
^ 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
|
1989 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1990 |
|
817 | 1991 |
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count |
1992 |
"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
|
1993 |
anAddressBuffer, data from aDataBuffer. |
817 | 1994 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
1995 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
1996 |
Return the number of bytes transmitted, or a negative number on error. |
|
1997 |
On error, the unix error code is left in the lastErrorNumber |
|
1998 |
instance variable. |
|
1999 |
Flags is currently ignored; it is there for ST-80 compatibility." |
|
2000 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2001 |
^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 |
817 | 2002 |
! |
2003 |
||
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2004 |
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:flags |
126 | 2005 |
"send datagramm data - fetch address of destination host from |
2006 |
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
|
2007 |
sending count bytes. |
126 | 2008 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
2009 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2010 |
Return the number of bytes transmitted, or a negative number on error. |
|
2011 |
On error, the unix error code is left in the lastErrorNumber |
|
2012 |
instance variable." |
|
0 | 2013 |
|
1282 | 2014 |
|domainClass addr| |
2015 |
||
2016 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2017 |
domainClass isNil ifTrue:[ |
|
1343 | 2018 |
^ self error:'invalid (unsupported) domain'. |
1282 | 2019 |
]. |
2020 |
||
2021 |
(anAddressBuffer isKindOf:SocketAddress) ifTrue:[ |
|
1343 | 2022 |
addr := anAddressBuffer. |
1282 | 2023 |
] ifFalse:[ |
1343 | 2024 |
anAddressBuffer isByteArray ifFalse:[ |
2025 |
^ self error:'bad socketAddress argument' |
|
2026 |
]. |
|
2027 |
addr := domainClass hostAddress:anAddressBuffer. |
|
28 | 2028 |
]. |
0 | 2029 |
%{ |
418 | 2030 |
#ifndef NO_SOCKET |
217 | 2031 |
OBJ fp = __INST(filePointer); |
21 | 2032 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2033 |
if ((fp != nil) |
126 | 2034 |
&& __isSmallInteger(startIndex) |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2035 |
&& __isSmallInteger(nBytes)) { |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2036 |
SOCKET sock; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2037 |
int objSize; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2038 |
struct sockaddr *sockaddr_ptr; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2039 |
union sockaddr_u sa; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2040 |
int alen = 0; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2041 |
int sockAddrOffs, sockaddr_size; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2042 |
int n; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2043 |
char *extPtr; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2044 |
int _flags = 0; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2045 |
int offs; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2046 |
unsigned long norder; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2047 |
unsigned char *buffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2048 |
unsigned char *allocatedBuffer; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2049 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2050 |
_flags = __longIntVal(flags); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2051 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
1343 | 2052 |
|
2053 |
if (! __isBytes(addr)) { |
|
2054 |
sockaddr_size = 0; |
|
2055 |
sockaddr_ptr = (struct sockaddr *)0; |
|
2056 |
} else { |
|
2057 |
int nIndex; |
|
2058 |
OBJ cls; |
|
2059 |
||
2060 |
sockAddrOffs = 0; |
|
2061 |
if ((cls = __qClass(addr)) != @global(ByteArray)) |
|
2062 |
sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2063 |
nIndex = __qSize(addr) - OHDR_SIZE; |
|
2064 |
sockaddr_size = nIndex - sockAddrOffs; |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2065 |
if (sockaddr_size > sizeof(sa)) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2066 |
fprintf(stderr, "bad socketAddr\n"); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2067 |
goto bad; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2068 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2069 |
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
|
2070 |
sockaddr_ptr = (struct sockaddr *)(&sa); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2071 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2072 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2073 |
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
|
2074 |
if (__isSmallInteger(nBytes)) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2075 |
if (__intVal(nBytes) < objSize) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2076 |
objSize = __intVal(nBytes); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2077 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2078 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2079 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2080 |
#ifdef DO_WRAP_CALLS |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2081 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2082 |
buffer = extPtr + offs; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2083 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2084 |
allocatedBuffer = buffer = (char *)malloc(objSize); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2085 |
bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize); |
1343 | 2086 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2087 |
|
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2088 |
do { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2089 |
__threadErrno = 0; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2090 |
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
|
2091 |
} 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
|
2092 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2093 |
if (allocatedBuffer) { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2094 |
free(allocatedBuffer); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2095 |
} |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2096 |
#else |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2097 |
__BEGIN_INTERRUPTABLE__ |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2098 |
do { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2099 |
if (extPtr) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2100 |
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
|
2101 |
} else { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2102 |
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
|
2103 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2104 |
} while ((n < 0) && (errno == EINTR)); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2105 |
__END_INTERRUPTABLE__ |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2106 |
#endif |
1343 | 2107 |
|
2108 |
if (n < 0) { |
|
2109 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2110 |
} |
|
2111 |
RETURN (__MKSMALLINT(n)); |
|
0 | 2112 |
} |
418 | 2113 |
#endif |
126 | 2114 |
bad: ; |
42 | 2115 |
%}. |
2116 |
" |
|
126 | 2117 |
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
|
2118 |
(i.e. not ByteArray-like), |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2119 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
126 | 2120 |
or if the addressBuffer is nonNil AND too small. |
42 | 2121 |
" |
126 | 2122 |
self primitiveFailed |
0 | 2123 |
! ! |
2124 |
||
2125 |
!Socket methodsFor:'low level'! |
|
2126 |
||
507 | 2127 |
bindAnonymously |
1505 | 2128 |
"bind to any address. A free port will be allocated. |
2129 |
Our own socket address will be determined after conection set up. |
|
2130 |
This is the default after the socket has been created" |
|
2131 |
||
507 | 2132 |
^ self |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2133 |
bindTo:nil |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2134 |
address:nil |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2135 |
reuseAddress:false |
509 | 2136 |
! |
2137 |
||
2138 |
bindAnonymouslyToAddress:addressString |
|
1505 | 2139 |
"bind to address addressString. |
2140 |
A free port will be allocated" |
|
2141 |
||
509 | 2142 |
^ self |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2143 |
bindTo:nil |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2144 |
address:addressString |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2145 |
reuseAddress:false |
507 | 2146 |
! |
2147 |
||
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2148 |
bindTo:aSocketAddress |
425 | 2149 |
"ST80 compatible bind, expecting a socketAddress argument. |
2150 |
The socketAddress object (an instance of SocketAddress) |
|
2151 |
is supposed to respond to #portOrName and #address requests." |
|
71 | 2152 |
|
2153 |
^ self bindTo:(aSocketAddress portOrName) |
|
2154 |
address:(aSocketAddress address) |
|
425 | 2155 |
reuseAddress:true |
71 | 2156 |
! |
2157 |
||
425 | 2158 |
bindTo:portNrOrNameString address:addressString |
28 | 2159 |
"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
|
2160 |
Currently only non-address binding is supported; |
425 | 2161 |
i.e. the address must always be nil. |
71 | 2162 |
|
2163 |
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
|
2164 |
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
|
2165 |
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
|
2166 |
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
|
2167 |
" |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2168 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2169 |
^ self |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2170 |
bindTo:portNrOrNameString |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2171 |
address:addressString |
425 | 2172 |
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
|
2173 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2174 |
|
1282 | 2175 |
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
|
2176 |
"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
|
2177 |
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
|
2178 |
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
|
2179 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2180 |
The interpretation of portNrOrName depends on the domain: |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2181 |
inet domain uses (4byte) byteArray like internet numbers, |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2182 |
unix domain uses pathname strings, |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2183 |
others use whatever will come up in the future |
425 | 2184 |
|
2185 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
2186 |
is to be set (to avoid the 'bind: address in use' error). |
|
2187 |
" |
|
28 | 2188 |
|
1282 | 2189 |
|ok addr addrName domainClass| |
2190 |
||
28 | 2191 |
filePointer isNil ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2192 |
^ self errorNotOpen |
1282 | 2193 |
]. |
2194 |
||
2195 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2196 |
domainClass isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2197 |
^ self error:'invalid (unsupported) domain'. |
28 | 2198 |
]. |
1282 | 2199 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2200 |
" backward compatibility: support for byteArray and string arg " |
1282 | 2201 |
|
2202 |
hostOrPathNameOrSocketAddrOrNil isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2203 |
addr := domainClass anyHost. |
1282 | 2204 |
] ifFalse:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2205 |
hostOrPathNameOrSocketAddrOrNil isString ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2206 |
addr := domainClass hostName:hostOrPathNameOrSocketAddrOrNil. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2207 |
addrName := hostOrPathNameOrSocketAddrOrNil. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2208 |
] ifFalse:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2209 |
(hostOrPathNameOrSocketAddrOrNil isKindOf:SocketAddress) ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2210 |
addr := hostOrPathNameOrSocketAddrOrNil. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2211 |
] ifFalse:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2212 |
hostOrPathNameOrSocketAddrOrNil isByteArray ifFalse:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2213 |
^ self error:'bad host (socketAddress) argument' |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2214 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2215 |
addr := domainClass hostAddress:hostOrPathNameOrSocketAddrOrNil. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2216 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2217 |
]. |
1282 | 2218 |
]. |
2219 |
portNrOrNameOrNil notNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2220 |
addr port:portNrOrNameOrNil. |
1282 | 2221 |
]. |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2222 |
(portNrOrNameOrNil isNil or:[portNrOrNameOrNil == 0]) ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2223 |
addr := addr copy. |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
2224 |
]. |
1282 | 2225 |
|
1120 | 2226 |
%{ /* STACK: 100000 */ |
418 | 2227 |
#ifndef NO_SOCKET |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2228 |
OBJ fp = __INST(filePointer); |
1282 | 2229 |
|
2230 |
if (! __isBytes(addr)) { |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2231 |
addr = nil; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2232 |
fprintf(stderr, "Socket: bad sddr\n"); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2233 |
RETURN (false); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2234 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2235 |
if (fp != nil) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2236 |
SOCKET sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2237 |
union sockaddr_u sa; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2238 |
int sockaddr_size; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2239 |
int ret; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2240 |
int sockAddrOffs; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2241 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2242 |
{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2243 |
int nIndex; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2244 |
OBJ cls; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2245 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2246 |
sockAddrOffs = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2247 |
if ((cls = __qClass(addr)) != @global(ByteArray)) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2248 |
sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2249 |
nIndex = __qSize(addr) - OHDR_SIZE; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2250 |
sockaddr_size = nIndex - sockAddrOffs; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2251 |
if (sockaddr_size > sizeof(sa)) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2252 |
fprintf(stderr, "Socket: bad socketAddr\n"); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2253 |
RETURN (false); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2254 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2255 |
bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2256 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2257 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2258 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
28 | 2259 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2260 |
# ifdef SO_REUSEADDR |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2261 |
if (reuse == true) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2262 |
int on = 1; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2263 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2264 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2265 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2266 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2267 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2268 |
# endif /* SO_REUSEADDR */ |
28 | 2269 |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2270 |
# ifdef BIND_BLOCKS |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2271 |
# ifdef DO_WRAP_CALLS |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2272 |
do { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2273 |
__threadErrno = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2274 |
ret = STX_WSA_CALL3("bind", bind, sock, &sa, sockaddr_size); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2275 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2276 |
# else |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2277 |
__BEGIN_INTERRUPTABLE__ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2278 |
do { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2279 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2280 |
} while ((ret < 0) && (errno == EINTR)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2281 |
__END_INTERRUPTABLE__ |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2282 |
# endif |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2283 |
# else |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2284 |
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
|
2285 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2286 |
if (ret < 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2287 |
DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2288 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2289 |
RETURN (false); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2290 |
} else { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2291 |
ok = true; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2292 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2293 |
if (! __isSmallInteger(portNrOrNameOrNil) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2294 |
|| (portNrOrNameOrNil == __MKSMALLINT(0))) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2295 |
unsigned int alen = sockaddr_size; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2296 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2297 |
/* |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2298 |
* anonymous port - get the actual portNr |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2299 |
*/ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2300 |
if (getsockname(sock, (struct sockaddr *)&sa, &alen) < 0) { |
1536 | 2301 |
# ifdef WIN32 |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2302 |
errno = WSAGetLastError(); |
1536 | 2303 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2304 |
fprintf(stderr, "SOCKET: cannot get socketname: %d\n", errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2305 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2306 |
bcopy(&sa, (__byteArrayVal(addr) + sockAddrOffs), alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2307 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2308 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2309 |
} |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2310 |
#endif /* NO_SOCKET */ |
1282 | 2311 |
|
2312 |
getOutOfHere: ; |
|
42 | 2313 |
%}. |
1282 | 2314 |
ok ~~ true ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2315 |
^ false |
1282 | 2316 |
]. |
2317 |
||
2318 |
peer := addr. |
|
2319 |
port := addr port. |
|
2320 |
peerName := addrName. |
|
2321 |
||
28 | 2322 |
^ true |
0 | 2323 |
|
28 | 2324 |
" |
2325 |
(Socket domain:#inet type:#stream) |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2326 |
bindTo:9999 |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2327 |
address:nil |
28 | 2328 |
" |
1474 | 2329 |
! ! |
2330 |
||
2331 |
!Socket protectedMethodsFor:'low level'! |
|
0 | 2332 |
|
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2333 |
closeFile |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2334 |
"low level close" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2335 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2336 |
%{ /* NOCONTEXT */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2337 |
#ifndef NO_SOCKET |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2338 |
OBJ t; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2339 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2340 |
t = __INST(filePointer); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2341 |
if (t != nil) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2342 |
FILE *fp; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2343 |
SOCKET sock; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2344 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2345 |
__INST(filePointer) = nil; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2346 |
fp = __FILEVal(t); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2347 |
sock = SOCKET_FROM_FILE(fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2348 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2349 |
# ifdef xxDO_WRAP_CALLS |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2350 |
{ int ret; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2351 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2352 |
do { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2353 |
__threadErrno = 0; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2354 |
ret = STX_C_CALL1("fclose", fclose, fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2355 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2356 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2357 |
# ifdef WIN32 |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2358 |
do { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2359 |
__threadErrno = 0; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2360 |
ret = STX_WSA_CALL1("closesocket", closesocket, sock); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2361 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2362 |
closesocket(sock); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2363 |
# endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2364 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2365 |
# else /* !DO_WRAP_CALLS */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2366 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2367 |
DBGFPRINTF((stderr, "SOCKET: fflush %x (%d)\n", fp, fileno(fp))); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2368 |
fflush(fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2369 |
/* shutdown(fileno(fp), 2); */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2370 |
# ifdef xxWIN32 |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2371 |
closesocket(sock); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2372 |
# endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2373 |
DBGFPRINTF((stderr, "SOCKET: fclose %x (%d)\n", fp, sock)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2374 |
if (@global(FileOpenTrace) == true) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2375 |
fprintf(stderr, "fclose [Socket] %x\n", fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2376 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2377 |
fclose(fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2378 |
# ifdef WIN32 |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2379 |
DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2380 |
closesocket(sock); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2381 |
# endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2382 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2383 |
# endif /* !DO_WRAP_CALLS */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2384 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2385 |
#endif /* NO_SOCKET */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2386 |
%} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2387 |
! ! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2388 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2389 |
!Socket methodsFor:'low level'! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2390 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2391 |
getSocketError |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2392 |
"get the SO_ERROR form the socket, which indicates the |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2393 |
result of an asynchronous operation" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2394 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2395 |
%{ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2396 |
#ifndef NO_SOCKET |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2397 |
OBJ fp; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2398 |
int err; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2399 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2400 |
fp = __INST(filePointer); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2401 |
if (fp == nil) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2402 |
err = EBADF; |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2403 |
} else { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2404 |
unsigned int sz; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2405 |
SOCKET sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2406 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2407 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2408 |
sz = sizeof(err); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2409 |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) { |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2410 |
# ifdef WIN32 |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2411 |
errno = WSAGetLastError(); |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2412 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2413 |
err = errno; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2414 |
} |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2415 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2416 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2417 |
RETURN(__MKSMALLINT(err)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2418 |
#endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2419 |
%} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2420 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2421 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2422 |
listenFor:aNumber |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2423 |
"same as listenWithBacklog: - for ST-80 compatibility" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2424 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2425 |
^ self listenWithBacklog:aNumber |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2426 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2427 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2428 |
listenWithBacklog:aNumber |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2429 |
"start listening; return true if ok, false on error" |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2430 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2431 |
filePointer isNil ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2432 |
^ self errorNotOpen |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2433 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2434 |
%{ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2435 |
#ifndef NO_SOCKET |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2436 |
OBJ fp = __INST(filePointer); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2437 |
SOCKET sock; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2438 |
int ret; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2439 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2440 |
if (! __isSmallInteger(aNumber)) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2441 |
DBGPRINTF(("SOCKET: invalid arg\n")); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2442 |
RETURN (false); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2443 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2444 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2445 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2446 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2447 |
#ifdef LISTEN_BLOCKS |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2448 |
# ifdef DO_WRAP_CALLS |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2449 |
do { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2450 |
__threadErrno = 0; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2451 |
ret = STX_WSA_CALL2("listen", listen, sock, __intVal(aNumber)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2452 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2453 |
# else |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2454 |
__BEGIN_INTERRUPTABLE__ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2455 |
do { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2456 |
ret = listen(sock, __intVal(aNumber)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2457 |
} while ((ret < 0) && (errno == EINTR)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2458 |
__END_INTERRUPTABLE__ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2459 |
# endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2460 |
#else |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2461 |
ret = listen(sock, __intVal(aNumber)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2462 |
#endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2463 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2464 |
if (ret < 0) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2465 |
DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2466 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2467 |
RETURN (false); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2468 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2469 |
#else |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2470 |
RETURN (false); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2471 |
#endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2472 |
%}. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2473 |
listening := true. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2474 |
^ true |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2475 |
! ! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2476 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2477 |
!Socket protectedMethodsFor:'low level'! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2478 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2479 |
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
|
2480 |
|ok| |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2481 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2482 |
%{ /* STACK: 32000 */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2483 |
OBJ fp = __INST(filePointer); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2484 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2485 |
if (fp != nil) { |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2486 |
SOCKET sock; |
1532 | 2487 |
int opt = -1; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2488 |
int level = -1; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2489 |
int usize = -1; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2490 |
int ret; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2491 |
union u { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2492 |
BOOL u_bool; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2493 |
int u_int; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2494 |
struct linger u_linger; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2495 |
} u; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2496 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2497 |
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
|
2498 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2499 |
# ifdef SO_BROADCAST |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2500 |
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
|
2501 |
/* Enables transmission and receipt of broadcast messages on the socket. */ |
1532 | 2502 |
opt = SO_BROADCAST; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2503 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2504 |
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
|
2505 |
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
|
2506 |
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
|
2507 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2508 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2509 |
# endif /* SO_BROADCAST */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2510 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2511 |
# ifdef SO_CONDITIONAL |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2512 |
# if 0 |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2513 |
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
|
2514 |
/* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */ |
1532 | 2515 |
opt = SO_CONDITIONAL; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2516 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2517 |
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
|
2518 |
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
|
2519 |
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
|
2520 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2521 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2522 |
# endif |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2523 |
# endif /* SO_CONDITIONAL */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2524 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2525 |
# ifdef SO_DEBUG |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2526 |
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
|
2527 |
/* Records debugging information. */ |
1532 | 2528 |
opt = SO_DEBUG; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2529 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2530 |
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
|
2531 |
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
|
2532 |
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
|
2533 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2534 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2535 |
# endif /* SO_DEBUG */ |
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 |
# ifdef SO_DONTLINGER |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2538 |
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
|
2539 |
/* 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
|
2540 |
Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */ |
1532 | 2541 |
opt = SO_DONTLINGER; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2542 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2543 |
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
|
2544 |
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
|
2545 |
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
|
2546 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2547 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2548 |
# endif /* SO_DONTLINGER */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2549 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2550 |
# ifdef SO_DONTROUTE |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2551 |
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
|
2552 |
/* 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
|
2553 |
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
|
2554 |
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
|
2555 |
Not supported on ATM sockets (results in an error). */ |
1532 | 2556 |
opt = SO_DONTROUTE; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2557 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2558 |
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
|
2559 |
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
|
2560 |
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
|
2561 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2562 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2563 |
# endif /* SO_DONTROUTE */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2564 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2565 |
# ifdef SO_KEEPALIVE |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2566 |
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
|
2567 |
/* Sends keep-alives. Not supported on ATM sockets (results in an error). */ |
1532 | 2568 |
opt = SO_KEEPALIVE; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2569 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2570 |
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
|
2571 |
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
|
2572 |
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
|
2573 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2574 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2575 |
# endif /* SO_KEEPALIVE */ |
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 SO_LINGER |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2578 |
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
|
2579 |
/* Lingers on close if unsent data is present. */ |
1532 | 2580 |
opt = SO_LINGER; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2581 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2582 |
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
|
2583 |
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
|
2584 |
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
|
2585 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2586 |
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
|
2587 |
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
|
2588 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2589 |
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
|
2590 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2591 |
# endif /* SO_LINGER */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2592 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2593 |
# ifdef SO_OOBINLINE |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2594 |
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
|
2595 |
/* Receives OOB data in the normal data stream. */ |
1532 | 2596 |
opt = SO_OOBINLINE; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2597 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2598 |
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
|
2599 |
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
|
2600 |
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
|
2601 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2602 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2603 |
# endif /* SO_OOBINLINE */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2604 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2605 |
# ifdef SO_RCVBUF |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2606 |
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
|
2607 |
/* 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
|
2608 |
This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */ |
1532 | 2609 |
opt = SO_RCVBUF; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2610 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2611 |
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
|
2612 |
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
|
2613 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2614 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2615 |
# endif /* SO_RCVBUF */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2616 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2617 |
# ifdef SO_SNDBUF |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2618 |
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
|
2619 |
/* 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
|
2620 |
This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */ |
1532 | 2621 |
opt = SO_SNDBUF; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2622 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2623 |
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
|
2624 |
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
|
2625 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2626 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2627 |
# endif /* SO_SNDBUF */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2628 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2629 |
# ifdef SO_REUSEADDR |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2630 |
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
|
2631 |
/* Allows the socket to be bound to an address that is already in use. */ |
1532 | 2632 |
opt = SO_REUSEADDR; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2633 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2634 |
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
|
2635 |
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
|
2636 |
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
|
2637 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2638 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2639 |
# endif /* SO_OOBINLINE */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2640 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2641 |
# ifdef SO_EXCLUSIVEADDRUSE |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2642 |
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
|
2643 |
/* 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
|
2644 |
Does not require administrative privilege. */ |
1532 | 2645 |
opt = SO_EXCLUSIVEADDRUSE; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2646 |
level = SOL_SOCKET; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2647 |
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
|
2648 |
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
|
2649 |
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
|
2650 |
else goto argError; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2651 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2652 |
# endif /* SO_OOBINLINE */ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2653 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2654 |
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
|
2655 |
|
1533 | 2656 |
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
|
2657 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2658 |
argError: ; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2659 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2660 |
%}. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2661 |
ok isNil ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2662 |
self primitiveFailed |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2663 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2664 |
ok ifFalse:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2665 |
'setsocketoption failed' infoPrintCR. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2666 |
]. |
1474 | 2667 |
! ! |
2668 |
||
2669 |
!Socket methodsFor:'low level'! |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2670 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2671 |
shutdown: howNum |
1339 | 2672 |
"shutDown the socket - inform it that no more I/O will be performed. |
1343 | 2673 |
0 - read side (no further reads) |
2674 |
1 - write side (no further writes) |
|
2675 |
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
|
2676 |
shutDown:2 |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2677 |
discards any pending data |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2678 |
(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
|
2679 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2680 |
%{ |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2681 |
#ifndef NO_SOCKET |
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 |
OBJ fp; |
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 |
fp = __INST(filePointer); |
1339 | 2686 |
if ((fp != nil) && __isSmallInteger(howNum)) { |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2687 |
SOCKET sock; |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2688 |
int ret; |
1343 | 2689 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2690 |
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
|
2691 |
# ifdef DO_WRAP_CALLS |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2692 |
do { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2693 |
__threadErrno = 0; |
1541 | 2694 |
DBGFPRINTF((stderr, "SOCKET: shutDown...\n")); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2695 |
ret = STX_WSA_CALL2("shutdown", shutdown, sock, __intVal(howNum)); |
1541 | 2696 |
DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno)); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2697 |
} 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
|
2698 |
# else |
1343 | 2699 |
__BEGIN_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2700 |
shutdown(sock, __intVal(howNum)); |
1343 | 2701 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2702 |
# endif |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2703 |
} |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2704 |
#endif |
1339 | 2705 |
%}. |
1505 | 2706 |
! |
2707 |
||
2708 |
tryToBindTo:portNrOrNameOrNil |
|
2709 |
(self bindTo:portNrOrNameOrNil address:nil) ifFalse:[ |
|
2710 |
self close. |
|
2711 |
^ nil |
|
2712 |
]. |
|
2713 |
^ self. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2714 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2715 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2716 |
!Socket methodsFor:'low level-accepting'! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2717 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2718 |
accept |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2719 |
"create a new TCP socket from accepting on the receiver. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2720 |
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
|
2721 |
For ST-80 compatibility" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2722 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2723 |
|newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2724 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2725 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2726 |
^ self waitForNewConnectionWithTimeout:nil |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2727 |
]. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2728 |
newSock := self class new. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2729 |
(newSock acceptOn:self) ifFalse:[^ nil]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2730 |
^ newSock |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2731 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2732 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2733 |
|sock newSock| |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2734 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2735 |
sock := Socket provide:8004. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2736 |
sock listenFor:5. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2737 |
newSock := sock accept. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2738 |
" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2739 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2740 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2741 |
acceptOn:aSocket |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2742 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2743 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2744 |
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
|
2745 |
Return the true if ok; false if not." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2746 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2747 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2748 |
^ 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
|
2749 |
]. |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
2750 |
aSocket readWait. |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2751 |
^ self primAcceptOn:aSocket blocking:false. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2752 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2753 |
"Modified: / 11.3.1996 / 14:21:31 / stefan" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2754 |
"Modified: / 1.8.1998 / 23:39:10 / cg" |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2755 |
! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
2756 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2757 |
blockingAccept |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2758 |
"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
|
2759 |
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
|
2760 |
For ST-80 compatibility" |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2761 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2762 |
|newSock| |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2763 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2764 |
newSock := self class new. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2765 |
(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
|
2766 |
^ newSock |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2767 |
! |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2768 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2769 |
blockingAcceptOn:aSocket |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2770 |
"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
|
2771 |
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
|
2772 |
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
|
2773 |
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
|
2774 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2775 |
^ 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
|
2776 |
! |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2777 |
|
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2778 |
pollingWaitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2779 |
"stupid MSDOS does not support select on sockets (sigh). |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2780 |
Must poll here." |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2781 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2782 |
|millis newConnection| |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2783 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2784 |
millis := timeoutSeconds * 1000. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2785 |
[millis > 0] whileTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2786 |
otherConnections size > 0 ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2787 |
otherConnections do:[:aConnection | |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2788 |
aConnection canReadWithoutBlocking ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2789 |
^ aConnection |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2790 |
] |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2791 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2792 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2793 |
newConnection := self blockingAccept. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2794 |
newConnection notNil ifTrue:[^ newConnection]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2795 |
Delay waitForMilliseconds:20. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2796 |
millis := millis - 20. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2797 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2798 |
^ nil. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2799 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2800 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2801 |
pollingWaitForNewConnectionWithTimeout:timeoutSeconds |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2802 |
"stupid MSDOS does not support select on sockets (sigh). |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2803 |
Must poll here." |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2804 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2805 |
|millis newConnection| |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2806 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2807 |
timeoutSeconds notNil ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2808 |
millis := timeoutSeconds * 1000. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2809 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2810 |
[millis isNil or:[millis > 0]] whileTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2811 |
newConnection := self blockingAccept. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2812 |
newConnection notNil ifTrue:[^ newConnection]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2813 |
Delay waitForMilliseconds:20. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2814 |
millis notNil ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2815 |
millis := millis - 20. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2816 |
] |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2817 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2818 |
^ nil. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2819 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
2820 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2821 |
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
|
2822 |
"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
|
2823 |
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
|
2824 |
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
|
2825 |
|
1560
50c1e959ede8
Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents:
1558
diff
changeset
|
2826 |
|serverSocketFd addr addrLen domainClass| |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2827 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2828 |
filePointer notNil ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2829 |
^ self errorAlreadyOpen |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2830 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2831 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2832 |
domain := aSocket domain. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2833 |
socketType := aSocket type. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2834 |
serverSocketFd := aSocket fileDescriptor. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2835 |
serverSocketFd isNil ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2836 |
^ 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
|
2837 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2838 |
(serverSocketFd isMemberOf:SmallInteger) ifFalse:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2839 |
^ 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
|
2840 |
]. |
1282 | 2841 |
|
2842 |
domainClass := self class socketAddressClassForDomain:domain. |
|
2843 |
domainClass isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2844 |
^ self error:'invalid (unsupported) domain'. |
1282 | 2845 |
]. |
2846 |
addrLen := domainClass socketAddressSize. |
|
2847 |
addr := domainClass new. |
|
2848 |
||
1120 | 2849 |
%{ /* STACK: 100000 */ |
418 | 2850 |
#ifndef NO_SOCKET |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2851 |
FILE *fp; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2852 |
int flags; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
2853 |
SOCKET sock, newSock; |
819 | 2854 |
union sockaddr_u sa; |
1560
50c1e959ede8
Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents:
1558
diff
changeset
|
2855 |
unsigned int alen, alen0; |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2856 |
struct hostent *he ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2857 |
char dotted[20] ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2858 |
|
1282 | 2859 |
if (!__isSmallInteger(addrLen)) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2860 |
DBGPRINTF(("SOCKET: bad addrLen\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2861 |
RETURN (false); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2862 |
} |
1282 | 2863 |
alen0 = __intVal(addrLen); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2864 |
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
|
2865 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2866 |
if (blocking == false) { |
1338
f81ec8de617f
Use fcntl instead of ioctl when setting O_NONBLOCK
Stefan Vogel <sv@exept.de>
parents:
1336
diff
changeset
|
2867 |
# if defined(O_NONBLOCK) && defined(SET_NDELAY) |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2868 |
flags = fcntl(sock, F_GETFL); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2869 |
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
|
2870 |
# endif |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2871 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2872 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2873 |
# ifdef DO_WRAP_CALLS |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2874 |
do { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2875 |
__threadErrno = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2876 |
alen = alen0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2877 |
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
|
2878 |
} 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
|
2879 |
# else |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2880 |
__BEGIN_INTERRUPTABLE__ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2881 |
do { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2882 |
alen = alen0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2883 |
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
|
2884 |
} 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
|
2885 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2886 |
# endif |
1541 | 2887 |
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
|
2888 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2889 |
if (blocking == false) { |
876 | 2890 |
# if defined(O_NDELAY) && defined(SET_NDELAY) |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2891 |
fcntl(sock, F_SETFL, flags); |
876 | 2892 |
# endif |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2893 |
} |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2894 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2895 |
if (newSock < 0) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2896 |
DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2897 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2898 |
RETURN (false); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2899 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2900 |
|
1282 | 2901 |
if (__isNonNilObject(addr)) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2902 |
OBJ oClass; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2903 |
int nInstVars, nInstBytes, objSize; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2904 |
char *cp; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2905 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2906 |
oClass = __qClass(addr); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2907 |
if (! __isBytes(addr) ) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2908 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2909 |
closesocket(newSock); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2910 |
RETURN (false); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2911 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2912 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2913 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2914 |
nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2915 |
objSize = __qSize(addr) - nInstBytes; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2916 |
cp = (char *)__InstPtr(addr) + nInstBytes; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2917 |
if (objSize < alen) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2918 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2919 |
closesocket(newSock); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2920 |
RETURN (false); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2921 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2922 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2923 |
/* |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2924 |
* extract the partners address |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2925 |
*/ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2926 |
bcopy((char *)&sa, cp, alen); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2927 |
addrLen = __MKSMALLINT(alen); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2928 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2929 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2930 |
/* |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2931 |
* 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
|
2932 |
*/ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2933 |
# ifdef WIN32 |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2934 |
{ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2935 |
HANDLE h; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2936 |
int _fd = _open_osfhandle(newSock, 0); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2937 |
fp = fdopen(_fd, "r+"); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2938 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2939 |
# else |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2940 |
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
|
2941 |
# endif |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2942 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2943 |
if (! fp) { |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2944 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2945 |
__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
|
2946 |
# ifdef DO_WRAP_CALLS |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2947 |
{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2948 |
int ret; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2949 |
do { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2950 |
__threadErrno = 0; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2951 |
ret = STX_WSA_CALL1("closesocket", closesocket, newSock); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2952 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2953 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2954 |
# else |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2955 |
closesocket(newSock); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2956 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2957 |
DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2958 |
RETURN (false); |
876 | 2959 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2960 |
|
1035 | 2961 |
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
|
2962 |
# ifdef WIN32 |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2963 |
{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2964 |
HANDLE h; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2965 |
int _fd = fileno(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2966 |
h = (HANDLE)_get_osfhandle(_fd); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2967 |
fprintf(stderr, "fdopen [Socket] -> %x (fd: %d) (H: %x)\n", fp, _fd, h); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2968 |
} |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2969 |
# else |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2970 |
fprintf(stderr, "fdopen [Socket] -> %x (fd: %d)\n", fp, newSock); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
2971 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2972 |
} |
876 | 2973 |
|
2974 |
# ifdef BUGGY_STDIO_LIB |
|
2975 |
setbuf(fp, NULL); |
|
2976 |
__INST(buffered) = false; |
|
2977 |
# endif |
|
2978 |
||
1486 | 2979 |
# if 0 |
2980 |
// The original code was: |
|
2981 |
__INST(filePointer) = __MKOBJ((INT)fp); __STORESELF(filePointer); |
|
2982 |
// but for that, gcc generates wrong code, which loads self (volatile) into |
|
2983 |
// a register (bp), then calls __MKOBJ, then stores indirect bp. |
|
2984 |
// That is wrong if a scavenge occurs in MKOBJ, as bp is now still pointing to the old |
|
2985 |
// object. |
|
2986 |
# endif |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2987 |
{ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2988 |
OBJ t; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2989 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2990 |
t = __MKOBJ(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2991 |
__INST(filePointer) = t; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
2992 |
__STORE(self, t); |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
2993 |
} |
876 | 2994 |
#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
|
2995 |
%}. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2996 |
mode := #readwrite. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2997 |
Lobby register:self. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2998 |
binary := false. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2999 |
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
|
3000 |
|
1282 | 3001 |
addr notNil ifTrue:[ |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3002 |
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
|
3003 |
]. |
7e5f2f6b177d
getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents:
1186
diff
changeset
|
3004 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3005 |
^ true |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3006 |
! |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
3007 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3008 |
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3009 |
"suspend the current process, until either a new connection comes |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3010 |
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
|
3011 |
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
|
3012 |
For an old connection, that socket is returned. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3013 |
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
|
3014 |
or nil, if a timeout occured. |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3015 |
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
|
3016 |
server application." |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3017 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3018 |
" first, a quick check if data is already available " |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3019 |
|
1035 | 3020 |
|wasBlocked sema| |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3021 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3022 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3023 |
"/ 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
|
3024 |
"/ Must poll here. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3025 |
^ 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
|
3026 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3027 |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3028 |
self canReadWithoutBlocking ifTrue:[ |
1170 | 3029 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3030 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3031 |
otherConnections do:[:aConnection | |
1170 | 3032 |
aConnection canReadWithoutBlocking ifTrue:[ |
3033 |
^ aConnection |
|
3034 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3035 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3036 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3037 |
[ |
1170 | 3038 |
"/ check again - prevent incoming interrupts from disturbing our setup |
3039 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3040 |
||
3041 |
self canReadWithoutBlocking ifTrue:[ |
|
3042 |
^ self accept. |
|
3043 |
]. |
|
3044 |
otherConnections do:[:aConnection | |
|
3045 |
aConnection canReadWithoutBlocking ifTrue:[ |
|
3046 |
^ aConnection |
|
3047 |
] |
|
3048 |
]. |
|
3049 |
||
3050 |
"/ nope - must wait. |
|
3051 |
||
3052 |
sema := Semaphore new name:'multiReadWait'. |
|
3053 |
otherConnections do:[:aConnection | |
|
3054 |
Processor signal:sema onInput:(aConnection fileDescriptor). |
|
3055 |
]. |
|
3056 |
Processor signal:sema onInput:(self fileDescriptor). |
|
3057 |
timeoutSeconds notNil ifTrue:[ |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3058 |
Processor signal:sema afterSeconds:timeoutSeconds |
1170 | 3059 |
]. |
3060 |
Processor activeProcess state:#ioWait. |
|
3061 |
sema wait. |
|
1136 | 3062 |
] ensure:[ |
1170 | 3063 |
sema notNil ifTrue:[Processor disableSemaphore:sema]. |
3064 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3065 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3066 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3067 |
"/ see who it was ... |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3068 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3069 |
self canReadWithoutBlocking ifTrue:[ |
1170 | 3070 |
^ self accept. |
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3071 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3072 |
otherConnections do:[:aConnection | |
1170 | 3073 |
aConnection canReadWithoutBlocking ifTrue:[ |
3074 |
^ aConnection |
|
3075 |
] |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3076 |
]. |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3077 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3078 |
"/ none - a timeout |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3079 |
^ nil |
867 | 3080 |
! |
3081 |
||
3082 |
waitForNewConnectionWithTimeout:timeoutSeconds |
|
3083 |
"suspend the current process, until a new connection comes |
|
3084 |
in at the receiver or a timeout occurs. |
|
3085 |
For a new connection, an accept is performed and the new socket is returned. |
|
3086 |
Returns nil, if a timeout occured. |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3087 |
This method implements the inner wait-primitive of a single-connection |
867 | 3088 |
server application." |
3089 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3090 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3091 |
"/ 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
|
3092 |
"/ Must poll here. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3093 |
^ self pollingWaitForNewConnectionWithTimeout:timeoutSeconds |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3094 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3095 |
|
867 | 3096 |
(self readWaitWithTimeout:timeoutSeconds) ifTrue:[ |
3097 |
"/ a timeout occurred - no connection within timeout |
|
3098 |
^ nil |
|
3099 |
]. |
|
3100 |
^ self accept. |
|
781
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3101 |
! ! |
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3102 |
|
4d61e7588ff3
added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents:
776
diff
changeset
|
3103 |
!Socket methodsFor:'low level-connecting'! |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
3104 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3105 |
connectTo:hostOrPathName port:portNrOrName |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3106 |
"low level connect; connect to port, portNrOrNameOrNil on host, hostName. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3107 |
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
|
3108 |
but it is recommended to pass socketAddress instances. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3109 |
|
71 | 3110 |
Return true if ok, false otherwise. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3111 |
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
|
3112 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
28 | 3113 |
|
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3114 |
^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil |
649 | 3115 |
! |
3116 |
||
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3117 |
connectTo:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil withTimeout:timeout |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3118 |
"low level connect; connect to port, portNrOrNameOrNil on host, hostName. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3119 |
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
|
3120 |
but it is recommended to pass socketAddress instances. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3121 |
|
649 | 3122 |
Return true if ok, false otherwise. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3123 |
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
|
3124 |
or timeout millliseconds have passed." |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3125 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3126 |
|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
|
3127 |
|
28 | 3128 |
filePointer isNil ifTrue:[ |
1343 | 3129 |
^ self errorNotOpen |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3130 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3131 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3132 |
domainClass := self class socketAddressClassForDomain:domain. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3133 |
domainClass isNil ifTrue:[ |
1343 | 3134 |
^ self error:'invalid (unsupported) domain'. |
28 | 3135 |
]. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3136 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3137 |
"/ backward compatibility: support for byteArray and string arg |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3138 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3139 |
hostOrPathNameOrSocketAddr isString ifTrue:[ |
1343 | 3140 |
addr := domainClass hostName:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil. |
3141 |
addrName := hostOrPathNameOrSocketAddr. |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3142 |
] ifFalse:[ |
1343 | 3143 |
hostOrPathNameOrSocketAddr isByteArray ifFalse:[ |
3144 |
^ self error:'bad host (socketAddress) argument' |
|
3145 |
]. |
|
3146 |
(hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[ |
|
3147 |
addr := hostOrPathNameOrSocketAddr. |
|
3148 |
portNrOrNameOrNil notNil ifTrue:[ |
|
3149 |
addr port:portNrOrNameOrNil. |
|
3150 |
]. |
|
3151 |
] ifFalse:[ |
|
3152 |
addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil. |
|
3153 |
]. |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3154 |
]. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3155 |
|
1120 | 3156 |
%{ /* STACK: 100000 */ |
649 | 3157 |
|
418 | 3158 |
#ifndef NO_SOCKET |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3159 |
OBJ fp = __INST(filePointer); |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3160 |
union sockaddr_u sa; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3161 |
SOCKET sock; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3162 |
int a; |
649 | 3163 |
int ret, oldFlags; |
28 | 3164 |
int on = 1; |
115 | 3165 |
int sockaddr_size; |
28 | 3166 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3167 |
if (!__isNonNilObject(addr) || !__isBytes(addr)) { |
1343 | 3168 |
DBGPRINTF(("SOCKET: invalid addrBytes\n")); |
3169 |
RETURN (false); |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3170 |
} |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3171 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3172 |
{ |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3173 |
int sockAddrOffs, nIndex; |
1343 | 3174 |
OBJ cls; |
3175 |
||
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3176 |
sockAddrOffs = 0; |
1343 | 3177 |
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
|
3178 |
sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1343 | 3179 |
nIndex = __qSize(addr) - OHDR_SIZE; |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3180 |
sockaddr_size = nIndex - sockAddrOffs; |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3181 |
if (sockaddr_size > sizeof(sa)) { |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3182 |
fprintf(stderr, "Socket: bad socketAddr\n"); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3183 |
RETURN (false); |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3184 |
} |
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3185 |
bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size); |
28 | 3186 |
} |
3187 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3188 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
28 | 3189 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3190 |
# if defined(O_NONBLOCK) |
1537 | 3191 |
# if !defined(WIN32) |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3192 |
/* |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3193 |
* set to non-blocking and wait later |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3194 |
*/ |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3195 |
oldFlags = fcntl(sock, F_GETFL, 0); |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3196 |
/* 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
|
3197 |
fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK); |
1537 | 3198 |
# endif |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3199 |
# endif |
649 | 3200 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3201 |
/* |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3202 |
* connect |
28 | 3203 |
*/ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3204 |
# ifdef DO_WRAP_CALLS |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3205 |
do { |
1541 | 3206 |
DBGFPRINTF((stderr, "SOCKET: connect...\n")); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3207 |
__threadErrno = 0; |
1542 | 3208 |
ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, sockaddr_size); |
1541 | 3209 |
DBGFPRINTF((stderr, "SOCKET: connect -> %d (%d)\n", ret, __threadErrno)); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3210 |
} 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
|
3211 |
# else |
81 | 3212 |
__BEGIN_INTERRUPTABLE__ |
28 | 3213 |
do { |
1504
92005eec5c9d
fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents:
1503
diff
changeset
|
3214 |
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
|
3215 |
} while ((ret < 0) |
1343 | 3216 |
&& ((errno == EINTR) |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3217 |
# ifdef EAGAIN |
1343 | 3218 |
|| (errno == EAGAIN) |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3219 |
# endif |
1343 | 3220 |
)); |
81 | 3221 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3222 |
#endif |
28 | 3223 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3224 |
if (ret < 0) { |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3225 |
# if defined(EINPROGRESS) || defined(EALREADY) |
1343 | 3226 |
if (0 |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3227 |
# ifdef EINPROGRESS |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3228 |
|| (errno == EINPROGRESS) |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3229 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3230 |
# ifdef EALREADY |
1343 | 3231 |
|| (errno == EALREADY) |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3232 |
# endif |
1343 | 3233 |
) { |
3234 |
/* |
|
3235 |
* This was a nonblocking operation that will take some time. |
|
3236 |
* Do a select on read to get informed when the operation is ready. |
|
3237 |
*/ |
|
1541 | 3238 |
DBGFPRINTF((stderr, "SOCKET: isAsync is true\n")); |
1343 | 3239 |
isAsync = true; |
3240 |
} else |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3241 |
# endif /* EINPROGRESS or EALREADY */ |
1343 | 3242 |
{ |
1541 | 3243 |
DBGFPRINTF((stderr, "SOCKET: connect failed ret=%d errno=%d __threadErrno=%d\n", |
1540 | 3244 |
ret, errno, __threadErrno )); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3245 |
# ifdef DUMP_ADDRESS |
1343 | 3246 |
{ |
3247 |
char *cp = (char *)(&sa); |
|
3248 |
int i; |
|
3249 |
||
3250 |
printf("address data:\n"); |
|
3251 |
for (i=0; i<sockaddr_size; i++) { |
|
3252 |
printf(" %02x\n", *cp++); |
|
3253 |
} |
|
3254 |
} |
|
649 | 3255 |
# endif |
1343 | 3256 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
3257 |
RETURN (false); |
|
3258 |
} |
|
28 | 3259 |
} |
649 | 3260 |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3261 |
# if defined(O_NONBLOCK) |
1537 | 3262 |
# if !defined(WIN32) |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3263 |
fcntl(sock, F_SETFL, oldFlags); |
1537 | 3264 |
# endif |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3265 |
# endif |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3266 |
|
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3267 |
# else /* NO_SOCKET */ |
418 | 3268 |
RETURN (false); |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3269 |
# endif /* NO_SOCKET */ |
42 | 3270 |
%}. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3271 |
isAsync == true ifTrue:[ |
1343 | 3272 |
(self writeWaitWithTimeoutMs:timeout) ifTrue:[ |
3273 |
"/ a timeout occured |
|
3274 |
"/ should cancel the connect? |
|
3275 |
^ false. |
|
3276 |
]. |
|
3277 |
err := self getSocketError. |
|
3278 |
err ~~ 0 ifTrue:[ |
|
3279 |
lastErrorNumber := err. |
|
3280 |
^ false. |
|
3281 |
]. |
|
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3282 |
]. |
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3283 |
port := portNrOrNameOrNil. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3284 |
peer := addr. |
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3285 |
peerName := addrName. |
28 | 3286 |
^ true |
896
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3287 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3288 |
" |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3289 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3290 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3291 |
sock connectTo:'localhost' port:21 withTimeout:1000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3292 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3293 |
|
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3294 |
|sock| |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3295 |
sock := Socket newTCP. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3296 |
sock connectTo:'localhost' port:9876 withTimeout:2000. |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3297 |
sock |
2ca43149a20e
Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents:
888
diff
changeset
|
3298 |
" |
25 | 3299 |
! ! |
3300 |
||
1462 | 3301 |
!Socket methodsFor:'printing & storing'! |
3302 |
||
3303 |
printOn:aStream |
|
3304 |
aStream nextPutAll:'Socket(protocol='. |
|
3305 |
protocol printOn:aStream. |
|
3306 |
aStream nextPutAll:' port='. |
|
3307 |
port printOn:aStream. |
|
3308 |
aStream nextPutAll:' peer='. |
|
3309 |
peer printOn:aStream. |
|
3310 |
aStream nextPutAll:')'. |
|
3311 |
! ! |
|
3312 |
||
25 | 3313 |
!Socket methodsFor:'queries'! |
3314 |
||
126 | 3315 |
domain |
3316 |
"return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)" |
|
3317 |
||
3318 |
^ domain |
|
3319 |
! |
|
3320 |
||
1505 | 3321 |
getFullSocketAddress |
1535 | 3322 |
"implemented for swazoo project (primitive code cant be loaded as extension) |
3323 |
Answer my own address (I am bound to this address). |
|
3324 |
Note that this address may change after a connect or accept." |
|
3325 |
||
3326 |
|error domainClass addr addrLen| |
|
3327 |
||
3328 |
filePointer isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3329 |
^ self errorNotOpen |
1535 | 3330 |
]. |
3331 |
||
3332 |
domainClass := self class socketAddressClassForDomain:domain. |
|
3333 |
domainClass isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3334 |
^ self error:'invalid (unsupported) domain'. |
1535 | 3335 |
]. |
3336 |
addrLen := domainClass socketAddressSize. |
|
3337 |
addr := domainClass new. |
|
3338 |
||
3339 |
%{ |
|
3340 |
#ifndef NO_SOCKET |
|
3341 |
OBJ fp = __INST(filePointer); |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3342 |
SOCKET sock; |
1535 | 3343 |
int ret; |
3344 |
union sockaddr_u sa; |
|
1560
50c1e959ede8
Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents:
1558
diff
changeset
|
3345 |
unsigned int alen, alen0; |
1535 | 3346 |
char *addrP; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3347 |
int addrObjSize, nAddrInstBytes; |
1535 | 3348 |
|
3349 |
if (!__isSmallInteger(addrLen)) { |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3350 |
DBGPRINTF(("SOCKET: bad addrLen\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3351 |
error = @symbol(badArgument); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3352 |
goto err; |
1535 | 3353 |
} |
1536 | 3354 |
alen = alen0 = __intVal(addrLen); |
1535 | 3355 |
|
3356 |
if (!__isNonNilObject(addr) || !__isBytes(addr)) { |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3357 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3358 |
error = @symbol(badArgument); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3359 |
goto err; |
1535 | 3360 |
} |
3361 |
||
3362 |
{ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3363 |
OBJ addrClass; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3364 |
int nAddrInstVars; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3365 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3366 |
addrClass = __qClass(addr); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3367 |
nAddrInstVars = __intVal(__ClassInstPtr(addrClass)->c_ninstvars); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3368 |
nAddrInstBytes = OHDR_SIZE + (nAddrInstVars * sizeof(OBJ)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3369 |
addrObjSize = __qSize(addr) - nAddrInstBytes; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3370 |
if (addrObjSize < alen0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3371 |
DBGPRINTF(("SOCKET: bad addr/alen\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3372 |
error = @symbol(badArgument); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3373 |
goto err; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3374 |
} |
1535 | 3375 |
} |
3376 |
||
3377 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
|
3378 |
# ifdef WIN32 |
|
3379 |
__threadErrno = 0; |
|
3380 |
# endif |
|
3381 |
ret = getsockname(sock, (struct sockaddr *)&sa, &alen); |
|
3382 |
if (ret < 0) { |
|
1536 | 3383 |
# ifdef WIN32 |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3384 |
errno = WSAGetLastError(); |
1536 | 3385 |
# endif |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3386 |
DBGPRINTF(("SOCKET: getsocketname failed ret=%d errno=%d\n", ret, errno)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3387 |
error = __MKSMALLINT(errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3388 |
goto err; |
1535 | 3389 |
} |
3390 |
||
3391 |
if (addrObjSize < alen) { |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3392 |
DBGPRINTF(("SOCKET: bad addr\n")); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3393 |
error = @symbol(badArgument); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3394 |
goto err; |
1535 | 3395 |
} |
3396 |
||
3397 |
addrP = (char *)__InstPtr(addr) + nAddrInstBytes; |
|
3398 |
bcopy((char *)&sa, addrP, alen); |
|
3399 |
||
3400 |
addrLen = __MKSMALLINT(alen); |
|
3401 |
||
3402 |
err:; |
|
3403 |
#else /* NO_SOCKET */ |
|
3404 |
error = @symbol(notImplemented); |
|
3405 |
#endif /* NO_SOCKET */ |
|
3406 |
%}. |
|
3407 |
error notNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3408 |
^ self errorReporter reportOn:error |
1535 | 3409 |
]. |
3410 |
^ addr |
|
3411 |
! |
|
3412 |
||
126 | 3413 |
getName |
3414 |
"return the name; here, we return the ports name" |
|
3415 |
||
3416 |
^ port printString |
|
3417 |
! |
|
3418 |
||
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3419 |
getPeer |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3420 |
"ST-80 compatibility: return an IPSocketAddress instance representing |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3421 |
my hostname/port combination. |
155
fcf846c707b7
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
3422 |
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
|
3423 |
|
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
|
3424 |
peer isNil ifTrue:[ |
1343 | 3425 |
peer := self class peerFromDomain:domain name:peerName port:port. |
819 | 3426 |
]. |
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
|
3427 |
^ peer |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3428 |
! |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3429 |
|
25 | 3430 |
getPeerName |
3431 |
"return the peer name; thats the hostname (or dotted name) of the |
|
3432 |
partners host after an accept." |
|
3433 |
||
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
|
3434 |
peerName isNil ifTrue:[ |
1343 | 3435 |
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
|
3436 |
]. |
25 | 3437 |
^ peerName |
28 | 3438 |
! |
3439 |
||
1146 | 3440 |
getSocketAddress |
3441 |
"implemented for swazoo project primitive code cant load as extension |
|
1170 | 3442 |
answer my own address (I am bound to this address). |
1146 | 3443 |
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
|
3444 |
|
1535 | 3445 |
^ self getFullSocketAddress hostAddress |
3446 |
"/ ^ self getFullSocketAddress copyFrom:5 to:8 |
|
1029
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
3447 |
! |
5906977e62f0
implement getSocketName for swazoo as primitive cant load as extension
penk
parents:
1010
diff
changeset
|
3448 |
|
1146 | 3449 |
getSocketAdress |
1505 | 3450 |
"BAD SPELLING, of #getSocketAddress, kept for compatibility with swazoo" |
3451 |
||
3452 |
<resource: #obsolete> |
|
1146 | 3453 |
|
3454 |
^ self getSocketAddress |
|
3455 |
! |
|
3456 |
||
126 | 3457 |
isActive |
3458 |
"return true, if the receiver has a connection" |
|
81 | 3459 |
|
126 | 3460 |
^ filePointer notNil |
81 | 3461 |
! |
3462 |
||
1110 | 3463 |
isConnected |
3464 |
"return true, if the receiver has a connection" |
|
3465 |
||
3466 |
^ self isActive |
|
3467 |
and:[port notNil |
|
1224
530a6f9723a1
use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3468 |
and:[peerName notNil or:[peer notNil]]] |
1110 | 3469 |
! |
3470 |
||
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3471 |
old_getFullSocketAddress |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3472 |
"implemented for swazoo project primitive code cant load as extension |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3473 |
answer my own address (I am bound to this address). |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3474 |
Note that this address may change after connect or accept." |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3475 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3476 |
|socketAddress error| |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3477 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3478 |
filePointer isNil ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3479 |
^ self errorNotOpen |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3480 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3481 |
socketAddress := ByteArray new:16. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3482 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3483 |
%{ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3484 |
#ifndef NO_SOCKET |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3485 |
OBJ fp = __INST(filePointer); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3486 |
SOCKET sock; |
1561
43a2b204e80e
signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents:
1560
diff
changeset
|
3487 |
unsigned int sockaddr_size; |
1558
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3488 |
int ret; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3489 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3490 |
if (!__isNonNilObject(socketAddress) || |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3491 |
(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3492 |
error = @symbol(badArgument1); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3493 |
goto err; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3494 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3495 |
sockaddr_size = __byteArraySize(socketAddress); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3496 |
|
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3497 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3498 |
ret = getsockname(sock, (struct sockaddr *)__byteArrayVal(socketAddress), &sockaddr_size); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3499 |
if (ret < 0) { |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3500 |
# ifdef WIN32 |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3501 |
errno = WSAGetLastError(); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3502 |
# endif |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3503 |
DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno)); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3504 |
error = __MKSMALLINT(errno); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3505 |
} |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3506 |
err:; |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3507 |
#else /* NO_SOCKET */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3508 |
error = @symbol(notImplemented); |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3509 |
#endif /* NO_SOCKET */ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3510 |
%}. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3511 |
error notNil ifTrue:[ |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3512 |
^ self errorReporter reportOn:error |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3513 |
]. |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3514 |
^ socketAddress |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3515 |
! |
a563aac90660
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
1542
diff
changeset
|
3516 |
|
71 | 3517 |
port |
3518 |
"return the port number (or name for unix-sockets) to which the socket is bound" |
|
28 | 3519 |
|
1505 | 3520 |
"/ sometimes maybe we do am lazy fetch of the port |
3521 |
"/ port == 0 ifTrue:[ |p| |
|
3522 |
"/ p := self getPort. |
|
3523 |
"/ p notNil ifTrue:[ |
|
3524 |
"/ port := p |
|
3525 |
"/ ] |
|
3526 |
"/ ]. |
|
71 | 3527 |
^ port |
28 | 3528 |
! |
3529 |
||
3530 |
type |
|
3531 |
"return the sockets connection type (i.e. #datagram, #stream etc)" |
|
3532 |
||
3533 |
^ socketType |
|
81 | 3534 |
! ! |
3535 |
||
126 | 3536 |
!Socket methodsFor:'socket setup'! |
3537 |
||
3538 |
domain:domainArg type:typeArg |
|
3539 |
"set up socket with domain and type. |
|
3540 |
This is a low level entry; no binding, listening or connect |
|
3541 |
is done. Both arguments must be symbols from one of |
|
3542 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
3543 |
||
649 | 3544 |
^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true |
126 | 3545 |
! |
3546 |
||
3547 |
domain:domainArg type:typeArg protocol:protocolNumber |
|
3548 |
"set up socket with domain, type and protocol number. |
|
3549 |
This is a low level entry; no binding, listening or connect |
|
3550 |
is done. Both arguments must be symbols from one of |
|
3551 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
3552 |
||
649 | 3553 |
^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true |
3554 |
||
3555 |
" |
|
3556 |
Socket new domain:#inet type:#stream |
|
3557 |
Socket new domain:#unix type:#stream |
|
3558 |
" |
|
3559 |
! |
|
3560 |
||
3561 |
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse |
|
3562 |
"set up socket with domain, type and protocol number. |
|
3563 |
This is a low level entry; no binding, listening or connect |
|
3564 |
is done. Both arguments must be symbols from one of |
|
3565 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp. |
|
3566 |
||
3567 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
3568 |
is to be set (to avoid the 'bind: address in use' error)." |
|
3569 |
||
1280
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3570 |
|domainName domainCode typeCode| |
126 | 3571 |
|
3572 |
filePointer notNil ifTrue:[ |
|
1343 | 3573 |
^ self errorAlreadyOpen |
126 | 3574 |
]. |
1280
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3575 |
domainName := SocketAddress domainCodeFromName:domainArg. |
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3576 |
domainCode := OperatingSystem domainCodeOf:domainName. |
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3577 |
typeCode := OperatingSystem socketTypeCodeOf:typeArg. |
126 | 3578 |
%{ |
649 | 3579 |
|
418 | 3580 |
#ifndef NO_SOCKET |
126 | 3581 |
FILE *fp; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3582 |
int dom, typ, pf, proto = 0; |
649 | 3583 |
int on = 1; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3584 |
SOCKET sock; |
126 | 3585 |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3586 |
if (! __isSmallInteger(domainCode)) { |
1343 | 3587 |
DBGPRINTF(("SOCKET: bad domain\n")); |
3588 |
RETURN ( nil ); |
|
126 | 3589 |
} |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3590 |
if (! __isSmallInteger(typeCode)) { |
1343 | 3591 |
DBGPRINTF(("SOCKET: bad type\n")); |
3592 |
RETURN ( nil ); |
|
126 | 3593 |
} |
3594 |
if (protocolNumber != nil) { |
|
1343 | 3595 |
if (!__isSmallInteger(protocolNumber)) { |
3596 |
DBGPRINTF(("SOCKET: bad protocol\n")); |
|
3597 |
RETURN ( nil ); |
|
3598 |
} |
|
3599 |
proto = __intVal(protocolNumber); |
|
126 | 3600 |
} |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3601 |
|
81 | 3602 |
|
126 | 3603 |
/* |
3604 |
* get address and protocol-family |
|
3605 |
*/ |
|
1280
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3606 |
dom = __intVal(domainCode); |
b973855bfe74
moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
3607 |
typ = __intVal(typeCode); |
126 | 3608 |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3609 |
# ifdef SOCKET_BLOCKS |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3610 |
# 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
|
3611 |
do { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3612 |
__threadErrno = 0; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3613 |
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
|
3614 |
} while ((sock < 0) && (__threadErrno == EINTR)); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3615 |
# else |
126 | 3616 |
__BEGIN_INTERRUPTABLE__ |
3617 |
do { |
|
1343 | 3618 |
DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto)); |
3619 |
sock = socket(dom, typ, proto); |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3620 |
# if defined(EPROTONOSUPPORT) /* for SGI */ |
1343 | 3621 |
if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) { |
3622 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
|
3623 |
proto = 0; |
|
3624 |
sock = socket(dom, typ, 0); |
|
3625 |
} |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3626 |
# endif |
126 | 3627 |
} while ((sock < 0) && (errno == EINTR)); |
3628 |
__END_INTERRUPTABLE__ |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3629 |
# endif |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3630 |
# else |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3631 |
sock = socket(dom, typ, proto); |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3632 |
# if defined(EPROTONOSUPPORT) /* for SGI */ |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3633 |
if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) { |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3634 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3635 |
proto = 0; |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3636 |
sock = socket(dom, typ, 0); |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3637 |
} |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3638 |
# endif |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3639 |
# endif |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3640 |
|
1541 | 3641 |
DBGFPRINTF((stderr, "SOCKET: create newSock=%d\n", sock)); |
126 | 3642 |
|
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3643 |
# ifdef WIN32 |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3644 |
if (sock == INVALID_SOCKET) |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3645 |
# else |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3646 |
if (sock < 0) |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3647 |
# endif |
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3648 |
{ |
1343 | 3649 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno)); |
3650 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 3651 |
} else { |
649 | 3652 |
# ifdef SO_REUSEADDR |
1343 | 3653 |
if (reuse == true) { |
3654 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n")); |
|
3655 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
3656 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
3657 |
} |
|
3658 |
} |
|
649 | 3659 |
# endif /* SO_REUSEADDR */ |
711 | 3660 |
|
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3661 |
# 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
|
3662 |
# ifdef SO_LINGER |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3663 |
{ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3664 |
struct linger l; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3665 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3666 |
l.l_onoff = 1; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3667 |
l.l_linger = 30; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3668 |
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
|
3669 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3670 |
# endif |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3671 |
# endif |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3672 |
# ifdef WIN32 |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3673 |
/* |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3674 |
* make it blocking |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3675 |
*/ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3676 |
{ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3677 |
int zero = 0; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3678 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3679 |
ioctlsocket(sock, FIONBIO, &zero); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3680 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3681 |
# endif |
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3682 |
/* |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3683 |
* make it a FILE * |
1343 | 3684 |
*/ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3685 |
# ifdef WIN32 |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3686 |
{ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3687 |
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
|
3688 |
fp = fdopen(_fd, "r+"); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3689 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3690 |
# else |
1343 | 3691 |
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
|
3692 |
# endif |
1343 | 3693 |
if (! fp) { |
3694 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
3695 |
__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
|
3696 |
# ifdef DO_WRAP_CALLS |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3697 |
{ int ret; |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3698 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3699 |
do { |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3700 |
__threadErrno = 0; |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3701 |
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
|
3702 |
} 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
|
3703 |
} |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3704 |
# else |
1343 | 3705 |
__BEGIN_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3706 |
closesocket(sock); |
1541 | 3707 |
DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", sock)); |
1343 | 3708 |
__END_INTERRUPTABLE__ |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3709 |
# endif |
1343 | 3710 |
} else { |
3711 |
if (@global(FileOpenTrace) == true) { |
|
3712 |
fprintf(stderr, "fdopen [Socket] -> %x\n", fp); |
|
3713 |
} |
|
3714 |
||
1486 | 3715 |
# if 0 |
3716 |
// The original code was: |
|
3717 |
__INST(filePointer) = __MKOBJ((INT)fp); __STORESELF(filePointer); |
|
3718 |
// but for that, gcc generates wrong code, which loads self (volatile) into |
|
3719 |
// a register (bp), then calls __MKOBJ, then stores indirect bp. |
|
3720 |
// That is wrong if a scavenge occurs in MKOBJ, as bp is now still pointing to the old |
|
3721 |
// object. |
|
3722 |
# endif |
|
1485
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3723 |
{ |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3724 |
OBJ t; |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3725 |
|
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3726 |
t = __MKOBJ(fp); |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3727 |
__INST(filePointer) = t; |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3728 |
__STORE(self, t); |
d8578cf3504b
gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents:
1474
diff
changeset
|
3729 |
} |
1343 | 3730 |
} |
126 | 3731 |
} |
418 | 3732 |
#endif |
126 | 3733 |
%}. |
3734 |
||
3735 |
"all ok?" |
|
3736 |
filePointer notNil ifTrue:[ |
|
1343 | 3737 |
domain := domainArg. |
3738 |
socketType := typeArg. |
|
3739 |
Lobby register:self. |
|
126 | 3740 |
] ifFalse:[ |
1343 | 3741 |
^ nil |
126 | 3742 |
]. |
3743 |
||
3744 |
" |
|
3745 |
Socket new domain:#inet type:#stream |
|
3746 |
Socket new domain:#unix type:#stream |
|
3747 |
" |
|
28 | 3748 |
! ! |
3749 |
||
3750 |
!Socket methodsFor:'specials'! |
|
3751 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3752 |
readWaitWithTimeoutMs:timeoutMilliSeconds |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3753 |
"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
|
3754 |
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
|
3755 |
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
|
3756 |
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
|
3757 |
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
|
3758 |
server application." |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3759 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3760 |
|millis| |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3761 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3762 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3763 |
"/ 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
|
3764 |
"/ Must poll here. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3765 |
|
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3766 |
millis := timeoutMilliSeconds. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3767 |
[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
|
3768 |
self canReadWithoutBlocking ifTrue:[^ false]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3769 |
Delay waitForMilliseconds:20. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3770 |
millis notNil ifTrue:[ |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3771 |
millis := millis - 20. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3772 |
] |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3773 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3774 |
^ true. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3775 |
]. |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3776 |
^ super readWaitWithTimeoutMs:timeoutMilliSeconds |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3777 |
! |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3778 |
|
1335 | 3779 |
receiveBufferSize |
3780 |
"get the send buffer size - for special applications only. |
|
3781 |
Not all operatingSystems offer this functionality |
|
3782 |
(returns nil, if unsupported)" |
|
3783 |
||
3784 |
filePointer isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3785 |
^ self errorNotOpen |
1335 | 3786 |
]. |
3787 |
%{ |
|
3788 |
#if defined(SO_RCVBUF) && defined(SOL_SOCKET) |
|
3789 |
{ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3790 |
OBJ fp = __INST(filePointer); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3791 |
SOCKET sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3792 |
int opt; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3793 |
unsigned int size; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3794 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3795 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3796 |
if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &size) >= 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3797 |
RETURN( __MKSMALLINT(opt) ); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3798 |
} |
1335 | 3799 |
} |
3800 |
#endif |
|
3801 |
%}. |
|
3802 |
^ nil |
|
3803 |
! |
|
3804 |
||
3805 |
receiveBufferSize:size |
|
3806 |
"set the receive buffer size - for special applications only. |
|
3807 |
Not all operatingSystems offer this functionality |
|
3808 |
(returns false, if unsupported)" |
|
3809 |
||
3810 |
filePointer isNil ifTrue:[ |
|
1343 | 3811 |
^ self errorNotOpen |
1335 | 3812 |
]. |
3813 |
%{ |
|
3814 |
#if defined(SO_RCVBUF) && defined(SOL_SOCKET) |
|
3815 |
if (__isSmallInteger(size)) { |
|
1343 | 3816 |
OBJ fp = __INST(filePointer); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3817 |
SOCKET sock; |
1343 | 3818 |
int opt; |
3819 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3820 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
1343 | 3821 |
opt = __intVal(size); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3822 |
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
|
3823 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3824 |
} |
1335 | 3825 |
} |
3826 |
#endif |
|
3827 |
%}. |
|
3828 |
^ false |
|
3829 |
! |
|
3830 |
||
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3831 |
receiveTimeout |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3832 |
"get the receive timeout in millis - for special applications only. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3833 |
Not all operatingSystems offer this functionality |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3834 |
(returns nil, if unsupported)" |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3835 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3836 |
|millis| |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3837 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3838 |
filePointer isNil ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3839 |
^ self errorNotOpen |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3840 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3841 |
%{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3842 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3843 |
{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3844 |
OBJ fp = __INST(filePointer); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3845 |
int sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3846 |
int len; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3847 |
int __millis; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3848 |
struct timeval tv = {0, 0}; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3849 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3850 |
sock = fileno(__FILEVal(fp)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3851 |
len = sizeof(struct timeval); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3852 |
if (getsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, &len) == 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3853 |
__millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3854 |
millis = __mkSmallInteger(__millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3855 |
# if 0 |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3856 |
fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3857 |
# endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3858 |
} else { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3859 |
fprintf(stderr, "getsockopt %d failed; errno=%d\n", sock, errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3860 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3861 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3862 |
#endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3863 |
%}. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3864 |
millis notNil ifTrue:[^ millis / 1000 ]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3865 |
^ nil |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3866 |
! |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3867 |
|
28 | 3868 |
receiveTimeout:seconds |
71 | 3869 |
"set the receive timeout - for special applications only. |
3870 |
Not all operatingSystems offer this functionality |
|
3871 |
(returns false, if unsupported)" |
|
28 | 3872 |
|
3873 |
|millis| |
|
3874 |
||
3875 |
filePointer isNil ifTrue:[ |
|
789 | 3876 |
^ self errorNotOpen |
28 | 3877 |
]. |
3878 |
millis := (seconds * 1000) rounded. |
|
3879 |
%{ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3880 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) |
58 | 3881 |
if (__isSmallInteger(millis)) { |
789 | 3882 |
OBJ fp = __INST(filePointer); |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3883 |
int sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3884 |
int __millis = __intVal(millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3885 |
struct timeval tv = {0, 0}; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3886 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3887 |
sock = fileno(__FILEVal(fp)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3888 |
tv.tv_sec = __millis / 1000; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3889 |
tv.tv_usec = (__millis % 1000) * 1000; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3890 |
# if 0 |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3891 |
fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3892 |
# endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3893 |
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) { |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3894 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3895 |
} |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3896 |
fprintf(stderr, "setsockopt %d failed; errno=%d\n", sock, errno); |
28 | 3897 |
} |
3898 |
#endif |
|
71 | 3899 |
%}. |
28 | 3900 |
^ false |
81 | 3901 |
! |
3902 |
||
1335 | 3903 |
sendBufferSize |
3904 |
"get the send buffer size - for special applications only. |
|
3905 |
Not all operatingSystems offer this functionality |
|
3906 |
(returns nil, if unsupported)" |
|
3907 |
||
3908 |
filePointer isNil ifTrue:[ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3909 |
^ self errorNotOpen |
1335 | 3910 |
]. |
3911 |
%{ |
|
3912 |
#if defined(SO_SNDBUF) && defined(SOL_SOCKET) |
|
3913 |
{ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3914 |
OBJ fp = __INST(filePointer); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3915 |
SOCKET sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3916 |
int opt; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3917 |
unsigned int size; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3918 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3919 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3920 |
if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, &size) >= 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3921 |
RETURN( __MKSMALLINT(opt) ); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3922 |
} |
1335 | 3923 |
} |
3924 |
#endif |
|
3925 |
%}. |
|
3926 |
^ nil |
|
3927 |
! |
|
3928 |
||
3929 |
sendBufferSize:size |
|
3930 |
"set the send buffer size - for special applications only. |
|
3931 |
Not all operatingSystems offer this functionality |
|
3932 |
(returns false, if unsupported)" |
|
3933 |
||
3934 |
filePointer isNil ifTrue:[ |
|
1343 | 3935 |
^ self errorNotOpen |
1335 | 3936 |
]. |
3937 |
%{ |
|
3938 |
#if defined(SO_SNDBUF) && defined(SOL_SOCKET) |
|
3939 |
if (__isSmallInteger(size)) { |
|
1343 | 3940 |
OBJ fp = __INST(filePointer); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
3941 |
SOCKET sock; |
1343 | 3942 |
int opt; |
3943 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3944 |
sock = SOCKET_FROM_FILE_OBJECT(fp); |
1343 | 3945 |
opt = __intVal(size); |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3946 |
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
|
3947 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
3948 |
} |
1335 | 3949 |
} |
3950 |
#endif |
|
3951 |
%}. |
|
3952 |
^ false |
|
3953 |
! |
|
3954 |
||
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3955 |
sendTimeout |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3956 |
"get the send timeout in millis - for special applications only. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3957 |
Not all operatingSystems offer this functionality |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3958 |
(returns nil, if unsupported)" |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3959 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3960 |
|millis| |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3961 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3962 |
filePointer isNil ifTrue:[ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3963 |
^ self errorNotOpen |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3964 |
]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3965 |
%{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3966 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3967 |
{ |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3968 |
OBJ fp = __INST(filePointer); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3969 |
int sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3970 |
int len; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3971 |
int __millis; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3972 |
struct timeval tv = {0, 0}; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3973 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3974 |
sock = fileno(__FILEVal(fp)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3975 |
len = sizeof(struct timeval); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3976 |
if (getsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, &len) == 0) { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3977 |
__millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3978 |
millis = __mkSmallInteger(__millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3979 |
# if 0 |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3980 |
fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3981 |
# endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3982 |
} else { |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3983 |
fprintf(stderr, "getsockopt %d failed; errno=%d\n", sock, errno); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3984 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3985 |
} |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3986 |
#endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3987 |
%}. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3988 |
millis notNil ifTrue:[^ millis / 1000 ]. |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3989 |
^ nil |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3990 |
! |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
3991 |
|
126 | 3992 |
sendTimeout:seconds |
3993 |
"set the send timeout - for special applications only. |
|
3994 |
Not all operatingSystems offer this functionality |
|
3995 |
(returns false, if unsupported)" |
|
81 | 3996 |
|
126 | 3997 |
|millis| |
25 | 3998 |
|
126 | 3999 |
filePointer isNil ifTrue:[ |
789 | 4000 |
^ self errorNotOpen |
126 | 4001 |
]. |
4002 |
millis := (seconds * 1000) rounded. |
|
4003 |
%{ |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4004 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) |
126 | 4005 |
if (__isSmallInteger(millis)) { |
789 | 4006 |
OBJ fp = __INST(filePointer); |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4007 |
int sock; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4008 |
int __millis = __intVal(millis); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4009 |
struct timeval tv = {0, 0}; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4010 |
|
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4011 |
sock = fileno(__FILEVal(fp)); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4012 |
tv.tv_sec = __millis / 1000; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4013 |
tv.tv_usec = (__millis % 1000) * 1000; |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4014 |
# if 0 |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4015 |
fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec); |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4016 |
# endif |
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4017 |
if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) { |
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4018 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4019 |
} |
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4020 |
fprintf(stderr, "setsockopt %d failed; errno=%d\n", sock, errno); |
126 | 4021 |
} |
4022 |
#endif |
|
4023 |
%}. |
|
4024 |
^ false |
|
1568
3bca500e0c7a
send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents:
1561
diff
changeset
|
4025 |
|
1340 | 4026 |
! |
4027 |
||
1342 | 4028 |
setTCPCork:aBoolean |
4029 |
"enable/disable TCP_CORK (do-not-send-partial-frames) |
|
4030 |
For special applications only. |
|
4031 |
Not all OperatingSystems offer this functionality |
|
4032 |
(returns false, if unsupported)" |
|
4033 |
||
4034 |
filePointer isNil ifTrue:[ |
|
1343 | 4035 |
^ self errorNotOpen |
1342 | 4036 |
]. |
4037 |
%{ |
|
4038 |
#if defined(IPPROTO_TCP) && defined(TCP_CORK) |
|
4039 |
int onOff = (aBoolean == true); |
|
4040 |
||
4041 |
if ((aBoolean == true) || (aBoolean == false)) { |
|
1343 | 4042 |
OBJ fp = __INST(filePointer); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
4043 |
SOCKET sock; |
1343 | 4044 |
int onOff = (aBoolean == true); |
4045 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4046 |
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
|
4047 |
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
|
4048 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4049 |
} |
1342 | 4050 |
} |
4051 |
#endif |
|
4052 |
%}. |
|
4053 |
^ false |
|
4054 |
! |
|
4055 |
||
1341 | 4056 |
setTCPNoDelay:aBoolean |
1340 | 4057 |
"enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) |
4058 |
For special applications only. |
|
4059 |
Not all OperatingSystems offer this functionality |
|
4060 |
(returns false, if unsupported)" |
|
4061 |
||
4062 |
filePointer isNil ifTrue:[ |
|
1343 | 4063 |
^ self errorNotOpen |
1340 | 4064 |
]. |
4065 |
%{ |
|
1342 | 4066 |
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY) |
1340 | 4067 |
int onOff = (aBoolean == true); |
4068 |
||
4069 |
if ((aBoolean == true) || (aBoolean == false)) { |
|
1343 | 4070 |
OBJ fp = __INST(filePointer); |
1539
c0e89dcb58b3
non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents:
1538
diff
changeset
|
4071 |
SOCKET sock; |
1343 | 4072 |
int onOff = (aBoolean == true); |
4073 |
||
1529
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4074 |
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
|
4075 |
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
|
4076 |
RETURN(true); |
911273d090c1
Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents:
1505
diff
changeset
|
4077 |
} |
1340 | 4078 |
} |
4079 |
#endif |
|
4080 |
%}. |
|
4081 |
^ false |
|
126 | 4082 |
! ! |
82 | 4083 |
|
464 | 4084 |
!Socket class methodsFor:'documentation'! |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4085 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4086 |
version |
1600 | 4087 |
^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.225 2006-02-15 13:52:13 cg Exp $' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4088 |
! ! |