@@ -14,14 +14,10 @@ Message passing
14
14
15
15
#[ allow( missing_doc) ] ;
16
16
17
- use cast:: { transmute, transmute_mut} ;
18
- use container:: Container ;
17
+ use cast:: transmute;
19
18
use either:: { Either , Left , Right } ;
20
19
use kinds:: Send ;
21
- use option:: { Option , Some , None } ;
22
- use uint;
23
- use vec:: OwnedVector ;
24
- use util:: replace;
20
+ use option:: { Option , Some } ;
25
21
use unstable:: sync:: Exclusive ;
26
22
use rtcomm = rt:: comm;
27
23
use rt;
@@ -143,81 +139,6 @@ impl<T: Send> Selectable for Port<T> {
143
139
}
144
140
}
145
141
146
- /// Treat many ports as one.
147
- #[ unsafe_mut_field( ports) ]
148
- pub struct PortSet < T > {
149
- ports : ~[ pipesy:: Port < T > ] ,
150
- }
151
-
152
- impl < T : Send > PortSet < T > {
153
- pub fn new ( ) -> PortSet < T > {
154
- PortSet {
155
- ports : ~[ ]
156
- }
157
- }
158
-
159
- pub fn add ( & self , port : Port < T > ) {
160
- let Port { inner } = port;
161
- let port = match inner {
162
- Left ( p) => p,
163
- Right ( _) => fail ! ( "PortSet not implemented" )
164
- } ;
165
- unsafe {
166
- let self_ports = transmute_mut ( & self . ports ) ;
167
- self_ports. push ( port)
168
- }
169
- }
170
-
171
- pub fn chan ( & self ) -> Chan < T > {
172
- let ( po, ch) = stream ( ) ;
173
- self . add ( po) ;
174
- ch
175
- }
176
- }
177
-
178
- impl < T : Send > GenericPort < T > for PortSet < T > {
179
- fn try_recv ( & self ) -> Option < T > {
180
- unsafe {
181
- let self_ports = transmute_mut ( & self . ports ) ;
182
- let mut result = None ;
183
- // we have to swap the ports array so we aren't borrowing
184
- // aliasable mutable memory.
185
- let mut ports = replace ( self_ports, ~[ ] ) ;
186
- while result. is_none ( ) && ports. len ( ) > 0 {
187
- let i = wait_many ( ports) ;
188
- match ports[ i] . try_recv ( ) {
189
- Some ( m) => {
190
- result = Some ( m) ;
191
- }
192
- None => {
193
- // Remove this port.
194
- let _ = ports. swap_remove ( i) ;
195
- }
196
- }
197
- }
198
- * self_ports = ports;
199
- result
200
- }
201
- }
202
- fn recv ( & self ) -> T {
203
- self . try_recv ( ) . expect ( "port_set: endpoints closed" )
204
- }
205
- }
206
-
207
- impl < T : Send > Peekable < T > for PortSet < T > {
208
- fn peek ( & self ) -> bool {
209
- // It'd be nice to use self.port.each, but that version isn't
210
- // pure.
211
- for uint:: range( 0 , self . ports. len( ) ) |i| {
212
- let port: & pipesy:: Port < T > = & self . ports [ i] ;
213
- if port. peek ( ) {
214
- return true ;
215
- }
216
- }
217
- false
218
- }
219
- }
220
-
221
142
/// A channel that can be shared between many senders.
222
143
pub struct SharedChan < T > {
223
144
inner : Either < Exclusive < pipesy:: Chan < T > > , rtcomm:: SharedChan < T > >
0 commit comments