author | Stefan Vogel <sv@exept.de> |
Tue, 18 Oct 2016 18:50:48 +0200 | |
changeset 20680 | bf04d4121195 |
parent 20644 | c2b4ab689f0d |
child 20685 | 4cf48622d541 |
permissions | -rw-r--r-- |
20680 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
177 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5407 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
17 |
|
1344
32a51164b237
No longer a subclass of UnboundedExternalStream, now subclass of ExternalStream.
Stefan Vogel <sv@exept.de>
parents:
1295
diff
changeset
|
18 |
ExternalStream subclass:#NonPositionableExternalStream |
1295 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'StdInStream StdOutStream StdErrorStream' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Streams-External' |
|
1 | 23 |
! |
24 |
||
613 | 25 |
!NonPositionableExternalStream primitiveDefinitions! |
26 |
%{ |
|
2896 | 27 |
|
5918 | 28 |
#ifndef _STDIO_H_INCLUDED_ |
29 |
# include <stdio.h> |
|
30 |
# define _STDIO_H_INCLUDED_ |
|
31 |
#endif |
|
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3808
diff
changeset
|
32 |
|
10410 | 33 |
#ifndef REMOVE_LATER |
34 |
# define __win32_stdout() stdout |
|
35 |
# define __win32_stderr() stderr |
|
36 |
# define __win32_stdin() stdin |
|
37 |
#else |
|
38 |
extern FILE *__win32_stdin(); |
|
39 |
extern FILE *__win32_stderr(); |
|
40 |
extern FILE *__win32_stdout(); |
|
41 |
#endif |
|
42 |
||
613 | 43 |
%} |
44 |
||
45 |
! ! |
|
46 |
||
88 | 47 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
48 |
||
49 |
copyright |
|
50 |
" |
|
51 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
177 | 52 |
All Rights Reserved |
88 | 53 |
|
54 |
This software is furnished under a license and may be used |
|
55 |
only in accordance with the terms of that license and with the |
|
56 |
inclusion of the above copyright notice. This software may not |
|
57 |
be provided or otherwise made available to, or used by, any |
|
58 |
other person. No title to or ownership of the software is |
|
59 |
hereby transferred. |
|
60 |
" |
|
61 |
! |
|
62 |
||
63 |
documentation |
|
64 |
" |
|
65 |
This class provides common protocol for all non-positionable, |
|
66 |
external streams. Concrete subclasses are terminal streams, pipe streams, |
|
67 |
PrinterStreams, Sockets etc. |
|
68 |
||
69 |
There are three special instances of this class, representing stdin, |
|
70 |
stdout and stderr of the smalltalk/X process (see Unix manuals, if you |
|
177 | 71 |
dont know what those are used for). These special streams are bound to |
72 |
to globals Stdin, Stdout and Stderr at early initialization time |
|
73 |
(see Smalltalk>>initializeStandardStreams). |
|
159 | 74 |
|
75 |
The name of this class is a historical leftover - it should be called |
|
76 |
'TTYStream' or similar. |
|
1295 | 77 |
|
78 |
[author:] |
|
3808
5a7866138026
set eolMode of stderr & stdout to #crlf under win32
Claus Gittinger <cg@exept.de>
parents:
3173
diff
changeset
|
79 |
Claus Gittinger |
88 | 80 |
" |
216 | 81 |
! ! |
82 |
||
1 | 83 |
!NonPositionableExternalStream class methodsFor:'instance creation'! |
84 |
||
613 | 85 |
forStderr |
2965 | 86 |
"{ Pragma: +optSpace }" |
87 |
||
613 | 88 |
"return a NonPositionableExternalStream object for writing to |
89 |
Unixes standard error output file descriptor" |
|
90 |
||
91 |
StdErrorStream isNil ifTrue:[ |
|
92 |
StdErrorStream := self basicNew initializeForStderr |
|
93 |
]. |
|
94 |
^ StdErrorStream |
|
95 |
! |
|
96 |
||
1 | 97 |
forStdin |
2965 | 98 |
"{ Pragma: +optSpace }" |
99 |
||
44 | 100 |
"return a NonPositionableExternalStream object for reading from |
101 |
Unixes standard input file descriptor" |
|
102 |
||
88 | 103 |
StdInStream isNil ifTrue:[ |
177 | 104 |
StdInStream := self basicNew initializeForStdin |
88 | 105 |
]. |
106 |
^ StdInStream |
|
1 | 107 |
! |
108 |
||
109 |
forStdout |
|
2965 | 110 |
"{ Pragma: +optSpace }" |
111 |
||
44 | 112 |
"return a NonPositionableExternalStream object for writing to |
113 |
Unixes standard output file descriptor" |
|
114 |
||
88 | 115 |
StdOutStream isNil ifTrue:[ |
177 | 116 |
StdOutStream := self basicNew initializeForStdout |
88 | 117 |
]. |
118 |
^ StdOutStream |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
119 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
120 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
121 |
makePTYPair |
10327 | 122 |
"return an array with two streams - the first one is the master, |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
123 |
the second the slave of a ptym/ptys pair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
124 |
This is much like a bidirectional pipe, but allows signals & |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
125 |
control chars to be passed through the connection. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
126 |
This is needed to execute a shell in a view. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
127 |
This is the higher level equivalent of OperatingSystem>>makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
128 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
129 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
130 |
|ptyPair master slave| |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
131 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
132 |
ptyPair := OperatingSystem makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
133 |
ptyPair notNil ifTrue:[ |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
134 |
master := self forReadWriteToFileDescriptor:(ptyPair at:1). |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
135 |
master buffered:false. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
136 |
slave := self forReadWriteToFileDescriptor:(ptyPair at:2). |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
137 |
slave buffered:false. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
138 |
ptyPair at:1 put:master. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
139 |
ptyPair at:2 put:slave. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
140 |
^ ptyPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
141 |
]. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
142 |
^ nil |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
143 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
144 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
145 |
ExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
146 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
147 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
148 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
149 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
150 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
151 |
makePipe |
10327 | 152 |
"return an array with two streams - the first one for reading, |
153 |
the second for writing. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
154 |
This is the higher level equivalent of OperatingSystem>>makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
155 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
156 |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
157 |
|pipe rs ws| |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
158 |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
159 |
pipe := OperatingSystem makePipe. |
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
160 |
pipe isNil ifTrue:[ |
16348 | 161 |
"/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again |
162 |
'makePipe: enforcing finalization to close any open streams' infoPrintCR. |
|
163 |
ObjectMemory garbageCollect; finalize. |
|
164 |
pipe := OperatingSystem makePipe. |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
165 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
166 |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
167 |
pipe notNil ifTrue:[ |
16348 | 168 |
rs := self forFileDescriptor:(pipe at:1) mode:#readonly buffered:false handleType:#pipeFilePointer. |
169 |
ws := self forFileDescriptor:(pipe at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer. |
|
170 |
^ Array with:rs with:ws |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
171 |
]. |
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
172 |
^ nil |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
173 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
174 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
175 |
|pipe rs ws| |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
176 |
|
7541 | 177 |
pipe := NonPositionableExternalStream makePipe. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
178 |
rs := pipe at:1. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
179 |
ws := pipe at:2. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
180 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
181 |
'read ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
182 |
[ |
16348 | 183 |
1 to:10 do:[:i | |
184 |
Transcript showCR:rs nextLine |
|
185 |
]. |
|
186 |
rs close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
187 |
] forkAt:7. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
188 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
189 |
'write ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
190 |
[ |
16348 | 191 |
1 to:10 do:[:i | |
192 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
193 |
]. |
|
194 |
ws close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
195 |
] fork. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
196 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
197 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
198 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
613 | 199 |
! ! |
200 |
||
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
201 |
!NonPositionableExternalStream methodsFor:'accessing'! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
202 |
|
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
203 |
buffered:aBoolean |
16348 | 204 |
"do not allow to change to buffered mode - ignore true here" |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
205 |
|
16348 | 206 |
aBoolean ifFalse:[ |
207 |
super buffered:false. |
|
208 |
]. |
|
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
209 |
! ! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
210 |
|
613 | 211 |
!NonPositionableExternalStream methodsFor:'error handling'! |
212 |
||
213 |
positionError |
|
2965 | 214 |
"{ Pragma: +optSpace }" |
215 |
||
613 | 216 |
"notify that this stream has no concept of a position" |
217 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
7861
diff
changeset
|
218 |
^ PositionError raiseRequestWith:self |
4559 | 219 |
|
220 |
" |
|
221 |
Stderr positionError |
|
222 |
" |
|
19073 | 223 |
! |
224 |
||
225 |
writeError:errorNumber |
|
20256 | 226 |
"report an error, that some write error occurred. |
19073 | 227 |
Redefined to care for writeErrors on stdout and stderr, |
228 |
which happens under linux, if the console is closed while I am running. |
|
229 |
In this case, we ignore the error." |
|
230 |
||
231 |
((self == Stderr) or:[self == Stdout]) ifTrue:[ |
|
20256 | 232 |
^ self |
19073 | 233 |
]. |
234 |
super writeError:errorNumber |
|
613 | 235 |
! ! |
236 |
||
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
237 |
!NonPositionableExternalStream methodsFor:'initialization'! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
238 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
239 |
initialize |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
240 |
"non-positionable streams do not work well when buffered" |
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
241 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
242 |
super initialize. |
20105 | 243 |
position := nil. "I am not positionable (reading and writing simultaneously)" |
15922 | 244 |
buffered := false. |
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
245 |
! ! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
246 |
|
20368 | 247 |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
248 |
!NonPositionableExternalStream methodsFor:'non homogenous reading'! |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
249 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
250 |
nextBytes:count into:anObject startingAt:start |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
251 |
"read the next count bytes into an object and return the number of |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
252 |
bytes read or the number of bytes read, if EOF is encountered before. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
253 |
An exception is raised if the connection is broken. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
254 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
255 |
Redefined here to avoid blocking of ST/X when waiting for io. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
256 |
Instead only the calling thread will block" |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
257 |
|
8815 | 258 |
|remaining offset nRead| |
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
259 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
260 |
count == 0 ifTrue:[ |
10327 | 261 |
^ 0. |
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
262 |
]. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
263 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
264 |
remaining := count. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
265 |
offset := start. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
266 |
|
10327 | 267 |
[ |
268 |
nRead := self nextAvailableBytes:remaining into:anObject startingAt:offset. |
|
269 |
nRead == 0 ifTrue:[ |
|
270 |
"atEnd does a readWait" |
|
271 |
self atEnd not. |
|
272 |
] ifFalse:[ |
|
273 |
remaining := remaining - nRead. |
|
274 |
offset := offset + nRead. |
|
275 |
remaining ~~ 0. |
|
276 |
] |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
277 |
] whileTrue. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
278 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
279 |
^ count - remaining |
20105 | 280 |
! |
281 |
||
282 |
nextInt16MSB:msbFlag |
|
283 |
"redefined to wait for data on pipes and sockets" |
|
284 |
||
285 |
|bytes nRead| |
|
286 |
||
287 |
bytes := ByteArray uninitializedNew:2. |
|
288 |
nRead := self nextBytes:2 into:bytes startingAt:1. |
|
289 |
nRead ~~ 2 ifTrue:[ |
|
290 |
^ self pastEndRead. |
|
291 |
]. |
|
292 |
^ bytes signedInt16At:1 MSB:msbFlag. |
|
293 |
! |
|
294 |
||
295 |
nextInt32MSB:msbFlag |
|
296 |
"redefined to wait for data on pipes and sockets" |
|
297 |
||
298 |
|bytes nRead| |
|
299 |
||
300 |
bytes := ByteArray uninitializedNew:4. |
|
301 |
nRead := self nextBytes:4 into:bytes startingAt:1. |
|
302 |
nRead ~~ 4 ifTrue:[ |
|
303 |
^ self pastEndRead. |
|
304 |
]. |
|
305 |
^ bytes signedInt32At:1 MSB:msbFlag. |
|
306 |
! |
|
307 |
||
308 |
nextUnsignedInt16MSB:msbFlag |
|
309 |
"redefined to wait for data on pipes and sockets" |
|
310 |
||
311 |
|bytes nRead| |
|
312 |
||
313 |
bytes := ByteArray uninitializedNew:4. |
|
314 |
nRead := self nextBytes:2 into:bytes startingAt:1. |
|
315 |
nRead ~~ 2 ifTrue:[ |
|
316 |
^ self pastEndRead. |
|
317 |
]. |
|
318 |
^ bytes unsignedInt16At:1 MSB:msbFlag. |
|
319 |
! |
|
320 |
||
321 |
nextUnsignedInt32MSB:msbFlag |
|
322 |
"redefined to wait for data on pipes and sockets" |
|
323 |
||
324 |
|bytes nRead| |
|
325 |
||
326 |
bytes := ByteArray uninitializedNew:4. |
|
327 |
nRead := self nextBytes:4 into:bytes startingAt:1. |
|
328 |
nRead ~~ 4 ifTrue:[ |
|
329 |
^ self pastEndRead. |
|
330 |
]. |
|
331 |
^ bytes unsignedInt32At:1 MSB:msbFlag. |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
332 |
! ! |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
333 |
|
613 | 334 |
!NonPositionableExternalStream methodsFor:'positioning'! |
335 |
||
336 |
position |
|
20105 | 337 |
position isNil ifTrue:[ |
338 |
^ self positionError. |
|
339 |
]. |
|
340 |
^ position |
|
1 | 341 |
! |
342 |
||
20105 | 343 |
position:newPosition |
344 |
(position isNil or:[newPosition < position]) ifTrue:[ |
|
345 |
"there is no turning back" |
|
346 |
^ self positionError |
|
347 |
]. |
|
348 |
self skip:newPosition - position. |
|
613 | 349 |
! |
44 | 350 |
|
613 | 351 |
skip:numberToSkip |
7241 | 352 |
"skip count bytes/characters, return the receiver. |
353 |
Re-redefined since PositionableStream redefined it." |
|
613 | 354 |
|
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
355 |
"don't know how to unread ..." |
613 | 356 |
numberToSkip < 0 ifTrue:[ |
20105 | 357 |
^ self positionError. |
88 | 358 |
]. |
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
359 |
numberToSkip timesRepeat:[self next]. |
4467 | 360 |
|
361 |
"Modified: / 30.7.1999 / 12:42:12 / cg" |
|
1 | 362 |
! ! |
363 |
||
177 | 364 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
365 |
||
366 |
printOn:aStream |
|
2965 | 367 |
"{ Pragma: +optSpace }" |
368 |
||
4392 | 369 |
"append a user printed representation of the receiver to aStream. |
370 |
The format is suitable for a human - not meant to be read back." |
|
177 | 371 |
|
2965 | 372 |
|myName| |
373 |
||
177 | 374 |
self == Stdin ifTrue:[ |
10327 | 375 |
myName := 'Stdin'. |
2965 | 376 |
] ifFalse:[ |
10327 | 377 |
self == Stdout ifTrue:[ |
378 |
myName := 'Stdout'. |
|
379 |
] ifFalse:[ |
|
380 |
self == Stderr ifTrue:[ |
|
381 |
myName := 'Stderr'. |
|
382 |
] |
|
383 |
] |
|
177 | 384 |
]. |
2965 | 385 |
|
386 |
myName notNil ifTrue:[ |
|
10327 | 387 |
aStream nextPutAll:myName. |
388 |
^ self |
|
177 | 389 |
]. |
390 |
super printOn:aStream |
|
391 |
! |
|
392 |
||
393 |
storeOn:aStream |
|
2965 | 394 |
"{ Pragma: +optSpace }" |
395 |
||
213 | 396 |
"append a printed representation of the receiver on aStream, from |
397 |
which the receiver can be reconstructed." |
|
177 | 398 |
|
399 |
((self == Stdin) |
|
400 |
or:[self == Stdout |
|
401 |
or:[self == Stderr]]) ifTrue:[ |
|
402 |
^ self printOn:aStream |
|
403 |
]. |
|
404 |
super storeOn:aStream |
|
405 |
! ! |
|
406 |
||
20680 | 407 |
!NonPositionableExternalStream protectedMethodsFor:'private'! |
408 |
||
409 |
closeFile |
|
410 |
|semasToSignal| |
|
411 |
||
412 |
handle notNil ifTrue:[ |
|
413 |
"make sure, that no select is performed on closed file descriptors" |
|
414 |
semasToSignal := Processor disableFd:self fileHandle doSignal:false. |
|
415 |
super closeFile. |
|
416 |
||
417 |
"tell the waiters that they must not wait any longer" |
|
418 |
semasToSignal do:[:eachSema| |
|
419 |
eachSema signalForAll. |
|
420 |
]. |
|
421 |
]. |
|
422 |
! ! |
|
423 |
||
613 | 424 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 425 |
|
5407 | 426 |
handleForStderr |
427 |
"{ Pragma: +optSpace }" |
|
428 |
||
429 |
"return a stderr handle" |
|
430 |
||
431 |
%{ |
|
18313 | 432 |
#ifdef __SCHTEAM__ |
433 |
return context._RETURN( StandardErrorStream ); |
|
434 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
435 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
436 |
RETURN ( __MKEXTERNALADDRESS( __win32_stderr() )); |
18313 | 437 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
438 |
RETURN ( __MKEXTERNALADDRESS(stderr) ); |
18313 | 439 |
# endif |
10327 | 440 |
#endif |
5407 | 441 |
%} |
442 |
! |
|
443 |
||
444 |
handleForStdin |
|
445 |
"{ Pragma: +optSpace }" |
|
446 |
||
447 |
"return a stdin handle" |
|
448 |
||
449 |
%{ |
|
18313 | 450 |
#ifdef __SCHTEAM__ |
451 |
return context._RETURN( StandardInputStream ); |
|
452 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
453 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
454 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdin() )); |
18313 | 455 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
456 |
RETURN ( __MKEXTERNALADDRESS(stdin) ); |
18313 | 457 |
# endif |
10327 | 458 |
#endif |
5407 | 459 |
%} |
460 |
! |
|
461 |
||
462 |
handleForStdout |
|
463 |
"{ Pragma: +optSpace }" |
|
464 |
||
465 |
"return a stdout handle" |
|
466 |
||
467 |
%{ |
|
18313 | 468 |
#ifdef __SCHTEAM__ |
469 |
return context._RETURN( StandardOutputStream ); |
|
470 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
471 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
472 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdout() )); |
18313 | 473 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
474 |
RETURN ( __MKEXTERNALADDRESS(stdout) ); |
18313 | 475 |
# endif |
10327 | 476 |
#endif |
5407 | 477 |
%} |
478 |
! |
|
479 |
||
613 | 480 |
initializeForStderr |
2965 | 481 |
"{ Pragma: +optSpace }" |
482 |
||
613 | 483 |
"setup for writing to stderr" |
269 | 484 |
|
20256 | 485 |
mode := #writeonly. "since stderr may be redirected to a pipe, reading is forbidden" |
613 | 486 |
buffered := false. |
20105 | 487 |
position := 0. "only writing - can keep track of position" |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
488 |
handle := self handleForStderr. |
12754 | 489 |
handleType := #filePointer. |
5407 | 490 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
20105 | 491 |
eolMode := #crlf |
5407 | 492 |
] |
613 | 493 |
! |
1 | 494 |
|
495 |
initializeForStdin |
|
2965 | 496 |
"{ Pragma: +optSpace }" |
497 |
||
44 | 498 |
"setup for reading stdin" |
499 |
||
1 | 500 |
mode := #readonly. |
6843
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
501 |
"/ buffered := true. |
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
502 |
buffered := false. |
20105 | 503 |
position := 0. "only reading - can keep track of position" |
12754 | 504 |
handleType := #filePointer. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
505 |
handle := self handleForStdin. |
1 | 506 |
! |
507 |
||
508 |
initializeForStdout |
|
2965 | 509 |
"{ Pragma: +optSpace }" |
510 |
||
44 | 511 |
"setup for writing to stdout" |
512 |
||
20105 | 513 |
mode := #writeonly. "since stdout may be redirected to a pipe, reading is forbidden" |
10 | 514 |
buffered := false. |
20105 | 515 |
position := 0. "only writing - can keep track of position" |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
516 |
handle := self handleForStdout. |
12754 | 517 |
handleType := #filePointer. |
5407 | 518 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
20105 | 519 |
eolMode := #crlf |
5407 | 520 |
] |
1 | 521 |
! |
522 |
||
523 |
reOpen |
|
2965 | 524 |
"{ Pragma: +optSpace }" |
525 |
||
44 | 526 |
"reopen the stream after an image restart. |
527 |
If I am one of the standard streams, reopen is easy" |
|
1 | 528 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
529 |
(self == StdInStream) ifTrue:[ |
177 | 530 |
^ self initializeForStdin |
1 | 531 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
532 |
(self == StdOutStream) ifTrue:[ |
177 | 533 |
^ self initializeForStdout |
1 | 534 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
535 |
(self == StdErrorStream) ifTrue:[ |
177 | 536 |
^ self initializeForStderr |
1 | 537 |
]. |
538 |
^ super reOpen |
|
539 |
! ! |
|
613 | 540 |
|
541 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
542 |
||
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
543 |
atEnd |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
544 |
"return true, if position is at end" |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
545 |
|
5918 | 546 |
(self == StdInStream) ifTrue:[ |
20225 | 547 |
OperatingSystem hasConsole ifFalse:[ |
548 |
^ true |
|
549 |
] |
|
5918 | 550 |
]. |
551 |
||
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
552 |
"first, wait to avoid blocking on the read. |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
553 |
On end of stream or error, readWait will return" |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
554 |
|
18798 | 555 |
self readWaitWithTimeoutMs:nil. |
20225 | 556 |
handle isNil ifTrue:[ |
557 |
"we were closed while waiting - so we are at the end" |
|
558 |
^ true. |
|
559 |
]. |
|
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
560 |
^ super atEnd. |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
561 |
! |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
562 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
563 |
collectionSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
564 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
565 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
566 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
567 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
568 |
|
5407 | 569 |
isPositionable |
570 |
"return true, if the stream supports positioning (this one is not)" |
|
571 |
||
572 |
^ false |
|
11455 | 573 |
! |
574 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
575 |
remainingSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
576 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
577 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
578 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
579 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
580 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
581 |
size |
11455 | 582 |
"we do not know our size" |
583 |
||
584 |
^ self positionError |
|
613 | 585 |
! ! |
586 |
||
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
587 |
!NonPositionableExternalStream methodsFor:'reading'! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
588 |
|
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
589 |
next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
590 |
"return the next element, if available. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
591 |
If nothing is available, this does never raise a read-beyond end signal. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
592 |
Instead, nil is returned immediately. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
593 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
594 |
Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
595 |
|
18798 | 596 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
597 |
^ super next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
598 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
599 |
|
20105 | 600 |
nextByte |
601 |
"redefined, to wait on pipes and sockets" |
|
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
602 |
|
18798 | 603 |
self readWaitWithTimeoutMs:nil. |
20105 | 604 |
^ super nextByte |
605 |
! |
|
606 |
||
607 |
nextLine |
|
608 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
609 |
character (i.e. read a single line of text). |
|
610 |
If the previous-to-last character is a cr, this is also removed, |
|
611 |
so it's possible to read alien (i.e. ms-dos) text as well. |
|
612 |
Redefined to not block forever if no cr is read." |
|
613 |
||
20175 | 614 |
|answerStream char wasBinary available "{ Class:SmallInteger }"| |
20105 | 615 |
|
20112 | 616 |
answerStream := WriteStream on:(String uninitializedNew:80). |
20105 | 617 |
[ |
618 |
available := self numAvailableForRead. |
|
20113 | 619 |
wasBinary := binary. "temporarily set to text mode" |
620 |
binary := false. |
|
20105 | 621 |
available timesRepeat:[ |
20148 | 622 |
char := super nextOrNil. "don't wait - we know that there is data" |
20105 | 623 |
char == Character cr ifTrue:[ |
624 |
(answerStream size ~~ 0 and:[answerStream last == Character return]) ifTrue:[ |
|
625 |
answerStream backStep. |
|
626 |
]. |
|
20113 | 627 |
binary := wasBinary. |
20105 | 628 |
^ answerStream contents. |
629 |
]. |
|
20256 | 630 |
char notNil ifTrue:[ |
20148 | 631 |
answerStream nextPut:char. |
632 |
]. |
|
20105 | 633 |
]. |
20113 | 634 |
binary := wasBinary. "restore saved mode" |
635 |
||
20105 | 636 |
"#atEnd waits for new data or EOF" |
637 |
self atEnd ifTrue:[ |
|
638 |
answerStream size == 0 ifTrue:[ |
|
639 |
^ self pastEndRead. |
|
640 |
]. |
|
641 |
^ answerStream contents. |
|
642 |
]. |
|
643 |
] loop. |
|
644 |
||
645 |
"not reached" |
|
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
646 |
! |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
647 |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
648 |
nextOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
649 |
"like #next, this returns the next element, if available. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
650 |
If nothing is available, this does never raise a read-beyond end signal. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
651 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
652 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
653 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
654 |
|
20680 | 655 |
self readWaitWithTimeoutMs:nil. |
656 |
handle isNil ifTrue:[ |
|
657 |
"we were closed while waiting - so we are at the end" |
|
658 |
^ nil. |
|
659 |
]. |
|
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
660 |
^ super nextOrNil |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
661 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
662 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
663 |
peek |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
664 |
"Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
665 |
|
18798 | 666 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
667 |
^ super peek |
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
668 |
! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
669 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
670 |
peekOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
671 |
"like #peek, this returns the next element, if available. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
672 |
If nothing is available, this does never raise a read-beyond end signal. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
673 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
674 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
675 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
676 |
|
20680 | 677 |
self readWaitWithTimeoutMs:nil. |
678 |
handle isNil ifTrue:[ |
|
679 |
"we were closed while waiting - so we are at the end" |
|
680 |
^ nil. |
|
681 |
]. |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
682 |
^ self peek |
18798 | 683 |
! |
684 |
||
20105 | 685 |
upTo:anObject into:aStream |
686 |
"read a collection of all objects up-to anObject and append these |
|
20256 | 687 |
elements to aStream, but excluding anObject. |
20105 | 688 |
The next read operation will return the element after anObject. |
689 |
(i.e. anObject is considered a separator, which is skipped) |
|
690 |
Similar to #through:, but the matching object is not included in the returned collection. |
|
691 |
If anObject is not encountered, all elements up to the end are read and returned. |
|
692 |
Compare this with #through: which also reads up to some object |
|
693 |
and also positions behind it, but DOES include it in the returned value." |
|
694 |
||
695 |
|element available "{ Class:SmallInteger }"| |
|
18798 | 696 |
|
20105 | 697 |
[ |
698 |
available := self numAvailableForRead. |
|
699 |
available timesRepeat:[ |
|
700 |
element := super next. "we know that there is data" |
|
701 |
element = anObject ifTrue:[ |
|
702 |
^ self. |
|
703 |
]. |
|
704 |
aStream nextPut:element. |
|
705 |
]. |
|
706 |
"#atEnd waits for new data or EOF" |
|
707 |
self atEnd ifTrue:[ |
|
708 |
^ self. |
|
709 |
]. |
|
710 |
] loop. |
|
711 |
||
712 |
"not reached" |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
713 |
! ! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
714 |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
715 |
!NonPositionableExternalStream methodsFor:'writing'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
716 |
|
17642
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
717 |
nextPutAll:aCollection |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
718 |
"nextPutBytes handles non-blocking io in receiver" |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
719 |
|
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
720 |
self nextPutBytes:aCollection size from:aCollection startingAt:1. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
721 |
^ self. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
722 |
! |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
723 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
724 |
nextPutAll:aCollection startingAt:start to:stop |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
725 |
"redefined, to wait until stream is writable, to avoid blocking in a write" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
726 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
727 |
|count| |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
728 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
729 |
count := stop-start+1. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
730 |
count ~= (self nextPutBytes:count from:aCollection startingAt:start) ifTrue:[ |
18313 | 731 |
"incomplete write" |
732 |
self writeError. |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
733 |
]. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
734 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
735 |
|
7679 | 736 |
nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset |
737 |
"redefined, to wait until stream is writable, to avoid blocking in a write" |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
738 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
739 |
|offset remaining wasBlocking| |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
740 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
741 |
offset := initialOffset. |
7679 | 742 |
remaining := initialWriteCount. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
743 |
|
7679 | 744 |
wasBlocking := self blocking:false. |
10327 | 745 |
[remaining ~~ 0] whileTrue:[ |
18313 | 746 |
|count| |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
747 |
|
18313 | 748 |
count := super nextPutBytes:remaining from:buffer startingAt:offset. |
7682
5d43745f59ac
only do a writeWait if previous non-blocking write failed to
Claus Gittinger <cg@exept.de>
parents:
7679
diff
changeset
|
749 |
|
18313 | 750 |
remaining := remaining - count. |
751 |
offset := offset + count. |
|
752 |
remaining ~~ 0 ifTrue:[ |
|
753 |
"Transcript showCR:'writeWait'." |
|
754 |
self writeWait. |
|
755 |
]. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
756 |
]. |
7679 | 757 |
wasBlocking ifTrue:[self blocking:true]. |
758 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
759 |
^ offset - initialOffset. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
760 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
761 |
|
1295 | 762 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
763 |
||
764 |
version |
|
18798 | 765 |
^ '$Header$' |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
766 |
! |
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
767 |
|
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
768 |
version_CVS |
18798 | 769 |
^ '$Header$' |
1295 | 770 |
! ! |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
771 |