InternalPipeStream.st
author Claus Gittinger <cg@exept.de>
Mon, 18 Nov 2019 16:15:00 +0100
changeset 5241 0937a27658e1
parent 5182 83a0d0ab1d86
child 5255 aed43d6cf187
permissions -rw-r--r--
#DOCUMENTATION by cg class: InternalPipeStream category of: #atEnd #next #nextAvailableBytes:into:startingAt: #nextPut: #readWaitWithTimeoutMs:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4326
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     1
"
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     2
 COPYRIGHT (c) 2002 by Claus Gittinger
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     3
              All Rights Reserved
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     4
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     5
 This software is furnished under a license and may be used
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     6
 only in accordance with the terms of that license and with the
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     8
 be provided or otherwise made available to, or used by, any
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
     9
 other person.  No title to or ownership of the software is
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    10
 hereby transferred.
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    11
"
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    14
"{ NameSpace: Smalltalk }"
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    15
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Stream subclass:#InternalPipeStream
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    17
	instanceVariableNames:'queue closed contentsSpecies'
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Streams'
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    23
!InternalPipeStream class methodsFor:'documentation'!
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    24
4326
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    25
copyright
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    26
"
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    27
 COPYRIGHT (c) 2002 by Claus Gittinger
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    28
              All Rights Reserved
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    29
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    30
 This software is furnished under a license and may be used
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    31
 only in accordance with the terms of that license and with the
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    33
 be provided or otherwise made available to, or used by, any
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    34
 other person.  No title to or ownership of the software is
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    35
 hereby transferred.
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    36
"
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    37
!
5aca213f1a71 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
    38
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    39
documentation
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    40
"
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    41
    not useful on its own, but can be used to talk to a vt100
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    42
    terminal view ...
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    43
    
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    44
    See example.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    45
"
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    46
!
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    47
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    48
examples
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    49
"
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    50
                                                                [exBegin]
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    51
    |p|
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    52
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    53
    p := InternalPipeStream new.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    54
    [
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    55
        10 timesRepeat:[
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    56
            p nextPutLine:'hello'
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    57
        ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    58
    ] fork.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    59
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    60
    [
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    61
        10 timesRepeat:[
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    62
            Transcript showCR:p nextLine
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    63
        ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    64
    ] fork.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    65
                                                                [exEnd]
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    66
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    67
                                                                [exBegin]
3291
facd0cfd0781 Fixed examples (added missing vars, dot at the end of statement)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3128
diff changeset
    68
    |userInput elizasOutput top terminal|
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    69
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    70
    userInput    := InternalPipeStream new.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    71
    elizasOutput := InternalPipeStream new.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    72
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    73
    top := StandardSystemView new.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    74
    terminal := VT100TerminalView openOnInput: userInput output:elizasOutput in:top.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    75
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    76
    top extent:(terminal preferredExtent).
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    77
    top label:'The doctor is in'.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    78
    top iconLabel:'doctor'.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    79
    top open.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    80
    top waitUntilVisible.
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    81
    top onChangeEvaluate:[:what :aParameter :changedObject | what == #destroyed ifTrue:[userInput close]].
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    82
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    83
    terminal translateNLToCRNL:true.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    84
    terminal inputTranslateCRToNL:true.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    85
    terminal localEcho:true.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    86
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    87
    elizasOutput nextPutLine:'Hi, I am Eliza'.
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    88
    elizasOutput nextPutLine:'What is your problem (type end to finish conversation) ?'.
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    89
    elizasOutput nextPutLine:''.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    90
    elizasOutput nextPutAll:'>'.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    91
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    92
    [top realized] whileTrue:[
5141
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    93
        |line answer matchingRule matches what|
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    94
5141
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    95
        ((userInput readWaitWithTimeout:1) not and:[top realized]) ifTrue:[
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    96
            line := userInput nextLine.
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    97
            ((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    98
                top destroy.
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
    99
                ^ self
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   100
            ].
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   101
            (matches := line subExpressionsInRegex:'I am (.+)' caseSensitive:false) size == 1 ifTrue:[
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   102
                answer := #( 
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   103
                            'Why are you %1?'
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   104
                            'What makes you think that you are %1?'
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   105
                            'Who told you, that you are %1?'
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   106
                          ) atRandom bindWithArguments:matches
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   107
            ] ifFalse:[
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   108
                answer := 'Tell me more.'.
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   109
            ].
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   110
            elizasOutput nextPutLine:answer.
046c31b9f275 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4326
diff changeset
   111
            elizasOutput nextPutAll:'>'.
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   112
        ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   113
    ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   114
                                                                [exEnd]
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   115
"
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   116
! !
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
!InternalPipeStream class methodsFor:'instance creation'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
new
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    ^ self basicNew initialize
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
! !
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
!InternalPipeStream methodsFor:'accessing'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
close
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   127
    "if there is any partner waiting at either side of the queue,
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   128
     tell it that the pipe is no longer active.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   129
     (readers will read an EOF condition, writers will get a write error).
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   130
     Either side may close the internal pipe."
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   131
     
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   132
    closed := true.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   133
    queue readSemaphore signalForAll
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   134
!
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   135
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   136
isOpen
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   137
    ^ closed not
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
5241
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   140
size
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   141
    ^ queue size
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   142
! !
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   143
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   144
!InternalPipeStream methodsFor:'initialization'!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   145
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   146
contentsSpecies:aClass
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   147
    "by default, I will return a String of elements, if reading multiple elements.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   148
     However, you may change this to eg. an array, if desired"
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   149
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   150
    contentsSpecies := aClass.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   151
!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   152
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   153
initialize
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   154
    queue := SharedQueue new.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   155
    closed := false.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   156
! !
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   157
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   158
!InternalPipeStream methodsFor:'queries'!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   159
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   160
atEnd
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   161
    ^ closed and:[queue isEmpty]
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   162
!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   163
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   164
contentsSpecies
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   165
    ^ contentsSpecies ? String
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   166
! !
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   167
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   168
!InternalPipeStream methodsFor:'reading'!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   169
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
next
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    "return the next element from the stream (might block until something is written)"
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   173
    (closed and:[queue isEmpty]) ifTrue:[^ self pastEndRead].
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    ^ queue next
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
nextAvailableBytes:nMax into:aBuffer startingAt:startIndex
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    |n idx ch|
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   180
    (closed and:[queue isEmpty and:[self pastEndRead isNil]]) ifTrue:[^ 0].
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   181
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    n := 0.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    idx := startIndex.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    [n <= nMax] whileTrue:[
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
        ch := queue nextIfEmpty:[^ n ].
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
        aBuffer at:idx put:ch.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
        idx := idx + 1.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
        n := n + 1
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    ].
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
    ^ n
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
5241
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   193
readWaitWithTimeoutMs:millis
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   194
    "suspend the current process, until the receiver
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   195
     becomes ready for reading or a timeout (in milliseconds) expired.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   196
     If data is already available, return immediate.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   197
     With nil millis, wait forever.
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   198
     Return true if a timeout occurred (i.e. false, if data is available).
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   199
     The other threads are not affected by the wait."
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   200
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   201
    (closed and:[queue isEmpty]) ifTrue:[^ false].
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   202
    ^ queue readWaitWithTimeoutMs:millis
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   203
! !
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   204
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   205
!InternalPipeStream methodsFor:'synchronization'!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   206
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   207
readWait
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   208
    queue readSemaphore wait
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   209
!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   210
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   211
writeWaitWithTimeoutMs:timeout
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   212
    queue writeSemaphore waitWithTimeoutMs:timeout
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   213
! !
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   214
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   215
!InternalPipeStream methodsFor:'writing'!
0937a27658e1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5182
diff changeset
   216
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   217
nextPut:anObject
5182
83a0d0ab1d86 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5163
diff changeset
   218
    "write an element (might wakeup readers).
83a0d0ab1d86 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5163
diff changeset
   219
     Answer the argument"
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   221
    closed ifTrue:[ self errorNotOpen].
5163
bb5f55706bab #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5141
diff changeset
   222
    queue nextPut:anObject.
bb5f55706bab #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5141
diff changeset
   223
    ^ anObject
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   224
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   225
    "
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   226
     |s|
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   227
     s := InternalPipeStream new.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   228
     s nextPut:$a.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   229
     s nextPut:$b.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   230
     s nextPut:$c.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   231
    "
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
! !
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
!InternalPipeStream class methodsFor:'documentation'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
version
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   237
    ^ '$Header$'
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
! !
3128
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   239