@@ -17,7 +17,7 @@ pub use adapter::{SendStatus};
17
17
pub use resource_id:: { ResourceId , ResourceType } ;
18
18
pub use endpoint:: { Endpoint } ;
19
19
pub use remote_addr:: { RemoteAddr , ToRemoteAddr } ;
20
- pub use transport:: { Transport } ;
20
+ pub use transport:: { Transport , TransportConnect , TransportListen } ;
21
21
pub use driver:: { NetEvent } ;
22
22
pub use poll:: { Readiness } ;
23
23
@@ -101,12 +101,22 @@ impl NetworkController {
101
101
& self ,
102
102
transport : Transport ,
103
103
addr : impl ToRemoteAddr ,
104
+ ) -> io:: Result < ( Endpoint , SocketAddr ) > {
105
+ self . connect_with ( transport. into ( ) , addr)
106
+ }
107
+
108
+ pub fn connect_with (
109
+ & self ,
110
+ transport_connect : TransportConnect ,
111
+ addr : impl ToRemoteAddr ,
104
112
) -> io:: Result < ( Endpoint , SocketAddr ) > {
105
113
let addr = addr. to_remote_addr ( ) . unwrap ( ) ;
106
- self . controllers [ transport. id ( ) as usize ] . connect ( addr) . map ( |( endpoint, addr) | {
107
- log:: trace!( "Connect to {}" , endpoint) ;
108
- ( endpoint, addr)
109
- } )
114
+ self . controllers [ transport_connect. id ( ) as usize ] . connect_with ( transport_connect, addr) . map (
115
+ |( endpoint, addr) | {
116
+ log:: trace!( "Connect to {}" , endpoint) ;
117
+ ( endpoint, addr)
118
+ } ,
119
+ )
110
120
}
111
121
112
122
/// Creates a connection to the specified address.
@@ -147,7 +157,15 @@ impl NetworkController {
147
157
transport : Transport ,
148
158
addr : impl ToRemoteAddr ,
149
159
) -> io:: Result < ( Endpoint , SocketAddr ) > {
150
- let ( endpoint, addr) = self . connect ( transport, addr) ?;
160
+ self . connect_sync_with ( transport. into ( ) , addr)
161
+ }
162
+
163
+ pub fn connect_sync_with (
164
+ & self ,
165
+ transport_connect : TransportConnect ,
166
+ addr : impl ToRemoteAddr ,
167
+ ) -> io:: Result < ( Endpoint , SocketAddr ) > {
168
+ let ( endpoint, addr) = self . connect_with ( transport_connect, addr) ?;
151
169
loop {
152
170
std:: thread:: sleep ( Duration :: from_millis ( 1 ) ) ;
153
171
match self . is_ready ( endpoint. resource_id ( ) ) {
@@ -173,12 +191,22 @@ impl NetworkController {
173
191
& self ,
174
192
transport : Transport ,
175
193
addr : impl ToSocketAddrs ,
194
+ ) -> io:: Result < ( ResourceId , SocketAddr ) > {
195
+ self . listen_with ( transport. into ( ) , addr)
196
+ }
197
+
198
+ pub fn listen_with (
199
+ & self ,
200
+ transport_listen : TransportListen ,
201
+ addr : impl ToSocketAddrs ,
176
202
) -> io:: Result < ( ResourceId , SocketAddr ) > {
177
203
let addr = addr. to_socket_addrs ( ) . unwrap ( ) . next ( ) . unwrap ( ) ;
178
- self . controllers [ transport. id ( ) as usize ] . listen ( addr) . map ( |( resource_id, addr) | {
179
- log:: trace!( "Listening at {} by {}" , addr, resource_id) ;
180
- ( resource_id, addr)
181
- } )
204
+ self . controllers [ transport_listen. id ( ) as usize ] . listen_with ( transport_listen, addr) . map (
205
+ |( resource_id, addr) | {
206
+ log:: trace!( "Listening at {} by {}" , addr, resource_id) ;
207
+ ( resource_id, addr)
208
+ } ,
209
+ )
182
210
}
183
211
184
212
/// Send the data message thought the connection represented by the given endpoint.
0 commit comments