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