@@ -429,6 +429,34 @@ impl<'a> SocketAncillary<'a> {
429
429
self . buffer . len ( )
430
430
}
431
431
432
+ /// Returns the raw ancillary data as byte slice.
433
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
434
+ pub fn data ( & self ) -> & [ u8 ] {
435
+ & self . buffer [ ..self . length ]
436
+ }
437
+
438
+ /// Returns the entire buffer, including unused capacity.
439
+ ///
440
+ /// Use [`data()`](Self::data) if you are only interested in the used portion of the buffer.
441
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
442
+ pub fn buffer ( & self ) -> & [ u8 ] {
443
+ self . buffer
444
+ }
445
+
446
+ /// Returns the entire buffer as mutable slice, including unused capacity.
447
+ ///
448
+ /// You should normally call [`set_len()`](Self::set_len)
449
+ /// after changing the contents of the buffer.
450
+ ///
451
+ /// # Safety
452
+ /// All data written to the buffer must be valid ancillary data for the target platform,
453
+ /// and you must call [`set_len()`](Self::set_len) after changing
454
+ /// the buffer contents to update the internal bookkeeping.
455
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
456
+ pub unsafe fn buffer_mut ( & mut self ) -> & mut [ u8 ] {
457
+ self . buffer
458
+ }
459
+
432
460
/// Returns `true` if the ancillary data is empty.
433
461
#[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
434
462
pub fn is_empty ( & self ) -> bool {
@@ -441,6 +469,20 @@ impl<'a> SocketAncillary<'a> {
441
469
self . length
442
470
}
443
471
472
+ /// Set the number of valid ancillary data bytes and the truncated flag.
473
+ ///
474
+ /// This can be used with [`buffer_mut()`](Self::buffer_mut)
475
+ /// to manually write ancillary data into the buffer.
476
+ ///
477
+ /// # Safety
478
+ /// - The length may not exceed [`capacity()`](Self::capacity).
479
+ /// - The data in the buffer at `0..length` must be valid ancillary data.
480
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
481
+ pub unsafe fn set_len ( & mut self , length : usize , truncated : bool ) {
482
+ self . length = length;
483
+ self . truncated = truncated;
484
+ }
485
+
444
486
/// Returns the iterator of the control messages.
445
487
#[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
446
488
pub fn messages ( & self ) -> Messages < ' _ > {
0 commit comments