当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust UnixDatagram.send_vectored_with_ancillary用法及代码示例


本文简要介绍rust语言中 std::os::unix::net::UnixDatagram.send_vectored_with_ancillary 的用法。

用法

pub fn send_vectored_with_ancillary(    &self,     bufs: &[IoSlice<'_>],     ancillary: &mut SocketAncillary<'_>) -> Result<usize>

在套接字上发送数据和辅助数据。

成功时,返回写入的字节数。

例子

#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixDatagram, SocketAncillary};
use std::io::IoSlice;

fn main() -> std::io::Result<()> {
    let sock = UnixDatagram::unbound()?;
    let buf1 = [1; 8];
    let buf2 = [2; 16];
    let buf3 = [3; 8];
    let bufs = &[
        IoSlice::new(&buf1),
        IoSlice::new(&buf2),
        IoSlice::new(&buf3),
    ][..];
    let fds = [0, 1, 2];
    let mut ancillary_buffer = [0; 128];
    let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
    ancillary.add_fds(&fds[..]);
    sock.send_vectored_with_ancillary(bufs, &mut ancillary)
        .expect("send_vectored_with_ancillary function failed");
    Ok(())
}

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::os::unix::net::UnixDatagram.send_vectored_with_ancillary。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。