12
12
13
13
use core:: prelude:: * ;
14
14
use alloc:: boxed:: Box ;
15
- use collections:: string:: String ;
16
- use core:: mem;
17
- use libc:: c_int;
18
-
19
- use local:: Local ;
20
- use task:: Task ;
21
15
22
16
pub trait EventLoop {
23
17
fn run ( & mut self ) ;
@@ -27,8 +21,7 @@ pub trait EventLoop {
27
21
fn remote_callback ( & mut self , Box < Callback + Send > )
28
22
-> Box < RemoteCallback + Send > ;
29
23
30
- /// The asynchronous I/O services. Not all event loops may provide one.
31
- fn io < ' a > ( & ' a mut self ) -> Option < & ' a mut IoFactory > ;
24
+ // last vestige of IoFactory
32
25
fn has_active_io ( & self ) -> bool ;
33
26
}
34
27
@@ -46,128 +39,7 @@ pub trait RemoteCallback {
46
39
fn fire ( & mut self ) ;
47
40
}
48
41
49
- pub struct LocalIo < ' a > {
50
- factory : & ' a mut IoFactory +' a ,
51
- }
52
-
53
- #[ unsafe_destructor]
54
- impl < ' a > Drop for LocalIo < ' a > {
55
- fn drop ( & mut self ) {
56
- // FIXME(pcwalton): Do nothing here for now, but eventually we may want
57
- // something. For now this serves to make `LocalIo` noncopyable.
58
- }
59
- }
60
-
61
- impl < ' a > LocalIo < ' a > {
62
- /// Returns the local I/O: either the local scheduler's I/O services or
63
- /// the native I/O services.
64
- pub fn borrow ( ) -> Option < LocalIo < ' a > > {
65
- // FIXME(#11053): bad
66
- //
67
- // This is currently very unsafely implemented. We don't actually
68
- // *take* the local I/O so there's a very real possibility that we
69
- // can have two borrows at once. Currently there is not a clear way
70
- // to actually borrow the local I/O factory safely because even if
71
- // ownership were transferred down to the functions that the I/O
72
- // factory implements it's just too much of a pain to know when to
73
- // relinquish ownership back into the local task (but that would be
74
- // the safe way of implementing this function).
75
- //
76
- // In order to get around this, we just transmute a copy out of the task
77
- // in order to have what is likely a static lifetime (bad).
78
- let mut t: Box < Task > = match Local :: try_take ( ) {
79
- Some ( t) => t,
80
- None => return None ,
81
- } ;
82
- let ret = t. local_io ( ) . map ( |t| {
83
- unsafe { mem:: transmute_copy ( & t) }
84
- } ) ;
85
- Local :: put ( t) ;
86
- return ret;
87
- }
88
-
89
- pub fn maybe_raise < T > ( f: |io: & mut IoFactory | -> IoResult < T > )
90
- -> IoResult < T >
91
- {
92
- #[ cfg( unix) ] use libc:: EINVAL as ERROR ;
93
- #[ cfg( windows) ] use libc:: ERROR_CALL_NOT_IMPLEMENTED as ERROR ;
94
- match LocalIo :: borrow ( ) {
95
- Some ( mut io) => f ( io. get ( ) ) ,
96
- None => Err ( IoError {
97
- code : ERROR as uint ,
98
- extra : 0 ,
99
- detail : None ,
100
- } ) ,
101
- }
102
- }
103
-
104
- pub fn new < ' a > ( io : & ' a mut IoFactory +' a ) -> LocalIo < ' a > {
105
- LocalIo { factory : io }
106
- }
107
-
108
- /// Returns the underlying I/O factory as a trait reference.
109
- #[ inline]
110
- pub fn get < ' a > ( & ' a mut self ) -> & ' a mut IoFactory {
111
- let f: & ' a mut IoFactory = self . factory ;
112
- f
113
- }
114
- }
115
-
116
- pub trait IoFactory {
117
- fn timer_init ( & mut self ) -> IoResult < Box < RtioTimer + Send > > ;
118
- fn tty_open ( & mut self , fd : c_int , readable : bool )
119
- -> IoResult < Box < RtioTTY + Send > > ;
120
- }
121
-
122
- pub trait RtioTimer {
123
- fn sleep ( & mut self , msecs : u64 ) ;
124
- fn oneshot ( & mut self , msecs : u64 , cb : Box < Callback + Send > ) ;
125
- fn period ( & mut self , msecs : u64 , cb : Box < Callback + Send > ) ;
126
- }
127
-
128
- pub trait RtioPipe {
129
- fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < uint > ;
130
- fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > ;
131
- fn clone ( & self ) -> Box < RtioPipe + Send > ;
132
-
133
- fn close_write ( & mut self ) -> IoResult < ( ) > ;
134
- fn close_read ( & mut self ) -> IoResult < ( ) > ;
135
- fn set_timeout ( & mut self , timeout_ms : Option < u64 > ) ;
136
- fn set_read_timeout ( & mut self , timeout_ms : Option < u64 > ) ;
137
- fn set_write_timeout ( & mut self , timeout_ms : Option < u64 > ) ;
138
- }
139
-
140
- pub trait RtioUnixListener {
141
- fn listen ( self : Box < Self > ) -> IoResult < Box < RtioUnixAcceptor + Send > > ;
142
- }
143
-
144
- pub trait RtioUnixAcceptor {
145
- fn accept ( & mut self ) -> IoResult < Box < RtioPipe + Send > > ;
146
- fn set_timeout ( & mut self , timeout : Option < u64 > ) ;
147
- fn clone ( & self ) -> Box < RtioUnixAcceptor + Send > ;
148
- fn close_accept ( & mut self ) -> IoResult < ( ) > ;
149
- }
150
-
151
- pub trait RtioTTY {
152
- fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < uint > ;
153
- fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > ;
154
- fn set_raw ( & mut self , raw : bool ) -> IoResult < ( ) > ;
155
- fn get_winsize ( & mut self ) -> IoResult < ( int , int ) > ;
156
- fn isatty ( & self ) -> bool ;
157
- }
158
-
159
42
pub trait PausableIdleCallback {
160
43
fn pause ( & mut self ) ;
161
44
fn resume ( & mut self ) ;
162
45
}
163
-
164
- pub trait RtioSignal { }
165
-
166
- #[ deriving( Show ) ]
167
- pub struct IoError {
168
- pub code : uint ,
169
- pub extra : uint ,
170
- pub detail : Option < String > ,
171
- }
172
-
173
- pub type IoResult < T > = Result < T , IoError > ;
0 commit comments