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