@@ -387,10 +387,11 @@ impl UnixStream {
387
387
/// Sets the read timeout for the socket.
388
388
///
389
389
/// If the provided value is [`None`], then [`read`] calls will block
390
- /// indefinitely. It is an error to pass the zero [`Duration`] to this
390
+ /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is passed to this
391
391
/// method.
392
392
///
393
393
/// [`None`]: ../../../../std/option/enum.Option.html#variant.None
394
+ /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
394
395
/// [`read`]: ../../../../std/io/trait.Read.html#tymethod.read
395
396
/// [`Duration`]: ../../../../std/time/struct.Duration.html
396
397
///
@@ -403,6 +404,20 @@ impl UnixStream {
403
404
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
404
405
/// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
405
406
/// ```
407
+ ///
408
+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
409
+ /// method:
410
+ ///
411
+ /// ```no_run
412
+ /// use std::io;
413
+ /// use std::os::unix::net::UnixStream;
414
+ /// use std::time::Duration;
415
+ ///
416
+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
417
+ /// let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
418
+ /// let err = result.unwrap_err();
419
+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
420
+ /// ```
406
421
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
407
422
pub fn set_read_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
408
423
self . 0 . set_timeout ( timeout, libc:: SO_RCVTIMEO )
@@ -411,10 +426,11 @@ impl UnixStream {
411
426
/// Sets the write timeout for the socket.
412
427
///
413
428
/// If the provided value is [`None`], then [`write`] calls will block
414
- /// indefinitely. It is an error to pass the zero [`Duration`] to this
415
- /// method.
429
+ /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is
430
+ /// passed to this method.
416
431
///
417
432
/// [`None`]: ../../../../std/option/enum.Option.html#variant.None
433
+ /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
418
434
/// [`write`]: ../../../../std/io/trait.Write.html#tymethod.write
419
435
/// [`Duration`]: ../../../../std/time/struct.Duration.html
420
436
///
@@ -427,6 +443,20 @@ impl UnixStream {
427
443
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
428
444
/// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
429
445
/// ```
446
+ ///
447
+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
448
+ /// method:
449
+ ///
450
+ /// ```no_run
451
+ /// use std::io;
452
+ /// use std::net::UdpSocket;
453
+ /// use std::time::Duration;
454
+ ///
455
+ /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
456
+ /// let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
457
+ /// let err = result.unwrap_err();
458
+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
459
+ /// ```
430
460
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
431
461
pub fn set_write_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
432
462
self . 0 . set_timeout ( timeout, libc:: SO_SNDTIMEO )
@@ -1250,10 +1280,11 @@ impl UnixDatagram {
1250
1280
/// Sets the read timeout for the socket.
1251
1281
///
1252
1282
/// If the provided value is [`None`], then [`recv`] and [`recv_from`] calls will
1253
- /// block indefinitely. It is an error to pass the zero [`Duration`] to this
1254
- /// method.
1283
+ /// block indefinitely. An [`Err`] is returned if the zero [`Duration`]
1284
+ /// is passed to this method.
1255
1285
///
1256
1286
/// [`None`]: ../../../../std/option/enum.Option.html#variant.None
1287
+ /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
1257
1288
/// [`recv`]: #method.recv
1258
1289
/// [`recv_from`]: #method.recv_from
1259
1290
/// [`Duration`]: ../../../../std/time/struct.Duration.html
@@ -1267,6 +1298,20 @@ impl UnixDatagram {
1267
1298
/// let sock = UnixDatagram::unbound().unwrap();
1268
1299
/// sock.set_read_timeout(Some(Duration::new(1, 0))).expect("set_read_timeout function failed");
1269
1300
/// ```
1301
+ ///
1302
+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
1303
+ /// method:
1304
+ ///
1305
+ /// ```no_run
1306
+ /// use std::io;
1307
+ /// use std::os::unix::net::UnixDatagram;
1308
+ /// use std::time::Duration;
1309
+ ///
1310
+ /// let socket = UnixDatagram::unbound().unwrap();
1311
+ /// let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
1312
+ /// let err = result.unwrap_err();
1313
+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
1314
+ /// ```
1270
1315
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
1271
1316
pub fn set_read_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
1272
1317
self . 0 . set_timeout ( timeout, libc:: SO_RCVTIMEO )
@@ -1275,7 +1320,7 @@ impl UnixDatagram {
1275
1320
/// Sets the write timeout for the socket.
1276
1321
///
1277
1322
/// If the provided value is [`None`], then [`send`] and [`send_to`] calls will
1278
- /// block indefinitely. It is an error to pass the zero [`Duration`] to this
1323
+ /// block indefinitely. An [`Err`] is returned if the zero [`Duration`] is passed to this
1279
1324
/// method.
1280
1325
///
1281
1326
/// [`None`]: ../../../../std/option/enum.Option.html#variant.None
@@ -1293,6 +1338,20 @@ impl UnixDatagram {
1293
1338
/// sock.set_write_timeout(Some(Duration::new(1, 0)))
1294
1339
/// .expect("set_write_timeout function failed");
1295
1340
/// ```
1341
+ ///
1342
+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
1343
+ /// method:
1344
+ ///
1345
+ /// ```no_run
1346
+ /// use std::io;
1347
+ /// use std::os::unix::net::UnixDatagram;
1348
+ /// use std::time::Duration;
1349
+ ///
1350
+ /// let socket = UnixDatagram::unbound().unwrap();
1351
+ /// let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
1352
+ /// let err = result.unwrap_err();
1353
+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
1354
+ /// ```
1296
1355
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
1297
1356
pub fn set_write_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
1298
1357
self . 0 . set_timeout ( timeout, libc:: SO_SNDTIMEO )
0 commit comments