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