@@ -20,26 +20,27 @@ impl TcpStream {
20
20
Ok ( Self { inner } )
21
21
}
22
22
23
- pub fn connect_timeout ( _: & SocketAddr , _: Duration ) -> io:: Result < TcpStream > {
24
- todo ! ( )
23
+ pub fn connect_timeout ( addr : & SocketAddr , timeout : Duration ) -> io:: Result < TcpStream > {
24
+ let timeout = u64:: try_from ( timeout. as_nanos ( ) / 100 )
25
+ . map_err ( |_| io:: const_io_error!( io:: ErrorKind :: InvalidInput , "timeout is too long" ) ) ?;
26
+ let inner = uefi_tcp:: TcpProtocol :: connect_timeout ( addr, timeout) ?;
27
+ Ok ( Self { inner } )
25
28
}
26
29
27
- pub fn set_read_timeout ( & self , _ : Option < Duration > ) -> io:: Result < ( ) > {
28
- unimplemented ! ( )
30
+ pub fn set_read_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
31
+ self . inner . set_read_timeout ( timeout )
29
32
}
30
33
31
- pub fn set_write_timeout ( & self , _ : Option < Duration > ) -> io:: Result < ( ) > {
32
- unimplemented ! ( )
34
+ pub fn set_write_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
35
+ self . inner . set_write_timeout ( timeout )
33
36
}
34
37
35
- // Possible to implement while waiting for event
36
38
pub fn read_timeout ( & self ) -> io:: Result < Option < Duration > > {
37
- Ok ( None )
39
+ self . inner . read_timeout ( )
38
40
}
39
41
40
- // Possible to implement while waiting for event
41
42
pub fn write_timeout ( & self ) -> io:: Result < Option < Duration > > {
42
- Ok ( None )
43
+ self . inner . write_timeout ( )
43
44
}
44
45
45
46
pub fn peek ( & self , _: & mut [ u8 ] ) -> io:: Result < usize > {
@@ -88,16 +89,15 @@ impl TcpStream {
88
89
unsupported ( )
89
90
}
90
91
91
- // Seems to be similar to abort_on_close option in `EFI_TCP6_PROTOCOL->Close()`
92
92
pub fn set_linger ( & self , _: Option < Duration > ) -> io:: Result < ( ) > {
93
- todo ! ( )
93
+ unsupported ( )
94
94
}
95
95
96
96
pub fn linger ( & self ) -> io:: Result < Option < Duration > > {
97
- todo ! ( )
97
+ unsupported ( )
98
98
}
99
99
100
- // Seems to be similar to `EFI_TCP6_OPTION->EnableNagle`
100
+ // UEFI doesn't seem to allow configure for active connections
101
101
pub fn set_nodelay ( & self , _: bool ) -> io:: Result < ( ) > {
102
102
unsupported ( )
103
103
}
@@ -106,26 +106,34 @@ impl TcpStream {
106
106
self . inner . nodelay ( )
107
107
}
108
108
109
- pub fn set_ttl ( & self , x : u32 ) -> io:: Result < ( ) > {
110
- self . inner . set_ttl ( x)
109
+ // UEFI doesn't seem to allow configure for active connections
110
+ pub fn set_ttl ( & self , _: u32 ) -> io:: Result < ( ) > {
111
+ unsupported ( )
111
112
}
112
113
113
114
pub fn ttl ( & self ) -> io:: Result < u32 > {
114
115
self . inner . ttl ( )
115
116
}
116
117
117
118
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
118
- unimplemented ! ( )
119
+ unsupported ( )
119
120
}
120
121
121
122
pub fn set_nonblocking ( & self , _: bool ) -> io:: Result < ( ) > {
122
- todo ! ( )
123
+ unsupported ( )
123
124
}
124
125
}
125
126
126
127
impl fmt:: Debug for TcpStream {
127
- fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
128
- todo ! ( )
128
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129
+ let mut res = f. debug_struct ( "TcpStream" ) ;
130
+ if let Ok ( addr) = self . socket_addr ( ) {
131
+ res. field ( "addr" , & addr) ;
132
+ }
133
+ if let Ok ( peer) = self . peer_addr ( ) {
134
+ res. field ( "peer" , & peer) ;
135
+ }
136
+ res. finish ( )
129
137
}
130
138
}
131
139
@@ -165,154 +173,158 @@ impl TcpListener {
165
173
}
166
174
167
175
pub fn set_only_v6 ( & self , _: bool ) -> io:: Result < ( ) > {
168
- unimplemented ! ( )
176
+ unsupported ( )
169
177
}
170
178
171
179
pub fn only_v6 ( & self ) -> io:: Result < bool > {
172
180
Ok ( false )
173
181
}
174
182
175
183
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
176
- unimplemented ! ( )
184
+ unsupported ( )
177
185
}
178
186
179
187
// Internally TCP Protocol is nonblocking
180
188
pub fn set_nonblocking ( & self , _: bool ) -> io:: Result < ( ) > {
181
- todo ! ( )
189
+ unsupported ( )
182
190
}
183
191
}
184
192
185
193
impl fmt:: Debug for TcpListener {
186
- fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
187
- todo ! ( )
194
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
195
+ let mut res = f. debug_struct ( "TcpListener" ) ;
196
+ if let Ok ( addr) = self . socket_addr ( ) {
197
+ res. field ( "addr" , & addr) ;
198
+ }
199
+ res. finish ( )
188
200
}
189
201
}
190
202
191
203
pub struct UdpSocket { }
192
204
193
205
impl UdpSocket {
194
206
pub fn bind ( _: io:: Result < & SocketAddr > ) -> io:: Result < UdpSocket > {
195
- unimplemented ! ( )
207
+ unsupported ( )
196
208
}
197
209
198
210
pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
199
- unimplemented ! ( )
211
+ unsupported ( )
200
212
}
201
213
202
214
pub fn socket_addr ( & self ) -> io:: Result < SocketAddr > {
203
- unimplemented ! ( )
215
+ unsupported ( )
204
216
}
205
217
206
218
pub fn recv_from ( & self , _: & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
207
- unimplemented ! ( )
219
+ unsupported ( )
208
220
}
209
221
210
222
pub fn peek_from ( & self , _: & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
211
- unimplemented ! ( )
223
+ unsupported ( )
212
224
}
213
225
214
226
pub fn send_to ( & self , _: & [ u8 ] , _: & SocketAddr ) -> io:: Result < usize > {
215
- unimplemented ! ( )
227
+ unsupported ( )
216
228
}
217
229
218
230
pub fn duplicate ( & self ) -> io:: Result < UdpSocket > {
219
- unimplemented ! ( )
231
+ unsupported ( )
220
232
}
221
233
222
234
pub fn set_read_timeout ( & self , _: Option < Duration > ) -> io:: Result < ( ) > {
223
- unimplemented ! ( )
235
+ unsupported ( )
224
236
}
225
237
226
238
pub fn set_write_timeout ( & self , _: Option < Duration > ) -> io:: Result < ( ) > {
227
- unimplemented ! ( )
239
+ unsupported ( )
228
240
}
229
241
230
242
pub fn read_timeout ( & self ) -> io:: Result < Option < Duration > > {
231
- unimplemented ! ( )
243
+ unsupported ( )
232
244
}
233
245
234
246
pub fn write_timeout ( & self ) -> io:: Result < Option < Duration > > {
235
- unimplemented ! ( )
247
+ unsupported ( )
236
248
}
237
249
238
250
pub fn set_broadcast ( & self , _: bool ) -> io:: Result < ( ) > {
239
- unimplemented ! ( )
251
+ unsupported ( )
240
252
}
241
253
242
254
pub fn broadcast ( & self ) -> io:: Result < bool > {
243
- unimplemented ! ( )
255
+ unsupported ( )
244
256
}
245
257
246
258
pub fn set_multicast_loop_v4 ( & self , _: bool ) -> io:: Result < ( ) > {
247
- unimplemented ! ( )
259
+ unsupported ( )
248
260
}
249
261
250
262
pub fn multicast_loop_v4 ( & self ) -> io:: Result < bool > {
251
- unimplemented ! ( )
263
+ unsupported ( )
252
264
}
253
265
254
266
pub fn set_multicast_ttl_v4 ( & self , _: u32 ) -> io:: Result < ( ) > {
255
- unimplemented ! ( )
267
+ unsupported ( )
256
268
}
257
269
258
270
pub fn multicast_ttl_v4 ( & self ) -> io:: Result < u32 > {
259
- unimplemented ! ( )
271
+ unsupported ( )
260
272
}
261
273
262
274
pub fn set_multicast_loop_v6 ( & self , _: bool ) -> io:: Result < ( ) > {
263
- unimplemented ! ( )
275
+ unsupported ( )
264
276
}
265
277
266
278
pub fn multicast_loop_v6 ( & self ) -> io:: Result < bool > {
267
- unimplemented ! ( )
279
+ unsupported ( )
268
280
}
269
281
270
282
pub fn join_multicast_v4 ( & self , _: & Ipv4Addr , _: & Ipv4Addr ) -> io:: Result < ( ) > {
271
- unimplemented ! ( )
283
+ unsupported ( )
272
284
}
273
285
274
286
pub fn join_multicast_v6 ( & self , _: & Ipv6Addr , _: u32 ) -> io:: Result < ( ) > {
275
- unimplemented ! ( )
287
+ unsupported ( )
276
288
}
277
289
278
290
pub fn leave_multicast_v4 ( & self , _: & Ipv4Addr , _: & Ipv4Addr ) -> io:: Result < ( ) > {
279
- unimplemented ! ( )
291
+ unsupported ( )
280
292
}
281
293
282
294
pub fn leave_multicast_v6 ( & self , _: & Ipv6Addr , _: u32 ) -> io:: Result < ( ) > {
283
- unimplemented ! ( )
295
+ unsupported ( )
284
296
}
285
297
286
298
pub fn set_ttl ( & self , _: u32 ) -> io:: Result < ( ) > {
287
- unimplemented ! ( )
299
+ unsupported ( )
288
300
}
289
301
290
302
pub fn ttl ( & self ) -> io:: Result < u32 > {
291
- unimplemented ! ( )
303
+ unsupported ( )
292
304
}
293
305
294
306
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
295
- unimplemented ! ( )
307
+ unsupported ( )
296
308
}
297
309
298
310
pub fn set_nonblocking ( & self , _: bool ) -> io:: Result < ( ) > {
299
- unimplemented ! ( )
311
+ unsupported ( )
300
312
}
301
313
302
314
pub fn recv ( & self , _: & mut [ u8 ] ) -> io:: Result < usize > {
303
- unimplemented ! ( )
315
+ unsupported ( )
304
316
}
305
317
306
318
pub fn peek ( & self , _: & mut [ u8 ] ) -> io:: Result < usize > {
307
- unimplemented ! ( )
319
+ unsupported ( )
308
320
}
309
321
310
322
pub fn send ( & self , _: & [ u8 ] ) -> io:: Result < usize > {
311
- unimplemented ! ( )
323
+ unsupported ( )
312
324
}
313
325
314
326
pub fn connect ( & self , _: io:: Result < & SocketAddr > ) -> io:: Result < ( ) > {
315
- unimplemented ! ( )
327
+ unsupported ( )
316
328
}
317
329
}
318
330
0 commit comments