author | Jan Vrany <jan.vrany@labware.com> |
Wed, 23 Jun 2021 12:50:05 +0100 | |
branch | jv |
changeset 25430 | acd92449dc30 |
parent 24087 | 4e07aa20b902 |
child 25462 | 548cb62b20c7 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
23107 | 3 |
COPYRIGHT (c) 2017 Jan Vrany |
177 | 4 |
All Rights Reserved |
1 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
5407 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
15 |
"{ NameSpace: Smalltalk }" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
16 |
|
1344
32a51164b237
No longer a subclass of UnboundedExternalStream, now subclass of ExternalStream.
Stefan Vogel <sv@exept.de>
parents:
1295
diff
changeset
|
17 |
ExternalStream subclass:#NonPositionableExternalStream |
1295 | 18 |
instanceVariableNames:'' |
19 |
classVariableNames:'StdInStream StdOutStream StdErrorStream' |
|
21784
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
20 |
poolDictionaries:'TTYConstants' |
1295 | 21 |
category:'Streams-External' |
1 | 22 |
! |
23 |
||
613 | 24 |
!NonPositionableExternalStream primitiveDefinitions! |
25 |
%{ |
|
2896 | 26 |
|
5918 | 27 |
#ifndef _STDIO_H_INCLUDED_ |
28 |
# include <stdio.h> |
|
29 |
# define _STDIO_H_INCLUDED_ |
|
30 |
#endif |
|
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3808
diff
changeset
|
31 |
|
10410 | 32 |
#ifndef REMOVE_LATER |
33 |
# define __win32_stdout() stdout |
|
34 |
# define __win32_stderr() stderr |
|
35 |
# define __win32_stdin() stdin |
|
36 |
#else |
|
37 |
extern FILE *__win32_stdin(); |
|
38 |
extern FILE *__win32_stderr(); |
|
39 |
extern FILE *__win32_stdout(); |
|
40 |
#endif |
|
41 |
||
613 | 42 |
%} |
43 |
||
44 |
! ! |
|
45 |
||
88 | 46 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
47 |
||
48 |
copyright |
|
49 |
" |
|
50 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
23107 | 51 |
COPYRIGHT (c) 2017 Jan Vrany |
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 |
|
20806 | 71 |
don't know what those are used for). These special streams are bound to |
177 | 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:] |
|
20806 | 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 |
|
21207 | 121 |
makeBidirectionalPipe |
122 |
"return an array with two streams - the first one for reading, |
|
123 |
the second for writing. |
|
124 |
This is the higher level equivalent of OperatingSystem>>makeBidirectionalPipe |
|
125 |
(which returns an array of file-descriptors)." |
|
126 |
||
127 |
|pipe rs ws| |
|
128 |
||
129 |
pipe := OperatingSystem makeBidirectionalPipe. |
|
130 |
pipe isNil ifTrue:[ |
|
131 |
"/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again |
|
132 |
'makePipe: enforcing finalization to close any open streams' infoPrintCR. |
|
133 |
ObjectMemory garbageCollect; finalize. |
|
134 |
pipe := OperatingSystem makeBidirectionalPipe. |
|
135 |
]. |
|
136 |
||
137 |
pipe isNil ifTrue:[ |
|
138 |
|errorNumber errorHolder| |
|
139 |
||
140 |
errorNumber := OperatingSystem lastErrorNumber. |
|
141 |
errorHolder := errorNumber. |
|
142 |
OpenError newException |
|
143 |
errorCode:errorNumber; |
|
144 |
osErrorHolder:errorHolder; |
|
145 |
raise. |
|
146 |
]. |
|
147 |
||
21227 | 148 |
rs := NonPositionableExternalStream forFileDescriptor:(pipe at:1) mode:#readWrite buffered:false handleType:#pipeFilePointer. |
149 |
ws := NonPositionableExternalStream forFileDescriptor:(pipe at:2) mode:#readWrite buffered:false handleType:#pipeFilePointer. |
|
21207 | 150 |
^ Array with:rs with:ws |
151 |
||
152 |
" |
|
153 |
|pipe rs ws| |
|
154 |
||
155 |
pipe := NonPositionableExternalStream makeBidirectionalPipe. |
|
156 |
rs := pipe at:1. |
|
157 |
ws := pipe at:2. |
|
158 |
||
159 |
'read ...'. |
|
160 |
[ |
|
161 |
1 to:10 do:[:i | |
|
162 |
Transcript showCR:rs nextLine |
|
163 |
]. |
|
164 |
rs close. |
|
165 |
] forkAt:7. |
|
166 |
||
167 |
'write ...'. |
|
168 |
[ |
|
169 |
1 to:10 do:[:i | |
|
170 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
171 |
]. |
|
172 |
ws close. |
|
173 |
] fork. |
|
174 |
" |
|
175 |
! |
|
176 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
177 |
makePTYPair |
10327 | 178 |
"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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
185 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
186 |
|ptyPair master slave| |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
187 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
188 |
ptyPair := OperatingSystem makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
189 |
ptyPair notNil ifTrue:[ |
21227 | 190 |
master := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyPair at:1). |
191 |
master buffered:false. |
|
192 |
slave := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyPair at:2). |
|
193 |
slave buffered:false. |
|
194 |
ptyPair at:1 put:master. |
|
195 |
ptyPair at:2 put:slave. |
|
196 |
^ ptyPair |
|
7497
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 |
^ nil |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
199 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
200 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
201 |
ExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
202 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
203 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
204 |
"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
|
205 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
206 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
207 |
makePipe |
10327 | 208 |
"return an array with two streams - the first one for reading, |
209 |
the second for writing. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
210 |
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
|
211 |
(which returns an array of file-descriptors)." |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
212 |
|
21230 | 213 |
|pipeArray rs ws| |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
214 |
|
21230 | 215 |
pipeArray := OperatingSystem makePipe. |
216 |
pipeArray isNil ifTrue:[ |
|
21207 | 217 |
"/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again |
218 |
'makePipe: enforcing finalization to close any open streams' infoPrintCR. |
|
219 |
ObjectMemory garbageCollect; finalize. |
|
21230 | 220 |
pipeArray := OperatingSystem makePipe. |
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
221 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
222 |
|
21230 | 223 |
pipeArray isNil ifTrue:[ |
21207 | 224 |
|errorNumber errorHolder| |
225 |
||
226 |
errorNumber := OperatingSystem lastErrorNumber. |
|
227 |
errorHolder := errorNumber. |
|
228 |
OpenError newException |
|
229 |
errorCode:errorNumber; |
|
230 |
osErrorHolder:errorHolder; |
|
231 |
raise. |
|
11907
98248eb75a8d
#retry makePipe after a failed try and garbageCollection
sr
parents:
11455
diff
changeset
|
232 |
]. |
21207 | 233 |
|
21230 | 234 |
rs := NonPositionableExternalStream forFileDescriptor:(pipeArray at:1) mode:#readonly buffered:false handleType:#pipeFilePointer. |
235 |
ws := NonPositionableExternalStream forFileDescriptor:(pipeArray at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer. |
|
21207 | 236 |
^ Array with:rs with:ws |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
237 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
238 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
239 |
|pipe rs ws| |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
240 |
|
7541 | 241 |
pipe := NonPositionableExternalStream makePipe. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
242 |
rs := pipe at:1. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
243 |
ws := pipe at:2. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
244 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
245 |
'read ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
246 |
[ |
21207 | 247 |
1 to:10 do:[:i | |
248 |
Transcript showCR:rs nextLine |
|
249 |
]. |
|
250 |
rs close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
251 |
] forkAt:7. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
252 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
253 |
'write ...'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
254 |
[ |
21207 | 255 |
1 to:10 do:[:i | |
256 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
257 |
]. |
|
258 |
ws close. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
259 |
] fork. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
260 |
" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
261 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
262 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
613 | 263 |
! ! |
264 |
||
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
265 |
!NonPositionableExternalStream methodsFor:'accessing'! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
266 |
|
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
267 |
buffered:aBoolean |
16348 | 268 |
"do not allow to change to buffered mode - ignore true here" |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
269 |
|
16348 | 270 |
aBoolean ifFalse:[ |
271 |
super buffered:false. |
|
272 |
]. |
|
21784
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
273 |
! |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
274 |
|
24087 | 275 |
setCommandString:dummyString |
276 |
"dummy for PipeStream compatibility" |
|
277 |
||
278 |
"Created: / 29-10-2018 / 18:06:44 / Claus Gittinger" |
|
279 |
! |
|
280 |
||
21784
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
281 |
getTTYAttributes |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
282 |
"Return (UNIX) TTY / PTY attributes for this stream as an instance of |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
283 |
UnixTerminalAttributes. Throw an error if terminal attributes cannot |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
284 |
be retrieved (OS call fails, stream does not refer to terminal or |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
285 |
opration is not supported by this operating system. |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
286 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
287 |
See tcgetattr() |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
288 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
289 |
^ OperatingSystem getTTYAttributes: self fileDescriptor |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
290 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
291 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
292 |
Stdout ttyAttributes |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
293 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
294 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
295 |
"Created: / 30-05-2017 / 20:55:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
296 |
! |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
297 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
298 |
setTTYAttributes: aUnixTerminalAttributes |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
299 |
"Set (UNIX) TTY / PTY attributes for this stream. Throw an error if |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
300 |
terminal attributes cannot be set (OS call fails, stream does not |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
301 |
refer to terminal or operation is not supported by this operating |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
302 |
system. |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
303 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
304 |
See tcsetattr() |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
305 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
306 |
^ OperatingSystem setTTYAttributes: self fileDescriptor to: aUnixTerminalAttributes withActions: TCSANOW |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
307 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
308 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
309 |
Stdout ttyAttributes |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
310 |
" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
311 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
312 |
"Created: / 30-05-2017 / 20:57:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
313 |
! ! |
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
314 |
|
613 | 315 |
!NonPositionableExternalStream methodsFor:'error handling'! |
316 |
||
317 |
positionError |
|
2965 | 318 |
"{ Pragma: +optSpace }" |
319 |
||
613 | 320 |
"notify that this stream has no concept of a position" |
321 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
7861
diff
changeset
|
322 |
^ PositionError raiseRequestWith:self |
4559 | 323 |
|
324 |
" |
|
325 |
Stderr positionError |
|
326 |
" |
|
19073 | 327 |
! |
328 |
||
329 |
writeError:errorNumber |
|
20256 | 330 |
"report an error, that some write error occurred. |
19073 | 331 |
Redefined to care for writeErrors on stdout and stderr, |
332 |
which happens under linux, if the console is closed while I am running. |
|
333 |
In this case, we ignore the error." |
|
334 |
||
335 |
((self == Stderr) or:[self == Stdout]) ifTrue:[ |
|
20256 | 336 |
^ self |
19073 | 337 |
]. |
338 |
super writeError:errorNumber |
|
613 | 339 |
! ! |
340 |
||
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
341 |
!NonPositionableExternalStream methodsFor:'initialization'! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
342 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
343 |
initialize |
16340
6203956d63ee
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16207
diff
changeset
|
344 |
"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
|
345 |
|
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
346 |
super initialize. |
20105 | 347 |
position := nil. "I am not positionable (reading and writing simultaneously)" |
15922 | 348 |
buffered := false. |
15919
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
349 |
! ! |
96f6c9fb9f7a
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15796
diff
changeset
|
350 |
|
20368 | 351 |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
352 |
!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
|
353 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
354 |
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
|
355 |
"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
|
356 |
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
|
357 |
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
|
358 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
359 |
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
|
360 |
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
|
361 |
|
8815 | 362 |
|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
|
363 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
364 |
count == 0 ifTrue:[ |
10327 | 365 |
^ 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
|
366 |
]. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
367 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
|
10327 | 371 |
[ |
372 |
nRead := self nextAvailableBytes:remaining into:anObject startingAt:offset. |
|
373 |
nRead == 0 ifTrue:[ |
|
374 |
"atEnd does a readWait" |
|
375 |
self atEnd not. |
|
376 |
] ifFalse:[ |
|
377 |
remaining := remaining - nRead. |
|
378 |
offset := offset + nRead. |
|
379 |
remaining ~~ 0. |
|
380 |
] |
|
7861
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
381 |
] whileTrue. |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
382 |
|
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
383 |
^ count - remaining |
20105 | 384 |
! |
385 |
||
386 |
nextInt16MSB:msbFlag |
|
387 |
"redefined to wait for data on pipes and sockets" |
|
388 |
||
389 |
|bytes nRead| |
|
390 |
||
391 |
bytes := ByteArray uninitializedNew:2. |
|
392 |
nRead := self nextBytes:2 into:bytes startingAt:1. |
|
393 |
nRead ~~ 2 ifTrue:[ |
|
394 |
^ self pastEndRead. |
|
395 |
]. |
|
396 |
^ bytes signedInt16At:1 MSB:msbFlag. |
|
397 |
! |
|
398 |
||
399 |
nextInt32MSB:msbFlag |
|
400 |
"redefined to wait for data on pipes and sockets" |
|
401 |
||
402 |
|bytes nRead| |
|
403 |
||
404 |
bytes := ByteArray uninitializedNew:4. |
|
405 |
nRead := self nextBytes:4 into:bytes startingAt:1. |
|
406 |
nRead ~~ 4 ifTrue:[ |
|
407 |
^ self pastEndRead. |
|
408 |
]. |
|
409 |
^ bytes signedInt32At:1 MSB:msbFlag. |
|
410 |
! |
|
411 |
||
21096 | 412 |
nextInt64MSB:msbFlag |
413 |
"redefined to wait for data on pipes and sockets" |
|
414 |
||
415 |
|bytes nRead| |
|
416 |
||
417 |
bytes := ByteArray uninitializedNew:8. |
|
418 |
nRead := self nextBytes:8 into:bytes startingAt:1. |
|
419 |
nRead ~~ 8 ifTrue:[ |
|
420 |
^ self pastEndRead. |
|
421 |
]. |
|
422 |
^ bytes signedInt64At:1 MSB:msbFlag. |
|
423 |
! |
|
424 |
||
20105 | 425 |
nextUnsignedInt16MSB:msbFlag |
426 |
"redefined to wait for data on pipes and sockets" |
|
427 |
||
428 |
|bytes nRead| |
|
429 |
||
21096 | 430 |
bytes := ByteArray uninitializedNew:2. |
20105 | 431 |
nRead := self nextBytes:2 into:bytes startingAt:1. |
432 |
nRead ~~ 2 ifTrue:[ |
|
433 |
^ self pastEndRead. |
|
434 |
]. |
|
435 |
^ bytes unsignedInt16At:1 MSB:msbFlag. |
|
436 |
! |
|
437 |
||
438 |
nextUnsignedInt32MSB:msbFlag |
|
439 |
"redefined to wait for data on pipes and sockets" |
|
440 |
||
441 |
|bytes nRead| |
|
442 |
||
443 |
bytes := ByteArray uninitializedNew:4. |
|
444 |
nRead := self nextBytes:4 into:bytes startingAt:1. |
|
445 |
nRead ~~ 4 ifTrue:[ |
|
446 |
^ self pastEndRead. |
|
447 |
]. |
|
448 |
^ bytes unsignedInt32At:1 MSB:msbFlag. |
|
21096 | 449 |
! |
450 |
||
451 |
nextUnsignedInt64MSB:msbFlag |
|
452 |
"redefined to wait for data on pipes and sockets" |
|
453 |
||
454 |
|bytes nRead| |
|
455 |
||
456 |
bytes := ByteArray uninitializedNew:8. |
|
457 |
nRead := self nextBytes:8 into:bytes startingAt:1. |
|
458 |
nRead ~~ 8 ifTrue:[ |
|
459 |
^ self pastEndRead. |
|
460 |
]. |
|
461 |
^ bytes unsignedInt64At: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
|
462 |
! ! |
9c2cd42e4667
Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents:
7682
diff
changeset
|
463 |
|
613 | 464 |
!NonPositionableExternalStream methodsFor:'positioning'! |
465 |
||
466 |
position |
|
20105 | 467 |
position isNil ifTrue:[ |
468 |
^ self positionError. |
|
469 |
]. |
|
470 |
^ position |
|
1 | 471 |
! |
472 |
||
20105 | 473 |
position:newPosition |
474 |
(position isNil or:[newPosition < position]) ifTrue:[ |
|
475 |
"there is no turning back" |
|
476 |
^ self positionError |
|
477 |
]. |
|
478 |
self skip:newPosition - position. |
|
613 | 479 |
! |
44 | 480 |
|
613 | 481 |
skip:numberToSkip |
7241 | 482 |
"skip count bytes/characters, return the receiver. |
483 |
Re-redefined since PositionableStream redefined it." |
|
613 | 484 |
|
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
485 |
"don't know how to unread ..." |
613 | 486 |
numberToSkip < 0 ifTrue:[ |
20105 | 487 |
^ self positionError. |
88 | 488 |
]. |
16207
923f92b4f0e8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16187
diff
changeset
|
489 |
numberToSkip timesRepeat:[self next]. |
4467 | 490 |
|
491 |
"Modified: / 30.7.1999 / 12:42:12 / cg" |
|
1 | 492 |
! ! |
493 |
||
177 | 494 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
495 |
||
496 |
printOn:aStream |
|
2965 | 497 |
"{ Pragma: +optSpace }" |
498 |
||
4392 | 499 |
"append a user printed representation of the receiver to aStream. |
500 |
The format is suitable for a human - not meant to be read back." |
|
177 | 501 |
|
2965 | 502 |
|myName| |
503 |
||
177 | 504 |
self == Stdin ifTrue:[ |
10327 | 505 |
myName := 'Stdin'. |
2965 | 506 |
] ifFalse:[ |
10327 | 507 |
self == Stdout ifTrue:[ |
508 |
myName := 'Stdout'. |
|
509 |
] ifFalse:[ |
|
510 |
self == Stderr ifTrue:[ |
|
511 |
myName := 'Stderr'. |
|
512 |
] |
|
513 |
] |
|
177 | 514 |
]. |
2965 | 515 |
|
516 |
myName notNil ifTrue:[ |
|
10327 | 517 |
aStream nextPutAll:myName. |
518 |
^ self |
|
177 | 519 |
]. |
520 |
super printOn:aStream |
|
521 |
! |
|
522 |
||
523 |
storeOn:aStream |
|
2965 | 524 |
"{ Pragma: +optSpace }" |
525 |
||
213 | 526 |
"append a printed representation of the receiver on aStream, from |
527 |
which the receiver can be reconstructed." |
|
177 | 528 |
|
529 |
((self == Stdin) |
|
530 |
or:[self == Stdout |
|
531 |
or:[self == Stderr]]) ifTrue:[ |
|
532 |
^ self printOn:aStream |
|
533 |
]. |
|
534 |
super storeOn:aStream |
|
535 |
! ! |
|
536 |
||
20680 | 537 |
!NonPositionableExternalStream protectedMethodsFor:'private'! |
538 |
||
539 |
closeFile |
|
540 |
|semasToSignal| |
|
541 |
||
542 |
handle notNil ifTrue:[ |
|
543 |
"make sure, that no select is performed on closed file descriptors" |
|
21239 | 544 |
semasToSignal := Processor disableFd:self fileHandle doSignal:false. |
20680 | 545 |
super closeFile. |
546 |
||
547 |
"tell the waiters that they must not wait any longer" |
|
548 |
semasToSignal do:[:eachSema| |
|
549 |
eachSema signalForAll. |
|
550 |
]. |
|
551 |
]. |
|
552 |
! ! |
|
553 |
||
613 | 554 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 555 |
|
5407 | 556 |
handleForStderr |
557 |
"{ Pragma: +optSpace }" |
|
558 |
||
559 |
"return a stderr handle" |
|
560 |
||
561 |
%{ |
|
18313 | 562 |
#ifdef __SCHTEAM__ |
563 |
return context._RETURN( StandardErrorStream ); |
|
564 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
565 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
566 |
RETURN ( __MKEXTERNALADDRESS( __win32_stderr() )); |
18313 | 567 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
568 |
RETURN ( __MKEXTERNALADDRESS(stderr) ); |
18313 | 569 |
# endif |
10327 | 570 |
#endif |
5407 | 571 |
%} |
572 |
! |
|
573 |
||
574 |
handleForStdin |
|
575 |
"{ Pragma: +optSpace }" |
|
576 |
||
577 |
"return a stdin handle" |
|
578 |
||
579 |
%{ |
|
18313 | 580 |
#ifdef __SCHTEAM__ |
581 |
return context._RETURN( StandardInputStream ); |
|
582 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
583 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
584 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdin() )); |
18313 | 585 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
586 |
RETURN ( __MKEXTERNALADDRESS(stdin) ); |
18313 | 587 |
# endif |
10327 | 588 |
#endif |
5407 | 589 |
%} |
590 |
! |
|
591 |
||
592 |
handleForStdout |
|
593 |
"{ Pragma: +optSpace }" |
|
594 |
||
595 |
"return a stdout handle" |
|
596 |
||
597 |
%{ |
|
18313 | 598 |
#ifdef __SCHTEAM__ |
599 |
return context._RETURN( StandardOutputStream ); |
|
600 |
#else |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19073
diff
changeset
|
601 |
# ifdef __win32__ |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
602 |
RETURN ( __MKEXTERNALADDRESS( __win32_stdout() )); |
18313 | 603 |
# else |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
604 |
RETURN ( __MKEXTERNALADDRESS(stdout) ); |
18313 | 605 |
# endif |
10327 | 606 |
#endif |
5407 | 607 |
%} |
608 |
! |
|
609 |
||
613 | 610 |
initializeForStderr |
2965 | 611 |
"{ Pragma: +optSpace }" |
612 |
||
613 | 613 |
"setup for writing to stderr" |
269 | 614 |
|
20256 | 615 |
mode := #writeonly. "since stderr may be redirected to a pipe, reading is forbidden" |
613 | 616 |
buffered := false. |
20105 | 617 |
position := 0. "only writing - can keep track of position" |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
618 |
handle := self handleForStderr. |
12754 | 619 |
handleType := #filePointer. |
5407 | 620 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
20105 | 621 |
eolMode := #crlf |
5407 | 622 |
] |
613 | 623 |
! |
1 | 624 |
|
625 |
initializeForStdin |
|
2965 | 626 |
"{ Pragma: +optSpace }" |
627 |
||
44 | 628 |
"setup for reading stdin" |
629 |
||
1 | 630 |
mode := #readonly. |
6843
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
631 |
"/ buffered := true. |
ef53f65b7364
stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents:
5918
diff
changeset
|
632 |
buffered := false. |
20105 | 633 |
position := 0. "only reading - can keep track of position" |
12754 | 634 |
handleType := #filePointer. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
635 |
handle := self handleForStdin. |
1 | 636 |
! |
637 |
||
638 |
initializeForStdout |
|
2965 | 639 |
"{ Pragma: +optSpace }" |
640 |
||
44 | 641 |
"setup for writing to stdout" |
642 |
||
20105 | 643 |
mode := #writeonly. "since stdout may be redirected to a pipe, reading is forbidden" |
10 | 644 |
buffered := false. |
20105 | 645 |
position := 0. "only writing - can keep track of position" |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
646 |
handle := self handleForStdout. |
12754 | 647 |
handleType := #filePointer. |
5407 | 648 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
20105 | 649 |
eolMode := #crlf |
5407 | 650 |
] |
1 | 651 |
! |
652 |
||
653 |
reOpen |
|
2965 | 654 |
"{ Pragma: +optSpace }" |
655 |
||
44 | 656 |
"reopen the stream after an image restart. |
657 |
If I am one of the standard streams, reopen is easy" |
|
1 | 658 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
659 |
(self == StdInStream) ifTrue:[ |
177 | 660 |
^ self initializeForStdin |
1 | 661 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
662 |
(self == StdOutStream) ifTrue:[ |
177 | 663 |
^ self initializeForStdout |
1 | 664 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
665 |
(self == StdErrorStream) ifTrue:[ |
177 | 666 |
^ self initializeForStderr |
1 | 667 |
]. |
668 |
^ super reOpen |
|
669 |
! ! |
|
613 | 670 |
|
671 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
672 |
||
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
673 |
atEnd |
21028 | 674 |
"return true, if position is at end. |
675 |
Notice: this is a blocking operation, as we do not know in advance, |
|
676 |
if there will be anything to read |
|
677 |
(i.e. if the partner will send more or close the stream). |
|
678 |
If you want to check for available data, |
|
679 |
use nextAvailable:, or canReadWithoutBlocking" |
|
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
680 |
|
5918 | 681 |
(self == StdInStream) ifTrue:[ |
20225 | 682 |
OperatingSystem hasConsole ifFalse:[ |
683 |
^ true |
|
684 |
] |
|
5918 | 685 |
]. |
686 |
||
20685 | 687 |
handle notNil ifTrue:[ |
688 |
"first, wait to avoid blocking on the read. |
|
689 |
On end of stream or error, readWait will return" |
|
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
690 |
|
20685 | 691 |
self readWaitWithTimeoutMs:nil. |
692 |
]. |
|
20225 | 693 |
handle isNil ifTrue:[ |
20685 | 694 |
"we are closed or were closed while waiting - so we are at the end" |
20225 | 695 |
^ true. |
696 |
]. |
|
5851
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
697 |
^ super atEnd. |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
698 |
! |
6823cc642d60
only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
699 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
700 |
collectionSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
701 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
702 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
703 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
704 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
705 |
|
5407 | 706 |
isPositionable |
707 |
"return true, if the stream supports positioning (this one is not)" |
|
708 |
||
709 |
^ false |
|
11455 | 710 |
! |
711 |
||
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
712 |
remainingSize |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
713 |
"we do not know our size" |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
714 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
715 |
^ self positionError |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
716 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
717 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11907
diff
changeset
|
718 |
size |
11455 | 719 |
"we do not know our size" |
720 |
||
721 |
^ self positionError |
|
613 | 722 |
! ! |
723 |
||
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
724 |
!NonPositionableExternalStream methodsFor:'reading'! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
725 |
|
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
726 |
next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
727 |
"return the next element, if available. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
728 |
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
|
729 |
Instead, nil is returned immediately. |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
730 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
731 |
Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
732 |
|
18798 | 733 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
734 |
^ super next |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
735 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
736 |
|
20105 | 737 |
nextByte |
738 |
"redefined, to wait on pipes and sockets" |
|
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
739 |
|
18798 | 740 |
self readWaitWithTimeoutMs:nil. |
20105 | 741 |
^ super nextByte |
742 |
! |
|
743 |
||
744 |
nextLine |
|
745 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
746 |
character (i.e. read a single line of text). |
|
747 |
If the previous-to-last character is a cr, this is also removed, |
|
748 |
so it's possible to read alien (i.e. ms-dos) text as well. |
|
749 |
Redefined to not block forever if no cr is read." |
|
750 |
||
20175 | 751 |
|answerStream char wasBinary available "{ Class:SmallInteger }"| |
20105 | 752 |
|
20112 | 753 |
answerStream := WriteStream on:(String uninitializedNew:80). |
20105 | 754 |
[ |
21131 | 755 |
"#atEnd waits for new data or EOF" |
756 |
self atEnd ifTrue:[ |
|
757 |
answerStream size == 0 ifTrue:[ |
|
758 |
^ self pastEndRead. |
|
759 |
]. |
|
760 |
^ answerStream contents. |
|
761 |
]. |
|
20105 | 762 |
available := self numAvailableForRead. |
21131 | 763 |
available == 0 ifTrue:[ |
764 |
"so #atEnd didn't wait above, but no data is present - check for error" |
|
765 |
self peek. |
|
766 |
available := self numAvailableForRead. |
|
767 |
]. |
|
768 |
||
20113 | 769 |
wasBinary := binary. "temporarily set to text mode" |
770 |
binary := false. |
|
20105 | 771 |
available timesRepeat:[ |
20148 | 772 |
char := super nextOrNil. "don't wait - we know that there is data" |
20105 | 773 |
char == Character cr ifTrue:[ |
774 |
(answerStream size ~~ 0 and:[answerStream last == Character return]) ifTrue:[ |
|
775 |
answerStream backStep. |
|
776 |
]. |
|
20113 | 777 |
binary := wasBinary. |
20105 | 778 |
^ answerStream contents. |
779 |
]. |
|
20256 | 780 |
char notNil ifTrue:[ |
20148 | 781 |
answerStream nextPut:char. |
782 |
]. |
|
20105 | 783 |
]. |
20113 | 784 |
binary := wasBinary. "restore saved mode" |
20105 | 785 |
] loop. |
786 |
||
787 |
"not reached" |
|
15796
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
788 |
! |
b3fdd3c2aec2
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
15720
diff
changeset
|
789 |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
790 |
nextOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
791 |
"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
|
792 |
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
|
793 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
794 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
795 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
796 |
|
20680 | 797 |
self readWaitWithTimeoutMs:nil. |
798 |
handle isNil ifTrue:[ |
|
799 |
"we were closed while waiting - so we are at the end" |
|
800 |
^ nil. |
|
801 |
]. |
|
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
802 |
^ super nextOrNil |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
803 |
! |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
804 |
|
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
805 |
peek |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
806 |
"Redefined, to wait on pipes and sockets" |
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
807 |
|
18798 | 808 |
self readWaitWithTimeoutMs:nil. |
14758
6a70a7006093
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
12754
diff
changeset
|
809 |
^ super peek |
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
810 |
! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
811 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
812 |
peekOrNil |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
813 |
"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
|
814 |
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
|
815 |
Instead, nil is returned immediately. |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
816 |
|
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
817 |
Redefined, to wait on pipes and sockets" |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
818 |
|
20680 | 819 |
self readWaitWithTimeoutMs:nil. |
820 |
handle isNil ifTrue:[ |
|
821 |
"we were closed while waiting - so we are at the end" |
|
822 |
^ nil. |
|
823 |
]. |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
824 |
^ self peek |
18798 | 825 |
! |
826 |
||
20105 | 827 |
upTo:anObject into:aStream |
828 |
"read a collection of all objects up-to anObject and append these |
|
20256 | 829 |
elements to aStream, but excluding anObject. |
20105 | 830 |
The next read operation will return the element after anObject. |
831 |
(i.e. anObject is considered a separator, which is skipped) |
|
832 |
Similar to #through:, but the matching object is not included in the returned collection. |
|
833 |
If anObject is not encountered, all elements up to the end are read and returned. |
|
834 |
Compare this with #through: which also reads up to some object |
|
835 |
and also positions behind it, but DOES include it in the returned value." |
|
836 |
||
837 |
|element available "{ Class:SmallInteger }"| |
|
18798 | 838 |
|
20105 | 839 |
[ |
21131 | 840 |
"#atEnd waits for new data or EOF" |
841 |
self atEnd ifTrue:[ |
|
842 |
^ self. |
|
843 |
]. |
|
20105 | 844 |
available := self numAvailableForRead. |
21131 | 845 |
available == 0 ifTrue:[ |
846 |
"so #atEnd didn't wait above, but no data is present - check for error" |
|
847 |
self peek. |
|
848 |
available := self numAvailableForRead. |
|
849 |
]. |
|
850 |
||
20105 | 851 |
available timesRepeat:[ |
852 |
element := super next. "we know that there is data" |
|
853 |
element = anObject ifTrue:[ |
|
854 |
^ self. |
|
855 |
]. |
|
856 |
aStream nextPut:element. |
|
857 |
]. |
|
858 |
] loop. |
|
859 |
||
860 |
"not reached" |
|
10349
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
861 |
! ! |
cbfa00bba11d
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10327
diff
changeset
|
862 |
|
21784
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
863 |
!NonPositionableExternalStream methodsFor:'testing'! |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
864 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
865 |
isTTY |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
866 |
"Return true if receiver refers to TTY / PTY, false otherwise." |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
867 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
868 |
^ OperatingSystem isTTY: self fileDescriptor |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
869 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
870 |
"Created: / 30-05-2017 / 16:46:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
871 |
! ! |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
872 |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
873 |
!NonPositionableExternalStream methodsFor:'writing'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
874 |
|
17642
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
875 |
nextPutAll:aCollection |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
876 |
"nextPutBytes handles non-blocking io in receiver" |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
877 |
|
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
878 |
self nextPutBytes:aCollection size from:aCollection startingAt:1. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
879 |
^ self. |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
880 |
! |
5988beff84f7
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
17607
diff
changeset
|
881 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
882 |
nextPutAll:aCollection startingAt:start to:stop |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
883 |
"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
|
884 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
885 |
|count| |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
886 |
|
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
887 |
count := stop-start+1. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
888 |
count ~= (self nextPutBytes:count from:aCollection startingAt:start) ifTrue:[ |
18313 | 889 |
"incomplete write" |
890 |
self writeError. |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
891 |
]. |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
892 |
! |
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
893 |
|
7679 | 894 |
nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset |
895 |
"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
|
896 |
|
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
897 |
|offset remaining wasBlocking| |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
898 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
899 |
offset := initialOffset. |
7679 | 900 |
remaining := initialWriteCount. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
901 |
|
7679 | 902 |
wasBlocking := self blocking:false. |
10327 | 903 |
[remaining ~~ 0] whileTrue:[ |
18313 | 904 |
|count| |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
905 |
|
18313 | 906 |
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
|
907 |
|
18313 | 908 |
remaining := remaining - count. |
909 |
offset := offset + count. |
|
910 |
remaining ~~ 0 ifTrue:[ |
|
911 |
"Transcript showCR:'writeWait'." |
|
912 |
self writeWait. |
|
913 |
]. |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
914 |
]. |
7679 | 915 |
wasBlocking ifTrue:[self blocking:true]. |
916 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
917 |
^ offset - initialOffset. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
918 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7241
diff
changeset
|
919 |
|
1295 | 920 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
921 |
||
922 |
version |
|
18798 | 923 |
^ '$Header$' |
12677
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
924 |
! |
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
925 |
|
aeab74b04f0b
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
12395
diff
changeset
|
926 |
version_CVS |
18798 | 927 |
^ '$Header$' |
21784
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
928 |
! |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
929 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
930 |
version_HG |
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
931 |
|
d58698c455c1
UNIX: added support for TTY / PTY attributes (`tdgetattr()` & `tcsetattr()`)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21285
diff
changeset
|
932 |
^ '$Changeset: <not expanded> $' |
1295 | 933 |
! ! |
17607
224f253b60c8
class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
16348
diff
changeset
|
934 |