author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 23 Jan 2016 07:23:05 +0000 | |
branch | jv |
changeset 19103 | 71257a47eba2 |
parent 18800 | 02724cc719b6 |
parent 19073 | adceca67c57b |
child 19863 | 513bd7237fe7 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
177 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
5407 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
15 |
|
1344
32a51164b237
No longer a subclass of UnboundedExternalStream, now subclass of ExternalStream.
Stefan Vogel <sv@exept.de>
parents:
1295
diff
changeset
|
16 |
ExternalStream subclass:#NonPositionableExternalStream |
1295 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'StdInStream StdOutStream StdErrorStream' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Streams-External' |
|
1 | 21 |
! |
22 |
||
613 | 23 |
!NonPositionableExternalStream primitiveDefinitions! |
24 |
%{ |
|
2896 | 25 |
|
5918 | 26 |
#ifndef _STDIO_H_INCLUDED_ |
27 |
# include <stdio.h> |
|
28 |
# define _STDIO_H_INCLUDED_ |
|
29 |
#endif |
|
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3808
diff
changeset
|
30 |
|
10410 | 31 |
#ifndef REMOVE_LATER |
32 |
# define __win32_stdout() stdout |
|
33 |
# define __win32_stderr() stderr |
|
34 |
# define __win32_stdin() stdin |
|
35 |
#else |
|
36 |
extern FILE *__win32_stdin(); |
|
37 |
extern FILE *__win32_stderr(); |
|
38 |
extern FILE *__win32_stdout(); |
|
39 |
#endif |
|
40 |
||
613 | 41 |
%} |
42 |
||
43 |
! ! |
|
44 |
||
88 | 45 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
46 |
||
47 |
copyright |
|
48 |
" |
|
49 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
177 | 50 |
All Rights Reserved |
88 | 51 |
|
52 |
This software is furnished under a license and may be used |
|
53 |
only in accordance with the terms of that license and with the |
|
54 |
inclusion of the above copyright notice. This software may not |
|
55 |
be provided or otherwise made available to, or used by, any |
|
56 |
other person. No title to or ownership of the software is |
|
57 |
hereby transferred. |
|
58 |
" |
|
59 |
! |
|
60 |
||
61 |
documentation |
|
62 |
" |
|
63 |
This class provides common protocol for all non-positionable, |
|
64 |
external streams. Concrete subclasses are terminal streams, pipe streams, |
|
65 |
PrinterStreams, Sockets etc. |
|
66 |
||
67 |
There are three special instances of this class, representing stdin, |
|
68 |
stdout and stderr of the smalltalk/X process (see Unix manuals, if you |
|
177 | 69 |
dont know what those are used for). These special streams are bound to |
70 |
to globals Stdin, Stdout and Stderr at early initialization time |
|
71 |
(see Smalltalk>>initializeStandardStreams). |
|
159 | 72 |
|
73 |
The name of this class is a historical leftover - it should be called |
|
74 |
'TTYStream' or similar. |
|
1295 | 75 |
|
76 |
[author:] |
|
3808
5a7866138026
set eolMode of stderr & stdout to #crlf under win32
Claus Gittinger <cg@exept.de>
parents:
3173
diff
changeset
|
77 |
Claus Gittinger |
88 | 78 |
" |
216 | 79 |
! ! |
80 |
||
1 | 81 |
!NonPositionableExternalStream class methodsFor:'instance creation'! |
82 |
||
613 | 83 |
forStderr |
2965 | 84 |
"{ Pragma: +optSpace }" |
85 |
||
613 | 86 |
"return a NonPositionableExternalStream object for writing to |
87 |
Unixes standard error output file descriptor" |
|
88 |
||
89 |
StdErrorStream isNil ifTrue:[ |
|
90 |
StdErrorStream := self basicNew initializeForStderr |
|
91 |
]. |
|
92 |
^ StdErrorStream |
|
93 |
! |
|
94 |
||
1 | 95 |
forStdin |
2965 | 96 |
"{ Pragma: +optSpace }" |
97 |
||
44 | 98 |
"return a NonPositionableExternalStream object for reading from |
99 |
Unixes standard input file descriptor" |
|
100 |
||
88 | 101 |
StdInStream isNil ifTrue:[ |
177 | 102 |
StdInStream := self basicNew initializeForStdin |
88 | 103 |
]. |
104 |
^ StdInStream |
|
1 | 105 |
! |
106 |
||
107 |
forStdout |
|
2965 | 108 |
"{ Pragma: +optSpace }" |
109 |
||
44 | 110 |
"return a NonPositionableExternalStream object for writing to |
111 |
Unixes standard output file descriptor" |
|
112 |
||
88 | 113 |
StdOutStream isNil ifTrue:[ |
177 | 114 |
StdOutStream := self basicNew initializeForStdout |
88 | 115 |
]. |
116 |
^ StdOutStream |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
117 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
118 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
119 |
makePTYPair |
10327 | 120 |
"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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
127 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
128 |
|ptyPair master slave| |
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 := OperatingSystem makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
131 |
ptyPair notNil ifTrue:[ |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
132 |
master := self forReadWriteToFileDescriptor:(ptyPair at:1). |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
133 |
master buffered:false. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
134 |
slave := self forReadWriteToFileDescriptor:(ptyPair at:2). |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
135 |
slave buffered:false. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
136 |
ptyPair at:1 put:master. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
137 |
ptyPair at:2 put:slave. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
138 |
^ ptyPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
139 |
]. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
140 |
^ nil |
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 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
143 |
ExternalStream makePTYPair. |
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 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
146 |
"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
|
147 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
148 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
149 |
makePipe |
10327 | 150 |
"return an array with two streams - the first one for reading, |
151 |
the second for writing. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
152 |
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
|
153 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
154 |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
155 |
|pipe rs ws| |
7497
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 := OperatingSystem makePipe. |
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
158 |
pipe isNil ifTrue:[ |
16348 | 159 |
"/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again |
160 |
'makePipe: enforcing finalization to close any open streams' infoPrintCR. |
|
161 |
ObjectMemory garbageCollect; finalize. |
|
162 |
pipe := OperatingSystem makePipe. |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
163 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
164 |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
165 |
pipe notNil ifTrue:[ |
16348 | 166 |
rs := self forFileDescriptor:(pipe at:1) mode:#readonly buffered:false handleType:#pipeFilePointer. |
167 |
ws := self forFileDescriptor:(pipe at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer. |
|
168 |
^ Array with:rs with:ws |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
169 |
]. |
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
170 |
^ nil |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
171 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
172 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
173 |
|pipe rs ws| |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
174 |
|
7541 | 175 |
pipe := NonPositionableExternalStream makePipe. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
176 |
rs := pipe at:1. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
177 |
ws := pipe at:2. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
178 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
179 |
'read ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
180 |
[ |
16348 | 181 |
1 to:10 do:[:i | |
182 |
Transcript showCR:rs nextLine |
|
183 |
]. |
|
184 |
rs close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
185 |
] forkAt:7. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
186 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
187 |
'write ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
188 |
[ |
16348 | 189 |
1 to:10 do:[:i | |
190 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
191 |
]. |
|
192 |
ws close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
193 |
] fork. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
194 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
195 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
196 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
613 | 197 |
! ! |
198 |
||
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
199 |
!NonPositionableExternalStream methodsFor:'accessing'! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
200 |
|
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
201 |
buffered:aBoolean |
16348 | 202 |
"do not allow to change to buffered mode - ignore true here" |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
203 |
|
16348 | 204 |
aBoolean ifFalse:[ |
205 |
super buffered:false. |
|
206 |
]. |
|
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
207 |
! ! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
208 |
|
613 | 209 |
!NonPositionableExternalStream methodsFor:'error handling'! |
210 |
||
211 |
positionError |
|
2965 | 212 |
"{ Pragma: +optSpace }" |
213 |
||
613 | 214 |
"notify that this stream has no concept of a position" |
215 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
7861
diff
changeset
|
216 |
^ PositionError raiseRequestWith:self |
4559 | 217 |
|
218 |
" |
|
219 |
Stderr positionError |
|
220 |
" |
|
19073 | 221 |
! |
222 |
||
223 |
writeError:errorNumber |
|
224 |
"report an error, that some write error occured. |
|
225 |
Redefined to care for writeErrors on stdout and stderr, |
|
226 |
which happens under linux, if the console is closed while I am running. |
|
227 |
In this case, we ignore the error." |
|
228 |
||
229 |
((self == Stderr) or:[self == Stdout]) ifTrue:[ |
|
230 |
^ self |
|
231 |
]. |
|
232 |
super writeError:errorNumber |
|
613 | 233 |
! ! |
234 |
||
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
235 |
!NonPositionableExternalStream methodsFor:'initialization'! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
236 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
237 |
initialize |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
238 |
"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
|
239 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
240 |
super initialize. |
15922 | 241 |
buffered := false. |
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
242 |
! ! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
243 |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
244 |
!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
|
245 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
246 |
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
|
247 |
"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
|
248 |
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
|
249 |
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
|
250 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
|
8815 | 254 |
|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
|
255 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
256 |
count == 0 ifTrue:[ |
10327 | 257 |
^ 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
|
258 |
]. |
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 |
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
|
261 |
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
|
262 |
|
10327 | 263 |
[ |
264 |
nRead := self nextAvailableBytes:remaining into:anObject startingAt:offset. |
|
265 |
nRead == 0 ifTrue:[ |
|
266 |
"atEnd does a readWait" |
|
267 |
self atEnd not. |
|
268 |
] ifFalse:[ |
|
269 |
remaining := remaining - nRead. |
|
270 |
offset := offset + nRead. |
|
271 |
remaining ~~ 0. |
|
272 |
] |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
273 |
] whileTrue. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
274 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
275 |
^ count - remaining |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
276 |
! ! |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
277 |
|
613 | 278 |
!NonPositionableExternalStream methodsFor:'positioning'! |
279 |
||
280 |
position |
|
2965 | 281 |
"{ Pragma: +optSpace }" |
282 |
||
613 | 283 |
"catch position - there is none here" |
284 |
||
285 |
^ self positionError |
|
1 | 286 |
! |
287 |
||
613 | 288 |
position:aPosition |
2965 | 289 |
"{ Pragma: +optSpace }" |
290 |
||
613 | 291 |
"catch position - there is none here" |
292 |
||
293 |
^ self positionError |
|
294 |
! |
|
44 | 295 |
|
613 | 296 |
skip:numberToSkip |
7241 | 297 |
"skip count bytes/characters, return the receiver. |
298 |
Re-redefined since PositionableStream redefined it." |
|
613 | 299 |
|
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
300 |
"don't know how to unread ..." |
613 | 301 |
numberToSkip < 0 ifTrue:[ |
16348 | 302 |
PositionError raiseRequest. |
303 |
^ self |
|
88 | 304 |
]. |
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
305 |
numberToSkip timesRepeat:[self next]. |
4467 | 306 |
|
307 |
"Modified: / 30.7.1999 / 12:42:12 / cg" |
|
1 | 308 |
! ! |
309 |
||
177 | 310 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
311 |
||
312 |
printOn:aStream |
|
2965 | 313 |
"{ Pragma: +optSpace }" |
314 |
||
4392 | 315 |
"append a user printed representation of the receiver to aStream. |
316 |
The format is suitable for a human - not meant to be read back." |
|
177 | 317 |
|
2965 | 318 |
|myName| |
319 |
||
177 | 320 |
self == Stdin ifTrue:[ |
10327 | 321 |
myName := 'Stdin'. |
2965 | 322 |
] ifFalse:[ |
10327 | 323 |
self == Stdout ifTrue:[ |
324 |
myName := 'Stdout'. |
|
325 |
] ifFalse:[ |
|
326 |
self == Stderr ifTrue:[ |
|
327 |
myName := 'Stderr'. |
|
328 |
] |
|
329 |
] |
|
177 | 330 |
]. |
2965 | 331 |
|
332 |
myName notNil ifTrue:[ |
|
10327 | 333 |
aStream nextPutAll:myName. |
334 |
^ self |
|
177 | 335 |
]. |
336 |
super printOn:aStream |
|
337 |
! |
|
338 |
||
339 |
storeOn:aStream |
|
2965 | 340 |
"{ Pragma: +optSpace }" |
341 |
||
213 | 342 |
"append a printed representation of the receiver on aStream, from |
343 |
which the receiver can be reconstructed." |
|
177 | 344 |
|
345 |
((self == Stdin) |
|
346 |
or:[self == Stdout |
|
347 |
or:[self == Stderr]]) ifTrue:[ |
|
348 |
^ self printOn:aStream |
|
349 |
]. |
|
350 |
super storeOn:aStream |
|
351 |
! ! |
|
352 |
||
613 | 353 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 354 |
|
5407 | 355 |
handleForStderr |
356 |
"{ Pragma: +optSpace }" |
|
357 |
||
358 |
"return a stderr handle" |
|
359 |
||
360 |
%{ |
|
18313 | 361 |
#ifdef __SCHTEAM__ |
362 |
return context._RETURN( StandardErrorStream ); |
|
363 |
#else |
|
364 |
# ifdef WIN32 |
|
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
365 |
RETURN ( __MKEXTERNALADDRESS( __win32_stderr() )); |
18313 | 366 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
367 |
RETURN ( __MKEXTERNALADDRESS(stderr) ); |
18313 | 368 |
# endif |
10327 | 369 |
#endif |
5407 | 370 |
%} |
371 |
! |
|
372 |
||
373 |
handleForStdin |
|
374 |
"{ Pragma: +optSpace }" |
|
375 |
||
376 |
"return a stdin handle" |
|
377 |
||
378 |
%{ |
|
18313 | 379 |
#ifdef __SCHTEAM__ |
380 |
return context._RETURN( StandardInputStream ); |
|
381 |
#else |
|
382 |
# ifdef WIN32 |
|
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
383 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdin() )); |
18313 | 384 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
385 |
RETURN ( __MKEXTERNALADDRESS(stdin) ); |
18313 | 386 |
# endif |
10327 | 387 |
#endif |
5407 | 388 |
%} |
389 |
! |
|
390 |
||
391 |
handleForStdout |
|
392 |
"{ Pragma: +optSpace }" |
|
393 |
||
394 |
"return a stdout handle" |
|
395 |
||
396 |
%{ |
|
18313 | 397 |
#ifdef __SCHTEAM__ |
398 |
return context._RETURN( StandardOutputStream ); |
|
399 |
#else |
|
400 |
# ifdef WIN32 |
|
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
401 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdout() )); |
18313 | 402 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
403 |
RETURN ( __MKEXTERNALADDRESS(stdout) ); |
18313 | 404 |
# endif |
10327 | 405 |
#endif |
5407 | 406 |
%} |
407 |
! |
|
408 |
||
613 | 409 |
initializeForStderr |
2965 | 410 |
"{ Pragma: +optSpace }" |
411 |
||
613 | 412 |
"setup for writing to stderr" |
269 | 413 |
|
613 | 414 |
mode := #readwrite. |
415 |
buffered := false. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
416 |
handle := self handleForStderr. |
12754 | 417 |
handleType := #filePointer. |
5407 | 418 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
16348 | 419 |
eolMode := #crlf |
5407 | 420 |
] |
613 | 421 |
! |
1 | 422 |
|
423 |
initializeForStdin |
|
2965 | 424 |
"{ Pragma: +optSpace }" |
425 |
||
44 | 426 |
"setup for reading stdin" |
427 |
||
1 | 428 |
mode := #readonly. |
6843
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
429 |
"/ buffered := true. |
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
430 |
buffered := false. |
12754 | 431 |
handleType := #filePointer. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
432 |
handle := self handleForStdin. |
1 | 433 |
! |
434 |
||
435 |
initializeForStdout |
|
2965 | 436 |
"{ Pragma: +optSpace }" |
437 |
||
44 | 438 |
"setup for writing to stdout" |
439 |
||
1 | 440 |
mode := #readwrite. |
10 | 441 |
buffered := false. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
442 |
handle := self handleForStdout. |
12754 | 443 |
handleType := #filePointer. |
5407 | 444 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
16348 | 445 |
eolMode := #crlf |
5407 | 446 |
] |
1 | 447 |
! |
448 |
||
449 |
reOpen |
|
2965 | 450 |
"{ Pragma: +optSpace }" |
451 |
||
44 | 452 |
"reopen the stream after an image restart. |
453 |
If I am one of the standard streams, reopen is easy" |
|
1 | 454 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
455 |
(self == StdInStream) ifTrue:[ |
177 | 456 |
^ self initializeForStdin |
1 | 457 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
458 |
(self == StdOutStream) ifTrue:[ |
177 | 459 |
^ self initializeForStdout |
1 | 460 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
461 |
(self == StdErrorStream) ifTrue:[ |
177 | 462 |
^ self initializeForStderr |
1 | 463 |
]. |
464 |
^ super reOpen |
|
465 |
! ! |
|
613 | 466 |
|
467 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
468 |
||
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
469 |
atEnd |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
470 |
"return true, if position is at end" |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
471 |
|
5918 | 472 |
(self == StdInStream) ifTrue:[ |
18798 | 473 |
OperatingSystem hasConsole ifFalse:[ |
474 |
^ true |
|
475 |
] |
|
5918 | 476 |
]. |
477 |
||
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
478 |
"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
|
479 |
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
|
480 |
|
18798 | 481 |
self readWaitWithTimeoutMs:nil. |
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
482 |
^ super atEnd. |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
483 |
! |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
484 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
485 |
collectionSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
486 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
487 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
488 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
489 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
490 |
|
5407 | 491 |
isPositionable |
492 |
"return true, if the stream supports positioning (this one is not)" |
|
493 |
||
494 |
^ false |
|
11455 | 495 |
! |
496 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
497 |
remainingSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
498 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
499 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
500 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
501 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
502 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
503 |
size |
11455 | 504 |
"we do not know our size" |
505 |
||
506 |
^ self positionError |
|
613 | 507 |
! ! |
508 |
||
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
509 |
!NonPositionableExternalStream methodsFor:'reading'! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
510 |
|
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
511 |
next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
512 |
"return the next element, if available. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
513 |
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
|
514 |
Instead, nil is returned immediately. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
515 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
516 |
Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
517 |
|
18798 | 518 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
519 |
^ super next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
520 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
521 |
|
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
522 |
nextLine |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
523 |
"Redefined, to wait on pipes and sockets" |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
524 |
|
18798 | 525 |
self readWaitWithTimeoutMs:nil. |
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
526 |
^ super nextLine |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
527 |
! |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
528 |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
529 |
nextOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
530 |
"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
|
531 |
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
|
532 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
533 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
534 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
535 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
536 |
self atEnd ifTrue:[^ nil]. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
537 |
^ super nextOrNil |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
538 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
539 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
540 |
peek |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
541 |
"Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
542 |
|
18798 | 543 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
544 |
^ super peek |
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
545 |
! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
546 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
547 |
peekOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
548 |
"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
|
549 |
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
|
550 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
551 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
552 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
553 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
554 |
self atEnd ifTrue:[^ nil]. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
555 |
^ self peek |
18798 | 556 |
! |
557 |
||
558 |
readWaitWithTimeoutMs:millisecondsOrNil |
|
559 |
"cannot do a readWait (which means possible suspend), |
|
560 |
if the processor is not yet initialized; i.e. if a read is attempted |
|
561 |
during early startup. |
|
562 |
This may happen, for example, if a MiniDebugger is entered, before |
|
563 |
process scheduling has been setup. |
|
564 |
In this case, all I/O operations here will be blocking." |
|
565 |
||
566 |
Smalltalk isInitialized ifFalse:[ ^ false ]. |
|
567 |
^ super readWaitWithTimeoutMs:millisecondsOrNil |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
568 |
! ! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
569 |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
570 |
!NonPositionableExternalStream methodsFor:'writing'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
571 |
|
17642
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
572 |
nextPutAll:aCollection |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
573 |
"nextPutBytes handles non-blocking io in receiver" |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
574 |
|
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
575 |
self nextPutBytes:aCollection size from:aCollection startingAt:1. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
576 |
^ self. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
577 |
! |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
578 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
579 |
nextPutAll:aCollection startingAt:start to:stop |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
580 |
"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
|
581 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
582 |
|count| |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
583 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
584 |
count := stop-start+1. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
585 |
count ~= (self nextPutBytes:count from:aCollection startingAt:start) ifTrue:[ |
18313 | 586 |
"incomplete write" |
587 |
self writeError. |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
588 |
]. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
589 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
590 |
|
7679 | 591 |
nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset |
592 |
"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
|
593 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
594 |
|offset remaining wasBlocking| |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
595 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
596 |
offset := initialOffset. |
7679 | 597 |
remaining := initialWriteCount. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
598 |
|
7679 | 599 |
wasBlocking := self blocking:false. |
10327 | 600 |
[remaining ~~ 0] whileTrue:[ |
18313 | 601 |
|count| |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
602 |
|
18313 | 603 |
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
|
604 |
|
18313 | 605 |
remaining := remaining - count. |
606 |
offset := offset + count. |
|
607 |
remaining ~~ 0 ifTrue:[ |
|
608 |
"Transcript showCR:'writeWait'." |
|
609 |
self writeWait. |
|
610 |
]. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
611 |
]. |
7679 | 612 |
wasBlocking ifTrue:[self blocking:true]. |
613 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
614 |
^ offset - initialOffset. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
615 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
616 |
|
1295 | 617 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
618 |
||
619 |
version |
|
18798 | 620 |
^ '$Header$' |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
621 |
! |
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
622 |
|
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
623 |
version_CVS |
18798 | 624 |
^ '$Header$' |
1295 | 625 |
! ! |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
626 |