InternalPipeStream.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4326 5aca213f1a71
child 5141 046c31b9f275
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
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:[
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    93
        |line answer matchingRule|
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    94
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    95
        line := userInput nextLine.
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
    96
        ((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    97
            top destroy.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    98
            ^ self
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
    99
        ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   100
3291
facd0cfd0781 Fixed examples (added missing vars, dot at the end of statement)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3128
diff changeset
   101
        answer := 'Tell me more.'.
1016
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   102
        elizasOutput nextPutLine:answer.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   103
        elizasOutput nextPutAll:'>'.
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   104
    ].
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   105
                                                                [exEnd]
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   106
"
47e190c35919 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1015
diff changeset
   107
! !
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!InternalPipeStream class methodsFor:'instance creation'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
new
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    ^ self basicNew initialize
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
! !
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
!InternalPipeStream methodsFor:'accessing'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
atEnd
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   118
    ^ closed and:[queue isEmpty]
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
close
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   122
    "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
   123
     tell it that the pipe is no longer active.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   124
     (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
   125
     Either side may close the internal pipe."
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   126
     
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   127
    closed := true.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   128
    queue readSemaphore signalForAll
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   129
!
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   130
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   131
isOpen
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   132
    ^ closed not
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
next
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    "return the next element from the stream (might block until something is written)"
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   138
    (closed and:[queue isEmpty]) ifTrue:[^ self pastEndRead].
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ^ queue next
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
nextAvailableBytes:nMax into:aBuffer startingAt:startIndex
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    |n idx ch|
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   145
    (closed and:[queue isEmpty and:[self pastEndRead isNil]]) ifTrue:[^ 0].
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   146
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    n := 0.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    idx := startIndex.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    [n <= nMax] whileTrue:[
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
        ch := queue nextIfEmpty:[^ n ].
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
        aBuffer at:idx put:ch.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
        idx := idx + 1.
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
        n := n + 1
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    ].
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    ^ n
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   158
nextPut:anObject
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    "write an element (might wakeup readers)"
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   161
    closed ifTrue:[ self errorNotOpen].
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   162
    queue nextPut:anObject
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   163
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   164
    "
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   165
     |s|
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   166
     s := InternalPipeStream new.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   167
     s nextPut:$a.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   168
     s nextPut:$b.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   169
     s nextPut:$c.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   170
    "
3128
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   171
!
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   172
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   173
size
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   174
    ^ queue size
1015
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
!InternalPipeStream methodsFor:'initialization'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   179
contentsSpecies:aClass
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   180
    "by default, I will return a String of elements, if reading multiple elements.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   181
     However, you may change this to eg. an array, if desired"
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   182
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   183
    contentsSpecies := aClass.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   184
!
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   185
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
initialize
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    queue := SharedQueue new.
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   188
    closed := false.
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   189
! !
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   190
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   191
!InternalPipeStream methodsFor:'queries'!
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   192
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   193
contentsSpecies
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   194
    ^ contentsSpecies ? String
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
! !
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
!InternalPipeStream methodsFor:'synchronization'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
readWait
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    queue readSemaphore wait
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   201
!
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   202
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   203
writeWaitWithTimeoutMs:timeout
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   204
    queue writeSemaphore waitWithTimeoutMs:timeout
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
! !
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
!InternalPipeStream class methodsFor:'documentation'!
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
version
3978
e4c47408edb2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3291
diff changeset
   210
    ^ '$Header$'
1015
b03679cb8a3f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
! !
3128
b4d3fba8e356 class: InternalPipeStream
Claus Gittinger <cg@exept.de>
parents: 1016
diff changeset
   212