如何从 Rust 中的特定原始文件描述符中读取? [英] How can I read from a specific raw file descriptor in Rust?

查看:22
本文介绍了如何从 Rust 中的特定原始文件描述符中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

编者注:此问题针对 1.0 之前的 Rust 版本.一些答案已更新以涵盖 Rust 1.0 或更高版本,但不是全部.

我正在用 Rust 编写一个 systemd 套接字激活服务.systemd 正在向我的进程传递一个打开的文件描述符.

是否有任何采用原始文件描述符的 Rust IO 函数?

在 Rust 1.0 之前,我每晚都使用 Rust.

解决方案

我认为现在你最好的选择可能是使用 libc crate 用于处理原始文件描述符.

FileDesc 移动到私有范围是几个月前运行时删除的结果.有关更多上下文,请参阅此 RFC.std::os::unix 当前具有 Fd 类型,我相信长期的想法是在该模块中公开更多特定于平台的功能.>

Editor's note: This question is for a version of Rust prior to 1.0. Some answers have been updated to cover Rust 1.0 or up, but not all.

I am writing a systemd socket activated service in Rust. My process is being handed an open file descriptor by systemd.

Are there any Rust IO functions that take a raw file descriptor?

I'm using a Rust nightly before Rust 1.0.

解决方案

I think right now your best bet is probably using the libc crate for working with raw file descriptors.

The movement of FileDesc to private scope was fallout from the runtime removal a few months back. See this RFC for some more context. std::os::unix currently has the type Fd, and I believe the long term idea is to expose more of the platform-specific functionality in that module.

这篇关于如何从 Rust 中的特定原始文件描述符中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆