NonPositionableExternalStream.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Apr 2020 16:22:26 +0200
changeset 25375 b784fc06a5eb
parent 25322 33036e5651e0
permissions -rw-r--r--
#REFACTORING by stefan class: KeyedCollection class added: #newWithCapacity:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23901
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
     1
"{ Encoding: utf8 }"
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
    14
"{ Package: 'stx:libbasic' }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
    15
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
    16
"{ NameSpace: Smalltalk }"
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
    17
1344
32a51164b237 No longer a subclass of UnboundedExternalStream, now subclass of ExternalStream.
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
    18
ExternalStream subclass:#NonPositionableExternalStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	instanceVariableNames:''
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
    20
	classVariableNames:'StdErrorStream StdInStream StdOutStream'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    21
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    22
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    25
!NonPositionableExternalStream primitiveDefinitions!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    26
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 1344
diff changeset
    27
5918
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
    28
#ifndef _STDIO_H_INCLUDED_
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
    29
# include <stdio.h>
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
    30
# define _STDIO_H_INCLUDED_
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
    31
#endif
3956
51f1a9a4d63f changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents: 3808
diff changeset
    32
10410
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    33
#ifndef REMOVE_LATER
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    34
# define __win32_stdout()        stdout
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    35
# define __win32_stderr()        stderr
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    36
# define __win32_stdin()         stdin
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    37
#else
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    38
    extern FILE *__win32_stdin();
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    39
    extern FILE *__win32_stderr();
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    40
    extern FILE *__win32_stdout();
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    41
#endif
822f8baf6eaa *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10349
diff changeset
    42
613
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
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    45
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    46
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    47
!NonPositionableExternalStream class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    48
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    49
copyright
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    50
"
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    51
 COPYRIGHT (c) 1989 by Claus Gittinger
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
    52
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    53
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    54
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    55
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    56
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    57
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    58
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    59
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    60
"
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    61
!
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    62
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    63
documentation
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    64
"
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    65
    This class provides common protocol for all non-positionable,
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    66
    external streams. Concrete subclasses are terminal streams, pipe streams,
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    67
    PrinterStreams, Sockets etc.
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    68
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    69
    There are three special instances of this class, representing stdin,
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    70
    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
    71
    don't know what those are used for). These special streams are bound to
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
    72
    to globals Stdin, Stdout and Stderr at early initialization time
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
    73
    (see Smalltalk>>initializeStandardStreams).
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    74
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    75
    The name of this class is a historical leftover - it should be called
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    76
    'TTYStream' or similar.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    77
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    78
    [author:]
20806
729f94d21909 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20685
diff changeset
    79
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
    80
"
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    81
! !
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    82
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
!NonPositionableExternalStream class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    85
forStderr
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    86
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    87
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    88
    "return a NonPositionableExternalStream object for writing to
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    89
     Unixes standard error output file descriptor"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    90
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    91
    StdErrorStream isNil ifTrue:[
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    92
	StdErrorStream := self basicNew initializeForStderr
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
    ^ StdErrorStream
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    95
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    96
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
forStdin
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    98
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    99
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   100
    "return a NonPositionableExternalStream object for reading from
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   101
     Unixes standard input file descriptor"
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   102
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   103
    StdInStream isNil ifTrue:[
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   104
	StdInStream := self basicNew initializeForStdin
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   105
    ].
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   106
    ^ StdInStream
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   107
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
a27a279701f8 Initial revision
claus
parents:
diff changeset
   109
forStdout
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   110
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   111
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   112
    "return a NonPositionableExternalStream object for writing to
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   113
     Unixes standard output file descriptor"
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   114
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   115
    StdOutStream isNil ifTrue:[
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   116
	StdOutStream := self basicNew initializeForStdout
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   117
    ].
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   118
    ^ StdOutStream
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   119
!
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   120
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   121
makeBidirectionalPipe
24602
cf345afadfb0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23901
diff changeset
   122
    "return an array with two streams for communication in both directions.
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   123
     This is the higher level equivalent of OperatingSystem>>makeBidirectionalPipe
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   124
     (which returns an array of file-descriptors)."
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   125
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   126
    |pipe rs ws|
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   127
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   128
    "/ must protect from being unwound, otherwise the pipe-FD might not be registered for finalization
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   129
    [
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   130
        pipe := OperatingSystem makeBidirectionalPipe.
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   131
        pipe isNil ifTrue:[
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   132
            "/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again
24602
cf345afadfb0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23901
diff changeset
   133
            Logger info:'makePipe: enforcing finalization to close any open streams'.
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   134
            ObjectMemory garbageCollect; finalize.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   135
            pipe := OperatingSystem makeBidirectionalPipe.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   136
            pipe isNil ifTrue:[
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   137
                |errorNumber errorHolder|
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   138
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   139
                errorNumber := OperatingSystem lastErrorNumber.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   140
                errorHolder := errorNumber.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   141
                OpenError newException
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   142
                    errorCode:errorNumber;
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   143
                    osErrorHolder:errorHolder;
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   144
                    raise.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   145
            ].
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   146
        ].
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   147
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   148
        rs := PipeStream forFileDescriptor:(pipe at:1) mode:#readWrite buffered:false handleType:#pipeFilePointer.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   149
        ws := PipeStream forFileDescriptor:(pipe at:2) mode:#readWrite buffered:false handleType:#pipeFilePointer.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   150
    ] valueUninterruptably.
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   151
    ^ Array with:rs with:ws
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   152
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   153
    "
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   154
     |pipe rs ws|
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   155
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   156
     pipe := NonPositionableExternalStream makeBidirectionalPipe.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   157
     rs := pipe at:1.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   158
     ws := pipe at:2.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   159
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   160
     'read ...'.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   161
     [
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   162
         1 to:10 do:[:i |
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   163
             Transcript showCR:rs nextLine
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   164
         ].
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   165
         rs close.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   166
     ] forkAt:7.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   167
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   168
     'write ...'.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   169
     [
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   170
         1 to:10 do:[:i |
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   171
             ws nextPutAll:'hello world '; nextPutAll:i printString; cr
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   172
         ].
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   173
         ws close.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   174
     ] fork.
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   175
    "
23485
aecf0f68402c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22954
diff changeset
   176
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   177
    "Modified: / 04-11-2018 / 11:19:35 / Claus Gittinger"
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   178
!
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   179
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   180
makePTYPair
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   181
    "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
   182
     the second the slave of a ptym/ptys pair.
23779
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   183
     (actually, there is a third element, which is the slave-pty's name)
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   184
     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
   185
     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
   186
     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
   187
     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
   188
     (which returns an array of file-descriptors)."
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   189
24719
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   190
    |ptyPair master slave ptyName|
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   191
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   192
    "/ must protect from being unwound, otherwise the pipe-FD might not be registered for finalization
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   193
    [
23779
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   194
        ptyPair := OperatingSystem makePTY.
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   195
        ptyPair notNil ifTrue:[
24719
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   196
            master := self 
23779
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   197
                        forFileDescriptor:(ptyPair at:1) mode:#readWrite
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   198
                        buffered:false handleType:nil.
24719
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   199
            slave := self 
23779
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   200
                        forFileDescriptor:(ptyPair at:2) mode:#readWrite
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   201
                        buffered:false handleType:nil.
24719
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   202
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   203
            (ptyName := ptyPair at:3 ifAbsent:nil) notNil ifTrue:[
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   204
                master setCommandString:ptyName.
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   205
                slave setCommandString:ptyName.
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   206
            ].
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   207
            slave buffered:false.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   208
            ptyPair at:1 put:master.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   209
            ptyPair at:2 put:slave.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   210
        ]
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   211
    ] valueUninterruptably.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   212
    ^ ptyPair
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   213
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   214
    "
24719
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   215
     UnixPTYStream makePTYPair.
22c0d19e7761 #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24638
diff changeset
   216
     PipeStream makePTYPair.
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   217
    "
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   218
23487
e9e4dd2d6325 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23485
diff changeset
   219
    "Modified: / 29-02-1996 / 18:28:36 / cg"
23779
123904e24d2a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23503
diff changeset
   220
    "Modified (comment): / 27-02-2019 / 18:49:46 / Claus Gittinger"
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   221
!
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   222
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   223
makePipe
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   224
    "return an array with two streams - the first one for reading,
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   225
     the second for writing.
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   226
     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
   227
     (which returns an array of file-descriptors)."
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   228
21230
9b7a6559527b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21227
diff changeset
   229
    |pipeArray rs ws|
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   230
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   231
    "/ must protect from being unwound, otherwise the pipe-FD might not be registered for finalization
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   232
    [
21230
9b7a6559527b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21227
diff changeset
   233
        pipeArray := OperatingSystem makePipe.
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   234
        pipeArray isNil ifTrue:[
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   235
            "/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   236
            'makePipe: enforcing finalization to close any open streams' infoPrintCR.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   237
            ObjectMemory garbageCollect; finalize.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   238
            pipeArray := OperatingSystem makePipe.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   239
            pipeArray isNil ifTrue:[
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   240
                |errorNumber errorHolder|
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   241
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   242
                errorNumber := OperatingSystem lastErrorNumber.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   243
                errorHolder := errorNumber.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   244
                OpenError newException
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   245
                    errorCode:errorNumber;
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   246
                    osErrorHolder:errorHolder;
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   247
                    raise.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   248
            ].
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   249
        ].
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   250
        rs := PipeStream forFileDescriptor:(pipeArray at:1) mode:#readonly buffered:false handleType:#pipeFilePointer.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   251
        ws := PipeStream forFileDescriptor:(pipeArray at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer.
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   252
    ] valueUninterruptably.
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   253
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   254
    ^ Array with:rs with:ws
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   255
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   256
    "
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   257
     |pipe rs ws|
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   258
7541
e980e3695dee Fix comments
Stefan Vogel <sv@exept.de>
parents: 7501
diff changeset
   259
     pipe := NonPositionableExternalStream makePipe.
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   260
     rs := pipe at:1.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   261
     ws := pipe at:2.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   262
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   263
     'read ...'.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   264
     [
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   265
         1 to:10 do:[:i |
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   266
             Transcript showCR:rs nextLine
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   267
         ].
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   268
         rs close.
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   269
     ] forkAt:7.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   270
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   271
     'write ...'.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   272
     [
21207
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   273
         1 to:10 do:[:i |
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   274
             ws nextPutAll:'hello world '; nextPutAll:i printString; cr
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   275
         ].
604babfb83ef #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21131
diff changeset
   276
         ws close.
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   277
     ] fork.
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   278
    "
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   279
23485
aecf0f68402c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22954
diff changeset
   280
    "Modified: / 29-02-1996 / 18:28:36 / cg"
23503
4c61c48be58c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23489
diff changeset
   281
    "Modified (format): / 04-11-2018 / 11:17:48 / Claus Gittinger"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   282
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   283
16340
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   284
!NonPositionableExternalStream methodsFor:'accessing'!
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   285
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   286
buffered:aBoolean
16348
7860486a31a0 Fix #buffered:
Stefan Vogel <sv@exept.de>
parents: 16340
diff changeset
   287
    "do not allow to change to buffered mode - ignore true here"
16340
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   288
16348
7860486a31a0 Fix #buffered:
Stefan Vogel <sv@exept.de>
parents: 16340
diff changeset
   289
    aBoolean ifFalse:[
23901
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
   290
        super buffered:false.
16348
7860486a31a0 Fix #buffered:
Stefan Vogel <sv@exept.de>
parents: 16340
diff changeset
   291
    ].
23901
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
   292
    ^ false
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
   293
f6e98ee5be18 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23779
diff changeset
   294
    "Modified: / 13-03-2019 / 19:33:55 / Stefan Vogel"
23489
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   295
!
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   296
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   297
setCommandString:dummyString
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   298
    "dummy for PipeStream compatibility"
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   299
24720
1f02c362969c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24719
diff changeset
   300
    "/ intentionally ignore here
1f02c362969c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24719
diff changeset
   301
    ^ self
1f02c362969c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24719
diff changeset
   302
23489
7973350d82f8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23487
diff changeset
   303
    "Created: / 29-10-2018 / 18:06:44 / Claus Gittinger"
16340
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   304
! !
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   305
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   306
!NonPositionableExternalStream methodsFor:'error handling'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   307
22192
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   308
errorNotOpen
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   309
    "report an error, that the stream has not been opened or has been closed.
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   310
     Redefined to care for closed stdout and stderr,
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   311
     which happens, if the console is closed while I am running.
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   312
     In this case, we ignore the error."
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   313
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   314
    ((self == Stderr) or:[self == Stdout]) ifTrue:[
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   315
        ^ self
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   316
    ].
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   317
    ^ super errorNotOpen
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   318
!
3e27b5e2db40 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21750
diff changeset
   319
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   320
positionError
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   321
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   322
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   323
    "notify that this stream has no concept of a position"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   324
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 7861
diff changeset
   325
    ^ PositionError raiseRequestWith:self
4559
7b454e1d1265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4467
diff changeset
   326
7b454e1d1265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4467
diff changeset
   327
    "
7b454e1d1265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4467
diff changeset
   328
     Stderr positionError
7b454e1d1265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4467
diff changeset
   329
    "
19073
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   330
!
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   331
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   332
writeError:errorNumber
20256
b706cfe3d902 #OTHER by mawalch
mawalch
parents: 20225
diff changeset
   333
    "report an error, that some write error occurred.
19073
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   334
     Redefined to care for writeErrors on stdout and stderr,
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   335
     which happens under linux, if the console is closed while I am running.
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   336
     In this case, we ignore the error."
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   337
22541
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   338
"/ No!! this causes nextPutAll: to loop forever, since there are always bytes remaining
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   339
"/
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   340
"/    ((self == Stderr) or:[self == Stdout]) ifTrue:[
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   341
"/        ^ self
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   342
"/    ].
19073
adceca67c57b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18798
diff changeset
   343
    super writeError:errorNumber
22541
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   344
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   345
    "Modified: / 09-02-2018 / 20:33:30 / stefan"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   346
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   347
15919
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   348
!NonPositionableExternalStream methodsFor:'initialization'!
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   349
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   350
initialize
16340
6203956d63ee class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16207
diff changeset
   351
    "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
   352
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   353
    super initialize.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   354
    position := nil.    "I am not positionable (reading and writing simultaneously)"
15922
af9427f065b7 initialize methods
Stefan Vogel <sv@exept.de>
parents: 15919
diff changeset
   355
    buffered := false.
15919
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   356
! !
96f6c9fb9f7a Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 15796
diff changeset
   357
20368
843040f392e1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20256
diff changeset
   358
7861
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   359
!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
   360
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   361
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
   362
    "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
   363
     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
   364
     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
   365
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   366
     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
   367
     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
   368
8815
88c21d3f2c9c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   369
    |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
   370
21750
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   371
    count == 0 ifTrue:[ ^ 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
   372
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   373
    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
   374
    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
   375
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   376
    [
21750
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   377
        nRead := self nextAvailableBytes:remaining into:anObject startingAt:offset.
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   378
        nRead == 0 ifTrue:[
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   379
            "atEnd does a readWait"
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   380
            (self atEnd) ifTrue:[^ count - remaining]
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   381
        ] ifFalse:[
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   382
            remaining := remaining - nRead.
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   383
            (remaining == 0) ifTrue:[^ count].
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   384
            offset := offset + nRead.
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   385
        ]
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   386
    ] loop.
7861
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   387
21750
b048d7e7b343 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21702
diff changeset
   388
    "Modified (format): / 16-05-2017 / 12:10:25 / cg"
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   389
!
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   390
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   391
nextInt16MSB:msbFlag
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   392
    "redefined to wait for data on pipes and sockets"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   393
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   394
    |bytes nRead|
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   395
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   396
    bytes := ByteArray uninitializedNew:2.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   397
    nRead := self nextBytes:2 into:bytes startingAt:1.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   398
    nRead ~~ 2 ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   399
        ^ self pastEndRead.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   400
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   401
    ^ bytes signedInt16At:1 MSB:msbFlag.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   402
!
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   403
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   404
nextInt32MSB:msbFlag
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   405
    "redefined to wait for data on pipes and sockets"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   406
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   407
    |bytes nRead|
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   408
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   409
    bytes := ByteArray uninitializedNew:4.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   410
    nRead := self nextBytes:4 into:bytes startingAt:1.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   411
    nRead ~~ 4 ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   412
        ^ self pastEndRead.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   413
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   414
    ^ bytes signedInt32At:1 MSB:msbFlag.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   415
!
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   416
21096
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   417
nextInt64MSB:msbFlag
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   418
    "redefined to wait for data on pipes and sockets"
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   419
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   420
    |bytes nRead|
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   421
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   422
    bytes := ByteArray uninitializedNew:8.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   423
    nRead := self nextBytes:8 into:bytes startingAt:1.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   424
    nRead ~~ 8 ifTrue:[
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   425
        ^ self pastEndRead.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   426
    ].
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   427
    ^ bytes signedInt64At:1 MSB:msbFlag.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   428
!
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   429
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   430
nextUnsignedInt16MSB:msbFlag
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   431
    "redefined to wait for data on pipes and sockets"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   432
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   433
    |bytes nRead|
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   434
21096
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   435
    bytes := ByteArray uninitializedNew:2.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   436
    nRead := self nextBytes:2 into:bytes startingAt:1.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   437
    nRead ~~ 2 ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   438
        ^ self pastEndRead.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   439
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   440
    ^ bytes unsignedInt16At:1 MSB:msbFlag.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   441
!
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   442
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   443
nextUnsignedInt32MSB:msbFlag
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   444
    "redefined to wait for data on pipes and sockets"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   445
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   446
    |bytes nRead|
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   447
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   448
    bytes := ByteArray uninitializedNew:4.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   449
    nRead := self nextBytes:4 into:bytes startingAt:1.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   450
    nRead ~~ 4 ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   451
        ^ self pastEndRead.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   452
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   453
    ^ bytes unsignedInt32At:1 MSB:msbFlag.
21096
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   454
!
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   455
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   456
nextUnsignedInt64MSB:msbFlag
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   457
    "redefined to wait for data on pipes and sockets"
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   458
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   459
    |bytes nRead|
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   460
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   461
    bytes := ByteArray uninitializedNew:8.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   462
    nRead := self nextBytes:8 into:bytes startingAt:1.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   463
    nRead ~~ 8 ifTrue:[
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   464
        ^ self pastEndRead.
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   465
    ].
b14f363d7d3b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21056
diff changeset
   466
    ^ 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
   467
! !
9c2cd42e4667 Provide a #nextBytes:into:startingAt: that does not block the whole ST/X
Stefan Vogel <sv@exept.de>
parents: 7682
diff changeset
   468
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   469
!NonPositionableExternalStream methodsFor:'positioning'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   470
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   471
position
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   472
    position isNil ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   473
        ^ self positionError.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   474
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   475
    ^ position
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   477
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   478
position:newPosition
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   479
    (position isNil or:[newPosition < position]) ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   480
        "there is no turning back"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   481
        ^ self positionError
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   482
    ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   483
    self skip:newPosition - position.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   484
!
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   485
22954
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   486
setToEnd
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   487
    "skip to the end of stream."
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   488
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   489
    [self nextOrNil notNil] whileTrue.
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   490
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   491
    "Created: / 18-05-2018 / 14:07:36 / Stefan Vogel"
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   492
!
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   493
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   494
skip:numberToSkip
7241
06359d192b65 comment
Claus Gittinger <cg@exept.de>
parents: 6843
diff changeset
   495
    "skip count bytes/characters, return the receiver.
06359d192b65 comment
Claus Gittinger <cg@exept.de>
parents: 6843
diff changeset
   496
     Re-redefined since PositionableStream redefined it."
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   497
16207
923f92b4f0e8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16187
diff changeset
   498
    "don't know how to unread ..."
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   499
    numberToSkip < 0 ifTrue:[
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   500
        ^ self positionError.
88
81dacba7a63a *** empty log message ***
claus
parents: 44
diff changeset
   501
    ].
16207
923f92b4f0e8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16187
diff changeset
   502
    numberToSkip timesRepeat:[self next].
4467
8ddf534d7d81 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   503
8ddf534d7d81 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   504
    "Modified: / 30.7.1999 / 12:42:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   505
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   506
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   507
!NonPositionableExternalStream methodsFor:'printing & storing'!
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   508
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   509
printOn:aStream
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   510
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   511
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
   512
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
   513
     The format is suitable for a human - not meant to be read back."
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   514
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   515
    |myName|
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   516
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   517
    self == Stdin ifTrue:[
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   518
	myName := 'Stdin'.
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   519
    ] ifFalse:[
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   520
	self == Stdout ifTrue:[
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   521
	    myName := 'Stdout'.
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   522
	] ifFalse:[
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   523
	    self == Stderr ifTrue:[
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   524
		myName := 'Stderr'.
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   525
	    ]
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   526
	]
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   527
    ].
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   528
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   529
    myName notNil ifTrue:[
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   530
	aStream nextPutAll:myName.
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   531
	^ self
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   532
    ].
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   533
    super printOn:aStream
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   534
!
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   535
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   536
storeOn:aStream
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   537
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   538
213
3b56a17534fd *** empty log message ***
claus
parents: 177
diff changeset
   539
    "append a printed representation of the receiver on aStream, from
3b56a17534fd *** empty log message ***
claus
parents: 177
diff changeset
   540
     which the receiver can be reconstructed."
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   541
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   542
    ((self == Stdin)
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   543
    or:[self == Stdout
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   544
    or:[self == Stderr]]) ifTrue:[
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   545
	^ self printOn:aStream
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   546
    ].
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   547
    super storeOn:aStream
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   548
! !
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   549
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   550
!NonPositionableExternalStream protectedMethodsFor:'private'!
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   551
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   552
closeFile
21687
79b0c824468e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21361
diff changeset
   553
    <resource: #PRIVATE>
79b0c824468e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21361
diff changeset
   554
    
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   555
    |semasToSignal fd|
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   556
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   557
    fd := self fileHandle.
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   558
    fd notNil ifTrue:[
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   559
        "make sure, that no select is performed on closed file descriptors"
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   560
        semasToSignal := Processor disableFd:fd doSignal:false.
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   561
        super closeFile.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   562
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   563
        "tell the waiters that they must not wait any longer"
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   564
        semasToSignal do:[:eachSema|
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   565
            eachSema signalForAll.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   566
        ].
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   567
    ].
21687
79b0c824468e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21361
diff changeset
   568
79b0c824468e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21361
diff changeset
   569
    "Modified: / 07-04-2017 / 14:32:00 / cg"
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   570
    "Modified: / 04-03-2020 / 14:52:38 / Stefan Vogel"
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   571
! !
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   572
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   573
!NonPositionableExternalStream methodsFor:'private'!
360
claus
parents: 269
diff changeset
   574
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   575
handleForStderr
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   576
    "{ Pragma: +optSpace }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   577
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   578
    "return a stderr handle"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   579
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   580
%{
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   581
#ifdef __SCHTEAM__
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   582
    return context._RETURN( StandardErrorStream );
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   583
#else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19073
diff changeset
   584
# ifdef __win32__
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   585
    RETURN ( __MKEXTERNALADDRESS( __win32_stderr() ));
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   586
# else
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   587
    RETURN ( __MKEXTERNALADDRESS(stderr) );
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   588
# endif
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   589
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   590
%}
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   591
!
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   592
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   593
handleForStdin
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   594
    "{ Pragma: +optSpace }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   595
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   596
    "return a stdin handle"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   597
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   598
%{
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   599
#ifdef __SCHTEAM__
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   600
    return context._RETURN( StandardInputStream );
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   601
#else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19073
diff changeset
   602
# ifdef __win32__
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   603
    RETURN ( __MKEXTERNALADDRESS( __win32_stdin() ));
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   604
# else
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   605
    RETURN ( __MKEXTERNALADDRESS(stdin) );
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   606
# endif
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   607
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   608
%}
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   609
!
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   610
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   611
handleForStdout
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   612
    "{ Pragma: +optSpace }"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   613
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   614
    "return a stdout handle"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   615
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   616
%{
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   617
#ifdef __SCHTEAM__
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   618
    return context._RETURN( StandardOutputStream );
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   619
#else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19073
diff changeset
   620
# ifdef __win32__
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   621
    RETURN ( __MKEXTERNALADDRESS( __win32_stdout() ));
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   622
# else
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
   623
    RETURN ( __MKEXTERNALADDRESS(stdout) );
18313
6df1638c8e2d comments only
Claus Gittinger <cg@exept.de>
parents: 17642
diff changeset
   624
# endif
10327
c7bb805fa32c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8815
diff changeset
   625
#endif
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   626
%}
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   627
!
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   628
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   629
initializeForStderr
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   630
    "setup for writing to stderr"
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   631
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   632
    "{ Pragma: +optSpace }"
269
93162487a94b *** empty log message ***
claus
parents: 216
diff changeset
   633
20256
b706cfe3d902 #OTHER by mawalch
mawalch
parents: 20225
diff changeset
   634
    mode := #writeonly. "since stderr may be redirected to a pipe, reading is forbidden"
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   635
    binary := false.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   636
    buffered := false.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   637
    position := 0.      "only writing - can keep track of position"
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11907
diff changeset
   638
    handle := self handleForStderr.
12754
25745c828a99 changed:
Stefan Vogel <sv@exept.de>
parents: 12708
diff changeset
   639
    handleType := #filePointer.
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   640
    hitEOF := false.
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   641
    self initializeEOLMode.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   642
    OperatingSystem isMSWINDOWSlike ifTrue:[
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   643
        eolMode := #crlf
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   644
    ].
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   645
    "This will possibly never be finalized, but keep in in Lobby
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   646
     to make #openStreams work"
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   647
    self registerForFinalization.
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   648
    "#registerForFinalization sets #preventTenueOf:, but I live forever..."
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   649
    ObjectMemory allowTenureOf:self.
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   650
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   651
    "Modified: / 25-04-2017 / 02:13:56 / cg"
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   652
    "Modified (comment): / 24-04-2018 / 10:28:50 / stefan"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   653
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   654
a27a279701f8 Initial revision
claus
parents:
diff changeset
   655
initializeForStdin
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   656
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   657
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   658
    "setup for reading stdin"
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   659
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
    mode := #readonly.
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   661
    binary := false.
6843
ef53f65b7364 stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents: 5918
diff changeset
   662
    "/ buffered := true.
ef53f65b7364 stdout/err must not be buffered (sending prompts without NL)
Claus Gittinger <cg@exept.de>
parents: 5918
diff changeset
   663
    buffered := false.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   664
    position := 0.      "only reading - can keep track of position"
12754
25745c828a99 changed:
Stefan Vogel <sv@exept.de>
parents: 12708
diff changeset
   665
    handleType := #filePointer.
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11907
diff changeset
   666
    handle := self handleForStdin.
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   667
    hitEOF := false.
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   668
    self initializeEOLMode.
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   669
    "This will possibly never be finalized, but keep in in Lobby
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   670
     to make #openStreams work"
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   671
    self registerForFinalization.
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   672
    "#registerForFinalization sets #preventTenueOf:, but I live forever..."
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   673
    ObjectMemory allowTenureOf:self.
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   674
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   675
    "Modified: / 25-04-2017 / 02:14:22 / cg"
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   676
    "Modified (comment): / 24-04-2018 / 10:28:43 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   677
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   678
a27a279701f8 Initial revision
claus
parents:
diff changeset
   679
initializeForStdout
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   680
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   681
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   682
    "setup for writing to stdout"
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   683
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   684
    mode := #writeonly. "since stdout may be redirected to a pipe, reading is forbidden"
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   685
    binary := false.
10
claus
parents: 5
diff changeset
   686
    buffered := false.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   687
    position := 0.      "only writing - can keep track of position"
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11907
diff changeset
   688
    handle := self handleForStdout.
12754
25745c828a99 changed:
Stefan Vogel <sv@exept.de>
parents: 12708
diff changeset
   689
    handleType := #filePointer.
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   690
    self initializeEOLMode.
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   691
    hitEOF := false.
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   692
    OperatingSystem isMSWINDOWSlike ifTrue:[
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   693
        eolMode := #crlf
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   694
    ].
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   695
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   696
    "This will possibly never be finalized, but keep in in Lobby
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   697
     to make #openStreams work"
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   698
    self registerForFinalization.
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   699
    "#registerForFinalization sets #preventTenueOf:, but I live forever..."
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   700
    ObjectMemory allowTenureOf:self.
21701
81f076cefc80 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21687
diff changeset
   701
21702
5c05820b761f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21701
diff changeset
   702
    "Modified: / 25-04-2017 / 02:14:27 / cg"
22702
d347a51bef9c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 22541
diff changeset
   703
    "Modified (comment): / 24-04-2018 / 10:28:38 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   704
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   705
a27a279701f8 Initial revision
claus
parents:
diff changeset
   706
reOpen
2965
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   707
    "{ Pragma: +optSpace }"
c5d6d02b0e8c lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   708
44
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   709
    "reopen the stream after an image restart.
b262907c93ea *** empty log message ***
claus
parents: 10
diff changeset
   710
     If I am one of the standard streams, reopen is easy"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   711
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   712
    (self == StdInStream) ifTrue:[
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   713
	^ self initializeForStdin
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
    ].
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   715
    (self == StdOutStream) ifTrue:[
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   716
	^ self initializeForStdout
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   717
    ].
477
8710aba7876b oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents: 475
diff changeset
   718
    (self == StdErrorStream) ifTrue:[
177
c9f8a4bc4b10 better printString & storeString
claus
parents: 159
diff changeset
   719
	^ self initializeForStderr
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   720
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   721
    ^ super reOpen
a27a279701f8 Initial revision
claus
parents:
diff changeset
   722
! !
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   723
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   724
!NonPositionableExternalStream methodsFor:'queries'!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   725
5851
6823cc642d60 only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
   726
atEnd
21028
986bb2a74ac2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20806
diff changeset
   727
    "return true, if position is at end.
986bb2a74ac2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20806
diff changeset
   728
     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
   729
     if there will be anything to read 
986bb2a74ac2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20806
diff changeset
   730
     (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
   731
     If you want to check for available data, 
986bb2a74ac2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20806
diff changeset
   732
     use nextAvailable:, or canReadWithoutBlocking"
5851
6823cc642d60 only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
   733
5918
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
   734
    (self == StdInStream) ifTrue:[
20225
bf9e7cd9f53d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20175
diff changeset
   735
        OperatingSystem hasConsole ifFalse:[
bf9e7cd9f53d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20175
diff changeset
   736
            ^ true
22777
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   737
        ].
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   738
        "/ ^ self isOpen not.
5918
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
   739
    ].
0d8bc97e7106 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5851
diff changeset
   740
20685
4cf48622d541 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20680
diff changeset
   741
    handle notNil ifTrue:[
4cf48622d541 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20680
diff changeset
   742
        "first, wait to avoid blocking on the read.
4cf48622d541 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20680
diff changeset
   743
         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
   744
22777
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   745
        (self == StdInStream) ifTrue:[
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   746
            self readWaitWithTimeoutMs:0.05.
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   747
        ] ifFalse:[
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   748
            self readWaitWithTimeoutMs:nil.
8edae1451af4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22702
diff changeset
   749
        ].
20685
4cf48622d541 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20680
diff changeset
   750
    ].
20225
bf9e7cd9f53d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20175
diff changeset
   751
    handle isNil ifTrue:[
20685
4cf48622d541 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20680
diff changeset
   752
        "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
   753
        ^ true.
bf9e7cd9f53d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20175
diff changeset
   754
    ].
5851
6823cc642d60 only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
   755
    ^ super atEnd.
6823cc642d60 only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
   756
!
6823cc642d60 only do readWait for pipes and sockets.
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
   757
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   758
collectionSize
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   759
    "we do not know our size"
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   760
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   761
    ^ self positionError
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   762
!
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   763
5407
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   764
isPositionable
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   765
    "return true, if the stream supports positioning (this one is not)"
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   766
d6729266a95b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
   767
    ^ false
11455
c78421a80b7c changed #size: raise error
Stefan Vogel <sv@exept.de>
parents: 10410
diff changeset
   768
!
c78421a80b7c changed #size: raise error
Stefan Vogel <sv@exept.de>
parents: 10410
diff changeset
   769
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   770
remainingSize
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   771
    "we do not know our size"
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   772
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   773
    ^ self positionError
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   774
!
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   775
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11907
diff changeset
   776
size
11455
c78421a80b7c changed #size: raise error
Stefan Vogel <sv@exept.de>
parents: 10410
diff changeset
   777
    "we do not know our size"
c78421a80b7c changed #size: raise error
Stefan Vogel <sv@exept.de>
parents: 10410
diff changeset
   778
c78421a80b7c changed #size: raise error
Stefan Vogel <sv@exept.de>
parents: 10410
diff changeset
   779
    ^ self positionError
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   780
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   781
10349
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   782
!NonPositionableExternalStream methodsFor:'reading'!
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   783
14758
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   784
next
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   785
    "return the next element, if available.
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   786
     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
   787
     Instead, nil is returned immediately.
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   788
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   789
     Redefined, to wait on pipes and sockets"
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   790
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   791
    self readWaitWithTimeoutMs:nil.
14758
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   792
    ^ super next
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   793
!
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   794
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   795
nextByte
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   796
    "redefined, to wait on pipes and sockets"
15796
b3fdd3c2aec2 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 15720
diff changeset
   797
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   798
    self readWaitWithTimeoutMs:nil.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   799
    ^ super nextByte
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   800
!
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   801
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   802
nextLine
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   803
    "return the characters upTo (but excluding) the next cr (carriage return)
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   804
     character (i.e. read a single line of text).
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   805
     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
   806
     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
   807
     Redefined to not block forever if no cr is read."
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   808
20175
6c184327b58b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20148
diff changeset
   809
    |answerStream char wasBinary available "{ Class:SmallInteger }"|
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   810
20112
51d94c856e12 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20105
diff changeset
   811
    answerStream := WriteStream on:(String uninitializedNew:80).
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   812
    [
21131
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   813
        "#atEnd waits for new data or EOF"
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   814
        self atEnd ifTrue:[
22954
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   815
            answerStream isEmpty ifTrue:[
21131
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   816
                ^ self pastEndRead.
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   817
            ].
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   818
            ^ answerStream contents.
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   819
        ].
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   820
        available := self numAvailableForRead.
21131
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   821
        available == 0 ifTrue:[
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   822
            "so #atEnd didn't wait above, but no data is present - check for error"
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   823
            self peek.
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   824
            available := self numAvailableForRead.        
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   825
        ].
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   826
        
20113
5f9348a2a716 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20112
diff changeset
   827
        wasBinary := binary.            "temporarily set to text mode"
5f9348a2a716 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20112
diff changeset
   828
        binary := false.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   829
        available timesRepeat:[
20148
a0e964e1c7ac #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 20115
diff changeset
   830
            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
   831
            char == Character cr ifTrue:[
22954
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   832
                (answerStream isEmpty not and:[answerStream last == Character return]) ifTrue:[
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   833
                    answerStream backStep.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   834
                ].
20113
5f9348a2a716 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20112
diff changeset
   835
                binary := wasBinary.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   836
                ^ answerStream contents.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   837
            ].
20256
b706cfe3d902 #OTHER by mawalch
mawalch
parents: 20225
diff changeset
   838
            char notNil ifTrue:[
20148
a0e964e1c7ac #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 20115
diff changeset
   839
                answerStream nextPut:char.
a0e964e1c7ac #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 20115
diff changeset
   840
            ].
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   841
        ].
20113
5f9348a2a716 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20112
diff changeset
   842
        binary := wasBinary.            "restore saved mode"
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   843
    ] loop.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   844
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   845
    "not reached"
22954
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   846
7a042f543d73 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22777
diff changeset
   847
    "Modified: / 18-05-2018 / 14:01:19 / Stefan Vogel"
15796
b3fdd3c2aec2 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 15720
diff changeset
   848
!
b3fdd3c2aec2 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 15720
diff changeset
   849
10349
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   850
nextOrNil
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   851
    "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
   852
     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
   853
     Instead, nil is returned immediately.
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   854
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   855
     Redefined, to wait on pipes and sockets"
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   856
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   857
    self readWaitWithTimeoutMs:nil.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   858
    handle isNil ifTrue:[
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   859
        "we were closed while waiting - so we are at the end"
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   860
        ^ nil.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   861
    ].
14758
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   862
    ^ super nextOrNil
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   863
!
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   864
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   865
peek
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   866
    "Redefined, to wait on pipes and sockets"
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   867
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   868
    self readWaitWithTimeoutMs:nil.
14758
6a70a7006093 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 12754
diff changeset
   869
    ^ super peek
10349
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   870
!
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   871
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   872
peekOrNil
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   873
    "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
   874
     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
   875
     Instead, nil is returned immediately.
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   876
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   877
     Redefined, to wait on pipes and sockets"
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   878
20680
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   879
    self readWaitWithTimeoutMs:nil.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   880
    handle isNil ifTrue:[
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   881
        "we were closed while waiting - so we are at the end"
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   882
        ^ nil.
bf04d4121195 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20644
diff changeset
   883
    ].
10349
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   884
    ^ self peek
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   885
!
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   886
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   887
upTo:anObject into:aStream
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   888
    "read a collection of all objects up-to anObject and append these
20256
b706cfe3d902 #OTHER by mawalch
mawalch
parents: 20225
diff changeset
   889
     elements to aStream, but excluding anObject.
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   890
     The next read operation will return the element after anObject.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   891
     (i.e. anObject is considered a separator, which is skipped)
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   892
     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
   893
     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
   894
     Compare this with #through: which also reads up to some object
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   895
     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
   896
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   897
    |element available "{ Class:SmallInteger }"|
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
   898
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   899
    [
21131
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   900
        "#atEnd waits for new data or EOF"
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   901
        self atEnd ifTrue:[
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   902
            ^ self.
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   903
        ].
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   904
        available := self numAvailableForRead.
21131
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   905
        available == 0 ifTrue:[
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   906
            "so #atEnd didn't wait above, but no data is present - check for error"
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   907
            self peek.
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   908
            available := self numAvailableForRead.        
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   909
        ].
d1acc3e2e4a1 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21096
diff changeset
   910
20105
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   911
        available timesRepeat:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   912
            element := super next.      "we know that there is data"
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   913
            element = anObject ifTrue:[
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   914
                ^ self.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   915
            ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   916
            aStream nextPut:element.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   917
        ].
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   918
    ] loop.
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   919
251e963545c6 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   920
    "not reached"
10349
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   921
! !
cbfa00bba11d Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents: 10327
diff changeset
   922
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   923
!NonPositionableExternalStream methodsFor:'testing'!
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   924
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   925
canReadWithoutBlocking
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   926
    "return true, if any data is available for reading (i.e.
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   927
     a read operation will not block the smalltalk process), false otherwise.
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   928
     We know, that error conditions do not block, so return true for errors."
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   929
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   930
    |fd|
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   931
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   932
    ^ readAhead notNil
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   933
        or:[(fd := self fileHandle) isNil
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   934
        or:[mode == #writeonly
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   935
        or:[OperatingSystem readCheck:fd]]]
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   936
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   937
    "
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   938
     |pipe|
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   939
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   940
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   941
     pipe canReadWithoutBlocking ifTrue:[
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   942
         Transcript showCR:'data available'
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   943
     ] ifFalse:[
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   944
         Transcript showCR:'no data available'
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   945
     ].
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   946
     pipe close
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   947
    "
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   948
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   949
    "Modified: / 25-09-1997 / 13:08:45 / stefan"
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   950
    "Modified: / 04-03-2020 / 14:51:53 / Stefan Vogel"
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   951
!
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   952
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   953
canWriteWithoutBlocking
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   954
    "return true, if data can be written into the stream
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   955
     (i.e. a write operation will not block the smalltalk process).
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   956
     We know, that error conditions do not block, so return true for errors."
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   957
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   958
    |fd|
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   959
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   960
    ^ (fd := self fileHandle) isNil
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   961
        or:[mode == #readonly
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   962
        or:[OperatingSystem writeCheck:fd]]
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   963
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
   964
    "Modified: / 04-03-2020 / 14:51:42 / Stefan Vogel"
21361
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   965
! !
a63984f4eceb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21239
diff changeset
   966
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   967
!NonPositionableExternalStream methodsFor:'writing'!
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
   968
17642
5988beff84f7 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 17607
diff changeset
   969
nextPutAll:aCollection
24638
b37abe380c6a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24602
diff changeset
   970
    "nextPutBytes handles non-blocking io in receiver.
b37abe380c6a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24602
diff changeset
   971
     Answer the receiver"
17642
5988beff84f7 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 17607
diff changeset
   972
25137
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   973
    |count nWritten|
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   974
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   975
    count := aCollection size.
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   976
    nWritten := self nextPutBytes:count from:aCollection startingAt:1.
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   977
    count ~= nWritten ifTrue:[
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   978
        "incomplete write"
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   979
        self writeError.
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   980
    ].
22541
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   981
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
   982
    "Modified: / 09-02-2018 / 19:59:15 / stefan"
17642
5988beff84f7 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 17607
diff changeset
   983
!
5988beff84f7 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 17607
diff changeset
   984
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   985
nextPutAll:aCollection startingAt:start to:stop
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   986
    "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
   987
25137
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   988
    |count nWritten|
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   989
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   990
    count := stop-start+1.
25137
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   991
    nWritten := self nextPutBytes:count from:aCollection startingAt:start.
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   992
    count ~= nWritten ifTrue:[
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   993
        "incomplete write"
34bca3daadac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24720
diff changeset
   994
        self writeError.
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   995
    ].
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   996
!
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
   997
7679
4c1f76483b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7541
diff changeset
   998
nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset
4c1f76483b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7541
diff changeset
   999
    "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
  1000
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
  1001
    |offset remaining wasBlocking|
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
  1002
25259
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1003
    "sr: ATTENTION: keep the following #blocking: call here,
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1004
     dont move it under the #handle is nil check,
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1005
     if you move it, expecco ALM will freeze with 100% cpu usage during startup...
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1006
     and see the comment inside the #handle is nil check,
25313
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1007
     which seems to assume this #blocking: call before.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1008
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1009
     Lange Rede kurzer Sinn: 'self blocking:' sends 'self fileDescriptor'
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1010
                              which may set handle to nil!!"
25319
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
  1011
    "for linux we set non-blocking mode, so that the whole ST with all
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
  1012
     other processes does not block, when a socket or pipe is full.
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
  1013
     For windows, writes are done in an own thread, so only the 
87bd826eaa92 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25313
diff changeset
  1014
     active process will block. For windows, #blocking: is a non-op."
25259
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1015
    wasBlocking := self blocking:false.
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1016
22193
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1017
    handle isNil ifTrue:[
22194
41775bf87e61 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22193
diff changeset
  1018
        "self blocking: above may set handle to nil!!"
22193
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1019
        self errorNotOpen.
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1020
        (self == Stderr or:[self == Stdout]) ifTrue:[
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1021
           "Care for closed stdout and stderr,
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1022
            which happens, if the console is closed while I am running.
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1023
            In this case, we ignore the error."
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1024
            ^ initialWriteCount.
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1025
        ].
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1026
        ^ 0.
023c7585d304 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22192
diff changeset
  1027
    ].
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
  1028
22194
41775bf87e61 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22193
diff changeset
  1029
    offset := initialOffset.
41775bf87e61 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22193
diff changeset
  1030
    remaining := initialWriteCount.
41775bf87e61 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22193
diff changeset
  1031
25313
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1032
    [
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1033
        [remaining ~~ 0] whileTrue:[
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1034
            |count|
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
  1035
25143
d9dc4a133499 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 25137
diff changeset
  1036
            count := super nextPutBytes:remaining from:buffer startingAt:offset.
d9dc4a133499 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 25137
diff changeset
  1037
            self assert:(count >= 0).
d9dc4a133499 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 25137
diff changeset
  1038
            count == 0 ifTrue:[
25313
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1039
                self writeWait.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1040
                count := super nextPutBytes:remaining from:buffer startingAt:offset.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1041
                self assert:(count >= 0).
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1042
                count == 0 ifTrue:[
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1043
                    Transcript showCR:'zero write'.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1044
                    self error:'zero write'
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1045
                ].
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1046
            ].
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1047
            remaining := remaining - count.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1048
            offset := offset + count.
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1049
            remaining ~~ 0 ifTrue:[
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1050
                "Transcript showCR:'writeWait'."
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1051
                self writeWait.
25143
d9dc4a133499 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 25137
diff changeset
  1052
            ].
d9dc4a133499 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 25137
diff changeset
  1053
        ].
25313
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1054
    ] ensure:[    
25322
33036e5651e0 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25319
diff changeset
  1055
        (wasBlocking and:[handle notNil]) ifTrue:[self blocking:true].
25313
a91253d9c944 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25259
diff changeset
  1056
    ].    
7679
4c1f76483b6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7541
diff changeset
  1057
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
  1058
    ^ offset - initialOffset.
25259
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1059
c6a993f1ead2 #BUGFIX by Stefan Reise
sr
parents: 25143
diff changeset
  1060
    "Modified (format): / 13-02-2020 / 14:23:44 / Stefan Reise"
25322
33036e5651e0 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25319
diff changeset
  1061
    "Modified: / 06-03-2020 / 15:06:07 / Stefan Vogel"
22541
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1062
!
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1063
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1064
nextPutLine:aString
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1065
    "write the characters in aString and append an end-of-Line marker
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1066
     (LF, CR or CRLF - depending in the setting of eolMode)"
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1067
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1068
    self nextPutAll:aString.
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1069
    self cr.
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1070
b8acf94e540b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22194
diff changeset
  1071
    "Created: / 09-02-2018 / 21:13:47 / stefan"
7497
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
  1072
! !
cc29afd51151 Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents: 7241
diff changeset
  1073
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1074
!NonPositionableExternalStream class methodsFor:'documentation'!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1075
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1076
version
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
  1077
    ^ '$Header$'
12677
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
  1078
!
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
  1079
aeab74b04f0b Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 12395
diff changeset
  1080
version_CVS
18798
0b4860a5c695 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18398
diff changeset
  1081
    ^ '$Header$'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1082
! !
17607
224f253b60c8 class: NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents: 16348
diff changeset
  1083