【问题标题】:Using Unix sockets with socket2将 Unix 套接字与 socket2 一起使用
【发布时间】:2018-08-24 19:14:49
【问题描述】:

我正在尝试使用socket2 crate 构建一个 Unix 域套接字,但最基本的代码无法编译:

extern crate socket2;
use socket2::*;

fn main() {
    let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap();
}

这是错误:

5 | let socket = Socket::new(Domain::unix(), Type::dgram(), None).unwrap();
  |                          ^^^^^^^^^^^^ function or associated item not found in 
                                               `socket2::Domain`

documentation 表示,unix 功能“仅在激活 unix 功能时在 Unix 上可用”。我在 Ubuntu 机器上运行这段代码。我是否需要激活货物文件中的其他内容才能启用此功能?板条箱缺少我可以依赖的示例。

【问题讨论】:

  • 这不是MCVE。请尝试创建一个
  • 代码已被编辑。
  • 为什么不直接使用普通的UDP socket
  • 我的用途是用于由于各种其他原因需要使用套接字文件进行通信的进程之间的 IPC。

标签: rust unix-socket


【解决方案1】:

This function is only available on Unix when the unix feature is activated.

还有How to activate a feature

在您的情况下,只需将其添加到您的货物清单中:

[dependencies.socket2]
version = "0.3.7"
features = ["unix"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-28
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2021-10-01
    相关资源
    最近更新 更多